Get the latest tech news

Notes on implementing dark mode


<em>Not</em> a dark mode tutorial, but a few notes on some specific refinements of a good dark mode implementation like tri-state instead of bi-state toggle, avoiding page flicker, and responding to theme changes from other tabs or the OS.

I thought this was something that’d never happen because over a decade I’d built up an inescapable legacy of fundamentally unmaintainable CSS, but for over a year I’ve been slowly making headway refactoring everything to Tailwind, and with that finally done, the possibility of dark mode was unlocked. It also has the added benefits of having no default expiration date (so unless a user manually clears data, a light/dark mode setting is sticky for a long time), and sends less personal information to the server, which is broadly a good thing. A lot of sites have so much crap happening when they’re loading that a flicker is lost amongst a sea of jarring effects (e.g. UI elements jumping around as sizes are determined suboptimally late), but a tasteful dark mode implementation takes care to avoid it.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of notes

notes

Photo of dark mode

dark mode

Related news:

News photo

Final Fantasy 14's Patch 7.0 notes reveal what to expect from Dawntrail ahead of early access launch

News photo

Notes on Tajikistan

News photo

New Elden Ring patch notes ahead of Erdtree launch