← All articles
3 Jun 2026 · 5 min read
Designing themeable interfaces with CSS variables
CSSDesign systems
A good theming system starts with semantic tokens instead of raw colours. Components ask for --bg or --accent and never care which palette is active.
Tokens first
- Surface tokens:
--bg,--surface,--border - Text tokens:
--fg,--muted - Brand tokens:
--accent,--accent-fg
Avoid the flash
Set the data-theme attribute from a tiny inline script before the first paint, otherwise visitors see a flash of the wrong theme.
:root[data-theme="ocean"] {
--bg: #061826;
--fg: #e6f4ff;
--accent: #38bdf8;
}