Add a lightweight, smart dark mode toggle to your website in seconds.
Toggle the dark mode switch in the bottom-right corner to instantly see your website adapt. Smooth animations, zero lag.
No dependencies. Loads instantly and keeps page speed blazing fast.
Automatically detects your user's system theme on first load.
Stores the user's preference with localStorage for seamless sessions.
Install DarkMode.js in two easy steps:
</body>.<div class="darkmode-toggle">
<input type="checkbox" id="darkmode">
<label for="darkmode"><span></span></label>
</div>
<script src="darkmode.js"></script>
| Feature | DarkMode.js | Competitor |
|---|---|---|
| Size | 3kB | 20-50kB+ |
| Dependencies | 0 | jQuery / Other Libraries |
| System Theme Detection | ✅ | ❌ |
| Persistent Preference | ✅ | ❌ |
| Ease of Install | 1 line HTML + 1 script | Multiple config steps |
Yes, only 3kB and no dependencies.
Yes, localStorage persists your last choice across sessions.
Yes, DarkMode.js reads prefers-color-scheme on first load.