A Dark Mode Toggle Without JavaScript
A Dark Mode Toggle Without JavaScript
Today I scratched my itch of implementing a dark mode toggle without JacaScript. The implementations I saw typically revolved about adding a 'dark' class to body via JS and then controlling it with JS handlers. Thanks to `:has()` selector [0], that passed 90% browser compatibility [1], it is possible to avoid JS. My implementation uses CSS variables combined with a checkbox, `:checked`, and `:has()`. It is simple, yet supports color scheme preference and updates toggle's label based on active mode. [0]: https://developer.mozilla.org/en-US/docs/Web/CSS/:has [1]: https://caniuse.com/css-has
Share cardActual performance
Launch Intel predictions
Analyze your own launch →Incorrect prediction on native model
Similar products
The Top Fives – now with Dark Mode
HackerNews Dark Mode
Dark Mode for HN
Dark Mode for HN
ReactNative Website Upgrade (dark mode, SPA...)
Full Dark Mode Support with Bootstrap 4
The best WordPress dark mode plugin
Spreadsheet with dark mode
Dark Mode List – A List of Apps That Support Dark Mode
I added dark mode to neobrutalism UI library