Show HN: A Dark Mode Toggle Without JavaScript
4 points| TymekDev | 2 years ago |tymekdev.github.io
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.
DHPersonal|2 years ago
TymekDev|2 years ago
I thought this might use indeterminate checkbox, but that wouldn't be necessary. 'Light', 'dark', and lack of thereof in localStorage already amount to three distinct states.
numtel|2 years ago
TymekDev|2 years ago
In fact, I am using it right now, and the example works without issues.
baobaba|2 years ago