1 hour ago · Tech · hide · 0 comments

My last post on color themes and subsequent dark-mode refresh made me want to add an easier way to toggle light and dark mode on this site. In my new nav section, you’ll now see a theme switcher over on the right: CSS vs. JavaScript? I was originally hoping to implement this entirely with CSS, since I know a number of folks out there keep JavaScript disabled when they peruse. I got that working, but the downside is that it doesn’t stick. As soon as a new page loads — for example, when you click any link on my site — the theme reverts to whatever’s dictated by your system. And so it came to pass that this site grew its first few lines of JavaScript. Revealing the switcher I don’t want to show the toggle if it won’t work, so I default to hiding it and then revealing it via JS. This way, if the user doesn’t have JS enabled, they won’t see the toggle. My first implementation of this resulted in a brief flicker on page load as the JS unhid the button. That really bugged me, so I asked…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.