Micro Snippet โšก $3

Dark Mode Toggle

System-aware dark/light mode with localStorage persistence.

Dark Mode Toggle preview
Dark Mode Toggle
$3
System-aware dark/light mode with localStorage persistence.
๐Ÿ”’Secure checkout via Stripe
๐Ÿ“งYou will receive a download link by email after successful payment
๐Ÿ”„Lifetime updates included
โ†ฉ๏ธ30-day refund policy

This is a digital download. No physical item will be shipped.

By purchasing you agree to our Terms of Service. A 30-day refund is available โ€” see our Refund Policy.

About this product

A single-file dark/light mode switcher that does everything right out of the box. On first visit it reads the user's prefers-color-scheme media query and applies the matching mode automatically โ€” no flash of wrong theme. After that, any manual toggle is saved to localStorage so the preference persists across sessions.

It works by toggling a data-theme attribute on the <html> element, which means it's compatible with any CSS custom-property-based theme. If you already have --color-bg, --color-text, and similar variables defined for light and dark, it just works.

The toggle button uses an animated SVG sun/moon icon that transitions smoothly between states. The entire file is under 800 bytes minified. No framework, no build step โ€” drop it in and it's done.

Features

  • Detects prefers-color-scheme
  • Saves preference to localStorage
  • Toggles class on <html>
  • Animated sun/moon icon
  • < 800 bytes minified

Files included

  • dark-mode.js
  • dark-mode.min.js
  • demo/index.html
  • README.md
Licence Single-site ยท Personal & commercial use ยท No redistribution or resale