Creating a fully functioning and professional blogging website with light/dark mode and responsiveness from scratch requires extensive code, beyond the scope of a single response. However, I can guide you on creating a basic structure and show you how to implement key features like theme toggling and responsiveness.
This example will give you a starting point. You'll need deeper knowledge in web development to extend functionalities like creating a back-end or a database for your posts.
Step 1: HTML Structure (index.html)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Blog Site</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<h1>My Blog</h1>
<button id="theme-toggle">Toggle Theme</button>
</header>
<main>
<article>
<h2>Blog Post Title</h2>
<p>Date: 2023-01-01</p>
<p>Lorem ipsum dolor sit amet...</p>
</article>
<!-- Repeat for more blog posts -->
</main>
<footer>
<p>Blog © 2023</p>
</footer>
<script src="script.js"></script>
</body>
</html>
Step 2: CSS for Styling and Responsiveness (style.css)
:root {
--background-color: #ffffff;
--text-color: #000000;
}
[data-theme='dark'] {
--background-color: #222222;
--text-color: #ffffff;
}
body {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
background-color: var(--background-color);
color: var(--text-color);
transition: background-color 0.3s, color 0.3s;
}
header {
background-color: #0066cc;
color: #ffffff;
padding: 20px;
text-align: center;
}
main {
padding: 20px;
}
footer {
background-color: #003366;
color: #ffffff;
text-align: center;
padding: 10px;
position: fixed;
bottom: 0;
width: 100%;
}
#theme-toggle {
cursor: pointer;
}
@media (max-width: 600px) {
header, footer {
text-align: center;
}
}
Step 3: JavaScript for Theme Switching (script.js)
document.getElementById('theme-toggle').addEventListener('click', function() {
if (document.body.getAttribute('data-theme') === 'dark') {
document.body.setAttribute('data-theme', 'light');
localStorage.setItem('theme', 'light'); // Save theme preference
} else {
document.body.setAttribute('data-theme', 'dark');
localStorage.setItem('theme', 'dark'); // Save theme preference
}
});
// Apply the saved theme on load
document.addEventListener('DOMContentLoaded', () => {
const savedTheme = localStorage.getItem('theme') || 'light'; // Default to light theme
document.body.setAttribute('data-theme', savedTheme);
});
Putting It All Together
- Create three files:
index.html, style.css, and script.js in the same directory.
- Copy the respective codes into these files.
- Open
index.html with a web browser to see the basic blog structure.
- Click the "Toggle Theme" button to switch between light and dark modes.
Extending Your Blog
- To add more functionality, consider learning more about frameworks/libraries like React or Vue.js for the front end.
- For the back end, exploring server-side languages like Node.js, Python (Flask or Django), or PHP will be beneficial.
- You’ll also need to delve into databases (e.g., MongoDB, PostgreSQL) to store and manage your blog posts dynamically.
This example serves as a foundation. Building a full-fledged, professional blogging website will require expanding upon this foundation, including implementing a back-end system, a database for your blog posts, user authentication, and more.