Hacker News new | ask | show | jobs
by bradly 188 days ago
I recently implemented dark/light mode for the first time and was really surprised to find that in order to add a toggle I had to duplicate a both of vars/styles and use JavaScript. I'm looking forward to not having to deal with that cruft in the future.
1 comments

You can do without javascript. Checkbox `:checked` + `label` trick for toggling states still works.

See: https://codepen.io/abdus/pen/bNpQqXv

Thanks, I’ll check this out!
Here's a version with a 3-way theme selector (light / system / dark) using radio inputs.

https://codepen.io/abdus/pen/yyOQpvE