Getting started
Theming
A theme sets a handful of knobs. Every color, radius and font in the system is computed from them.
The knobs
These are the only variables a theme should set. Their defaults make the neutral theme.
| Variable | Default | What it controls |
|---|---|---|
--neutral-hue | 0 | Tint of every gray. Surfaces, text, borders. |
--neutral-chroma | 0 | How strong the tint is. 0 is pure gray, 0.005 to 0.02 reads as a tint. |
--brand-hue | 260 | Hue of the brand scale. |
--brand-chroma | 0.15 | Saturation of the brand scale. |
--font-body | system sans | Body text. Maps to the font-sans utility. |
--font-display | system sans | Headings. Maps to the font-heading utility. |
--font-code | system mono | Code. Maps to the font-mono utility. |
--radius | 0.5rem | Base radius. The 7 radius steps are computed from it. |
Write a theme
A theme is 1 CSS block keyed by data-theme. Start with the knobs. Override a semantic token only when the computed value isn't what you want, like making the primary button use the brand color.
[data-theme="forest"] {
--neutral-hue: 150;
--neutral-chroma: 0.03;
--brand-hue: 150;
--brand-chroma: 0.16;
--font-body: var(--font-inter), ui-sans-serif, sans-serif;
--font-display: var(--font-fraunces), ui-serif, serif;
--radius: 1rem;
/* Optional semantic overrides */
--primary: var(--brand-700);
--primary-foreground: var(--neutral-0);
}
/* Every semantic override needs a dark version. Otherwise the light
value applies in dark mode too. The 3rd selector covers a .dark
section inside a forest page. */
.dark [data-theme="forest"],
[data-theme="forest"].dark,
[data-theme="forest"] .dark {
--primary: var(--brand-400);
--primary-foreground: var(--neutral-1000);
}Applying a theme
Set the attribute on <html> for the whole product. Dark mode is a separate .dark class, so every theme gets dark mode for free.
<html data-theme="forest" class="dark">Nesting themes
Any element can carry data-theme, and everything inside it switches. That works because the primitives and semantic tokens are declared on :root, [data-theme], so they are recomputed on each themed element. Use data-theme="neutral" to return to the default inside another theme.
Why not just :root?
:root is computed once at the root. Children inherit the result, so changing --neutral-hue on a child would do nothing.Examples
The same card under each theme. Each one sets the attribute on its own wrapper.
Neutral
Weekly review
3 items are waiting for you.
The default. Pure gray and system fonts.
Pangpond
Weekly review
3 items are waiting for you.
Blue-tinted neutrals with Figtree and Literata.
Forest
Weekly review
3 items are waiting for you.
Test theme. Green brand, 1rem radius, Inter and Fraunces.