Toggle light / dark mode
β’ 57 words β’ 1 min
After dabbling about this for a while, I decided to add a non-intrusive icon to
the footer of this site, wherein you can manually toggle between the light and
dark theme. Your choice is persistent locally indefinitely, courtesy of
localStorage1.
Previously, the theme used to be set automatically depending upon your system /
browser preferences
(prefers-color-scheme).
-
localStorage.getItem('theme'). ↩︎