Skip to main content
Login Join
Snippet · HTML

Dark Mode Toggle

Shared by Darshit Rajyaguru · May 14, 2026

21 views
1 upvote
Back to Snippets

Adds frontend dark/light mode toggle.

<button id="themeToggle">Toggle Dark Mode</button>

<style>
.dark-mode {
	background: #111;
	color: #fff;
}
</style>

<script>
document.getElementById('themeToggle').addEventListener('click', () => {
	document.body.classList.toggle('dark-mode');
});
</script>
Know a different way to do this? Add your approach as a variation so folks can compare them side by side.
Submit a variation

0 comments