p
GitHub

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.

VariableDefaultWhat it controls
--neutral-hue0Tint of every gray. Surfaces, text, borders.
--neutral-chroma0How strong the tint is. 0 is pure gray, 0.005 to 0.02 reads as a tint.
--brand-hue260Hue of the brand scale.
--brand-chroma0.15Saturation of the brand scale.
--font-bodysystem sansBody text. Maps to the font-sans utility.
--font-displaysystem sansHeadings. Maps to the font-heading utility.
--font-codesystem monoCode. Maps to the font-mono utility.
--radius0.5remBase 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.

src/app/theme-forest.css
[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?

A variable defined on :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.

Design tokensDone
Docs siteDoing
OpenLater

The default. Pure gray and system fonts.

Pangpond

Weekly review

3 items are waiting for you.

Design tokensDone
Docs siteDoing
OpenLater

Blue-tinted neutrals with Figtree and Literata.

Forest

Weekly review

3 items are waiting for you.

Design tokensDone
Docs siteDoing
OpenLater

Test theme. Green brand, 1rem radius, Inter and Fraunces.