Below is a complete HTML, CSS, and JavaScript code to create a sleek dark-mode diary app with multimodal input capabilities (text, picture upload, and audio recording). The app allows users to write text, upload images, and record audio files, all styled in a modern dark theme.
<!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 App</title>
<style>
/* General Reset */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Arial', sans-serif;
background-color: #121212;
color: #e0e0e0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
overflow: hidden;
}
.diary-app {
width: 90%;
max-width: 600px;
background: #1e1e1e;
border-radius: 12px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
padding: 20px;
display: flex;
flex-direction: column;
gap: 20px;
}
h1 {
text-align: center;
font-size: 2rem;
color: #bb86fc;
}
textarea {
background: #2c2c2c;
border: none;
border-radius: 8px;
color: #e0e0e0;
padding: 10px;
font-size: 1rem;
resize: none;
height: 150px;
}
textarea:focus {
outline: 2px solid #bb86fc;
}
.media-inputs {
display: flex;
flex-direction: column;
gap: 10px;
}
.media-inputs label {
background: #333;
color: #e0e0e0;
padding: 10px;
border-radius: 8px;
cursor: pointer;
text-align: center;
transition: background 0.3s ease;
}
.media-inputs label:hover {
background: #444;
}
.media-inputs input[type="file"] {
display: none;
}
.audio-recorder {
display: flex;
flex-direction: column;
gap: 10px;
}
.audio-recorder button {
background: #bb86fc;
color: #121212;
border: none;
border-radius: 8px;
padding: 10px;
font-size: 1rem;
cursor: pointer;
transition: background 0.3s ease;
}
.audio-recorder button:hover {
background: #9c27b0;
}
.preview-container {
display: flex;
flex-direction: column;
gap: 10px;
}
.preview-item {
background: #2c2c2c;
padding: 10px;
border-radius: 8px;
display: flex;
align-items: center;
gap: 10px;
}
.preview-item img {
max-width: 100px;
max-height: 100px;
border-radius: 8px;
}
.preview-item audio {
max-width: 100%;
}
</style>
</head>
<body>
<div class="diary-app">
<h1>Dark Mode Diary</h1>
<textarea placeholder="Write your thoughts here..."></textarea>
<div class="media-inputs">
<label for="image-upload">Upload Image</label>
<input type="file" id="image-upload" accept="image/*">
<div class="audio-recorder">
<button id="start-record">Start Recording Audio</button>
<button id="stop-record" disabled>Stop Recording</button>
</div>
</div>
<div class="preview-container">
<!-- Preview of uploaded media will appear here -->
</div>
</div>
<script>
const imageUpload = document.getElementById('image-upload');
const startRecordBtn = document.getElementById('start-record');
const stopRecordBtn = document.getElementById('stop-record');
const previewContainer = document.querySelector('.preview-container');
let mediaRecorder;
let audioChunks = [];
// Handle image upload
imageUpload.addEventListener('change', (event) => {
const file = event.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = (e) => {
const imgPreview = document.createElement('div');
imgPreview.classList.add('preview-item');
imgPreview.innerHTML = `<img src="${e.target.result}" alt="Uploaded Image">`;
previewContainer.appendChild(imgPreview);
};
reader.readAsDataURL(file);
}
});
// Handle audio recording
startRecordBtn.addEventListener('click', async () => {
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
mediaRecorder = new MediaRecorder(stream);
mediaRecorder.ondataavailable = (event) => {
audioChunks.push(event.data);
};
mediaRecorder.onstop = () => {
const audioBlob = new Blob(audioChunks, { type: 'audio/wav' });
const audioUrl = URL.createObjectURL(audioBlob);
const audioPreview = document.createElement('div');
audioPreview.classList.add('preview-item');
audioPreview.innerHTML = `<audio controls><source src="${audioUrl}" type="audio/wav"></audio>`;
previewContainer.appendChild(audioPreview);
audioChunks = [];
stream.getTracks().forEach(track => track.stop());
};
mediaRecorder.start();
startRecordBtn.disabled = true;
stopRecordBtn.disabled = false;
});
stopRecordBtn.addEventListener('click', () => {
mediaRecorder.stop();
startRecordBtn.disabled = false;
stopRecordBtn.disabled = true;
});
</script>
</body>
</html>
Features:
- Text Input: A sleek textarea for writing diary entries.
- Image Upload: Users can upload images, which are displayed as previews.
- Audio Recording: Users can record audio clips, which are saved and displayed as playable previews.
- Dark Mode Design: Minimalist dark theme with smooth hover effects.
How It Works:
- Text Input: Users can type their thoughts in the provided textarea.
- Image Upload: Clicking "Upload Image" lets users select an image file, which is displayed below.
- Audio Recording: Users can start and stop recording audio, and the recorded file is displayed as a playable audio element.
Notes:
- Ensure you test the audio recording feature in a secure environment (HTTPS or localhost).
- You can extend this app by adding features like saving entries locally using
localStorage or sending data to a backend server.