Skip to content
ARENAS®lab R&D 018

Utilities & Scripts Persistent preference

Light changes.Memory stays.

A two-state theme switch that remembers. Your choice is written to a first-party cookie, restored before the first paint of your next visit, and shared by every surface on the page.

Following your system appearance. Pick a mode to keep it.

Fig. 01Noon, fully lit
Saved as
Not saved yet
Kept for
365 days
Applied
Before the first paint
Switch
Shift+T

01Principles

Four ideas, one switch.

The pattern is small on purpose. What makes it feel effortless is a handful of decisions you never have to see.

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.

Tokens in useBackground, Surface, Muted ink, Ink

02Preference

Choice persists.

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.

document.cookietheme is not set

03Motion

Transition, not flash.

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.

On this deviceChecking this device

04System

One source of truth.

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.

Root element<html data-theme-status="light">

02Inspector

Watch the preference move.

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

  1. 01Switch the theme with any toggle, or press Shift + T.
  2. 02Reload. The page arrives in the mode you left it in.
  3. 03Open a second tab. A change in one reaches the other.
  4. 04Forget the preference to follow your system again.

Live readout

This browser

Active theme
Light mode
Decided by
Your system appearance
Cookie
Reading this browser
Expires
Reading this browser
Written with
Reading this browser
Context
Reading this browser
Last request
Carried no theme cookie to the server
Root attribute
data-theme-status="light"

Timeline

  1. Listening for the first change

03Tokens

Two palettes, one vocabulary.

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.

Day/ Paper and ink

data-theme-status="light"

The same names. Only the values move.

  • Background--background#F4F3EF
  • Surface--surface#EBE9E3
  • Raised--card#FBFAF8
  • Ink--foreground#15151516.4 : 1, AAA
  • Muted ink--muted-foreground#63615C5.6 : 1, AA
  • Hairline--hairline-strongInk at 24%
  • Sun--sun#EE7A3F

Night/ Ink and moonlight

data-theme-status="dark"

The same names. Only the values move.

  • Background--background#070915
  • Surface--surface#111526
  • Raised--card#0C0F1F
  • Ink--foreground#F4F3EF17.9 : 1, AAA
  • Muted ink--muted-foreground#9FA2B27.8 : 1, AAA
  • Hairline--hairline-strongInk at 24%
  • Moon--moon#DFE3F0

Top layer

Dialogs inherit the theme too.

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.

Top layer

Same theme, outside the page.

This dialog sits above everything else, yet it reads the same root attribute as the page beneath it. Switch the theme from here and watch both follow.

Shift+T

04Notes

From source to study.

A faithful reconstruction of a documented pattern, finished with the edges a production site needs.

Kept from the source

  1. 01The data-theme-status attribute, with light and dark as its only values
  2. 02A data-theme-toggle button where the sun and the moon trade places
  3. 03The Light and Dark words crossfading in front of mode
  4. 04A cookie named theme, kept for 365 days
  5. 05Shift + T to switch, ignored while you type
  6. 06The 0.4 s theme easing and the sprung 0.8 s icon motion

Added in this study

  1. 01The theme is resolved before the first paint, on the server and in the document head
  2. 02The system appearance is followed until a choice is made
  3. 03Cookie attributes adapt to embedded previews, with local storage as a fallback
  4. 04A reveal that unfolds from the control and stays calm under reduced motion
  5. 05Changes travel between open tabs
  6. 06Accessible names that match what you see, with spoken confirmations

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.

Leave the light as you like it.

ARENAS®lab R&D 018 Theme system study

Pattern by Osmo, Dennis Snellenberg

Back to top