Let’s Make A Better “Light / Dark” Toggle

Jason Knight
CodeX
Published in
11 min readDec 10, 2022

--

I’ve written before about light/dark toggles, but that was over two years ago, and as a mentor of mine told me 30 years ago:

If you’re not disgusted with your own code from even a few months ago, you’re in the wrong business.

This is because you learn better ways, learn from your mistakes, or just plain have the time to THINK.

What really prompted me to write this though is this article that popped up recommended to me here.

This is typical of most articles about it, and that’s not necessarily good. I mean it’s well written, he understands most of the concepts, he has a great and simple demo… But the approach and choice of tools is worse than my old one. No simple light/dark toggle should need a 14k JavaScripted SVG animation library!

What’s Wrong With His?

  1. He had to write twice the JS needed to do the job, whilst being reliant on a 14k library he didn’t even need.

--

--

Jason Knight
CodeX

Accessibility and Efficiency Consultant, Web Developer, Musician, and just general pain in the arse