01Surface
Color is context.
Every surface reads from a short list of named tokens. A theme swaps their values, never their names, so no component needs to know which one is active.
01Principles
The pattern is small on purpose. What makes it feel effortless is a handful of decisions you never have to see.
01Surface
Every surface reads from a short list of named tokens. A theme swaps their values, never their names, so no component needs to know which one is active.
02Preference
The choice is written to a first-party cookie called theme and kept for 365 days. It travels with every request, so the server can dress the page before it leaves.
theme is not set03Motion
A returning visitor never sees the wrong theme, not even for a frame. The switch unfolds from the control you touched, and turns instant when your system asks for less motion.
04System
A single attribute on the root element drives everything, including dialogs and menus that render outside the page. Every toggle on this page shares that one state.
<html data-theme-status="light">02Inspector
Everything in this panel is read live from your browser: the cookie, the attributes it was written with, and what the server received on the last request.
Try this
Live readout
This browser
data-theme-status="light"Timeline
03Tokens
Day and Night share every token name. Each text color is checked for contrast against the background it sits on, and both clear the WCAG AA bar.
data-theme-status="light"The same names. Only the values move.
--background#F4F3EF--surface#EBE9E3--card#FBFAF8--foreground#15151516.4 : 1, AAA--muted-foreground#63615C5.6 : 1, AA--hairline-strongInk at 24%--sun#EE7A3Fdata-theme-status="dark"The same names. Only the values move.
--background#070915--surface#111526--card#0C0F1F--foreground#F4F3EF17.9 : 1, AAA--muted-foreground#9FA2B27.8 : 1, AAA--hairline-strongInk at 24%--moon#DFE3F0Top layer
A native dialog renders above the page, in the browser's top layer. It still reads the same root attribute, so the theme follows it in, and so does the switch.
04Notes
A faithful reconstruction of a documented pattern, finished with the edges a production site needs.
Source and credit
Dark/Light Mode with Cookie is an Osmo resource by Dennis Snellenberg, filed under Utilities & Scripts and last updated on September 30, 2025.
This study is an independent reconstruction of the documented behavior. It redistributes none of Osmo's original files, media or assets.