Dark mode tokens — a rearrangement, not an inversion
A dark theme made by inverting a light palette usually fails. The background darkens while the accent stays put and disappears, shadows become invisible and borders vanish. Dark mode is the same palette rearranged under different rules.
Surface layers
In light mode the page background is the lightest surface and cards sit slightly lighter still, or separate through shadow. In dark mode the background is darkest and surfaces are lighter, so a card appears closer to the viewer. The tokens here use background 50 and surface 100 in light, background 950 and surface 900 in dark.
| Token | Light | Dark | Why |
|---|---|---|---|
| background | 50 | 950 | the furthest plane |
| surface | 100 | 900 | one step nearer than the background |
| text | 900 | 50 | maximum contrast with the background |
| muted | 700 | 300 | lower contrast but still 4.5:1 |
| border | 200 | 800 | the smallest separation from the background |
| primary | 600 | 400 | two steps lighter in the dark |
| on primary | 50 | 950 | 4.5:1 against the accent fill |
The accent goes lighter
If step 600 is the accent in light mode, step 400 is the accent in dark. Two reasons: at the same chroma colours look duller on a dark background, and step 600 against a 950 background lacks enough contrast, so the button sinks in. That is why the export defaults to 600 light and 400 dark.
Shadows and borders
A black shadow is invisible on a dark background. Depth comes instead from surface lightness and thin light borders, which is why the preview cards here use borders. Borders do not always need 3:1, but where the border carries function, as on an input, it should.
Implementation
:root { color-scheme: light dark; }
:root {
--bg: light-dark(oklch(97% 0.02 250), oklch(18% 0.03 250));
--surface: light-dark(oklch(93% 0.02 250), oklch(25% 0.03 250));
--text: light-dark(oklch(25% 0.04 250), oklch(97% 0.02 250));
--primary: light-dark(oklch(49% 0.16 250), oklch(68% 0.14 250));
}
Name tokens by role and change only values per theme. A name like --blue-600 that points at step 400 in dark mode is a lie; --color-primary stays true. Role names also keep utility class names stable.
Verification
- Check all 121 pairs in both themes; checking one leaves failures in the other.
- Make sure illustrations and images do not glare on the dark background.
- The focus ring must be visible in both themes; a single bright accent disappears on one.
- Let users choose the theme. Following the system alone removes that choice.
The token arrangement summarises common dark-mode practice; brand rules take precedence.
Questions
Should dark mode use pure black?
Contrast is highest but glare and smearing appear. A very dark grey, L 15–20%, is usually easier to read.
Why does my accent disappear in the dark?
It lacks contrast against the darker background and looks duller at the same chroma. Move one or two steps lighter.
How do I avoid a flash when the theme changes?
Set data-theme with an inline script before the page paints. That is what the theme boot script here does.
See the light and dark previews side by side in the export tab.
Open the toolBasis date 28 November 2026. Written against the W3C specifications, the APCA documentation and published browser support tables; updated when they change.
Back to the guides