Sure! Below is a complete all-in-one HTML file that includes HTML, CSS, and JavaScript to create a sleek dark mode diary app. It supports:
- Text input for diary entries
- Image upload
- Audio recording and attaching audio files
- Dark mode styling
✅ Note: Audio recording uses the MediaRecorder API, which is supported in most modern browsers (not Safari on iOS as of now).
You can save this as an .html file and open it in your browser.
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Dark Mode Diary</title>
<style>
body {
margin: 0;
font-family: 'Segoe UI', sans-serif;
background-color: #121212;
color: #e0e0e0;
display: flex;
flex-direction: column;
align-items: center;
padding: 20px;
}
h1 {
color: #ffffff;
}
.diary-container {
background-color: #1e1e1e;
border-radius: 10px;
padding: 20px;
width: 100%;
max-width: 600px;
box-shadow: 0 0 10px rgba(0,0,0,0.5);
}
textarea {
width: 100%;
height: 150px;
background-color: #2c2c2c;
color: #ffffff;
border: none;
border-radius: 5px;
padding: 10px;
resize: vertical;
font-size: 16px;
}
input[type="file"] {
margin-top: 10px;
color: #ffffff;
}
.controls {
margin-top: 15px;
display: flex;
justify-content: space-between;
flex-wrap: wrap;
}
button {
background-color: #3a3a3a;
color: #ffffff;
border: none;
padding: 10px 15px;
border-radius: 5px;
cursor: pointer;
margin-top: 10px;
}
button:hover {
background-color: #555;
}
.preview {
margin-top: 15px;
}
.preview img {
max-width: 100%;
border-radius: 5px;
margin-top: 10px;
}
audio {
margin-top: 10px;
width: 100%;
}
.entry {
background-color: #2a2a2a;
padding: 15px;
border-radius: 8px;
margin-top: 20px;
}
.entry h3 {
margin-top: 0;
}
.entry img {
max-width: 100%;
border-radius: 5px;
margin-top: 10px;
}
.entry audio {
margin-top: 10px;
width: 100%;
}
</style>
</head>
<body>
<h1>📝 Dark Mode Diary</h1>
<div class="diary-container">
<textarea id="textEntry" placeholder="Write your thoughts..."></textarea>
<div class="controls">
<div>
<label for="imageInput">📷 Add Image:</label>
<input type="file" id="imageInput" accept="image/*" />
</div>
<div>
<button id="recordBtn">🎤 Start Recording</button>
<button id="stopBtn" disabled>⏹ Stop</button>
</div>
</div>
<div class="preview" id="preview">
<!-- Image and audio preview -->
</div>
<button id="saveBtn">💾 Save Entry</button>
</div>
<div id="entries">
<!-- Saved entries will appear here -->
</div>
<script>
const imageInput = document.getElementById('imageInput');
const preview = document.getElementById('preview');
const recordBtn = document.getElementById('recordBtn');
const stopBtn = document.getElementById('stopBtn');
const saveBtn = document.getElementById('saveBtn');
const entries = document.getElementById('entries');
const textEntry = document.getElementById('textEntry');
let imageFile = null;
let audioBlob = null;
let mediaRecorder;
let audioChunks = [];
// Image preview
imageInput.addEventListener('change', (e) => {
const file = e.target.files[0];
if (file && file.type.startsWith('image/')) {
imageFile = file;
const reader = new FileReader();
reader.onload = function (event) {
const img = document.createElement('img');
img.src = event.target.result;
preview.innerHTML = '';
preview.appendChild(img);
};
reader.readAsDataURL(file);
}
});
// Audio recording
recordBtn.addEventListener('click', async () => {
if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) {
alert('Audio recording not supported in this browser.');
return;
}
try {
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
mediaRecorder = new MediaRecorder(stream);
audioChunks = [];
mediaRecorder.ondataavailable = (e) => {
audioChunks.push(e.data);
};
mediaRecorder.onstop = () => {
audioBlob = new Blob(audioChunks, { type: 'audio/webm' });
const audioURL = URL.createObjectURL(audioBlob);
const audio = document.createElement('audio');
audio.controls = true;
audio.src = audioURL;
preview.appendChild(audio);
};
mediaRecorder.start();
recordBtn.disabled = true;
stopBtn.disabled = false;
} catch (err) {
console.error('Error accessing microphone:', err);
alert('Could not access microphone.');
}
});
stopBtn.addEventListener('click', () => {
if (mediaRecorder && mediaRecorder.state !== 'inactive') {
mediaRecorder.stop();
recordBtn.disabled = false;
stopBtn.disabled = true;
}
});
// Save entry
saveBtn.addEventListener('click', () => {
const text = textEntry.value.trim();
if (!text && !imageFile && !audioBlob) {
alert('Please write something or add media.');
return;
}
const entryDiv = document.createElement('div');
entryDiv.className = 'entry';
const date = new Date().toLocaleString();
entryDiv.innerHTML = `<h3>${date}</h3><p>${text.replace(/\n/g, '<br>')}</p>`;
if (imageFile) {
const reader = new FileReader();
reader.onload = function (event) {
const img = document.createElement('img');
img.src = event.target.result;
entryDiv.appendChild(img);
};
reader.readAsDataURL(imageFile);
}
if (audioBlob) {
const audioURL = URL.createObjectURL(audioBlob);
const audio = document.createElement('audio');
audio.controls = true;
audio.src = audioURL;
entryDiv.appendChild(audio);
}
entries.prepend(entryDiv);
// Reset
textEntry.value = '';
imageInput.value = '';
imageFile = null;
audioBlob = null;
preview.innerHTML = '';
});
</script>
</body>
</html>
✅ Features:
- Dark Mode UI: Sleek and modern dark theme
- Text Entry: Write your diary entry
- Image Upload: Attach a picture
- Audio Recording: Record and attach voice notes
- Preview: See image/audio before saving
- Save Entry: Saves entry in the same page (not persistent)
📝 Notes:
- This app does not store data persistently. To make it persistent, you can use
localStorage, IndexedDB, or connect to a backend.
- Audio is recorded in
.webm format. You can convert it on the backend if needed.
- For mobile support, test on Android Chrome. iOS Safari may not support MediaRecorder.
Let me know if you want a version with persistent storage or backend integration!