# Customization and theming

Tokens on :root, hooks on a subtree, utilities on an element, and how dark mode works.

Source: https://www.zazz.sh/docs/theming/customization/

Zazz has three override surfaces, from widest to narrowest. Pick the narrowest that does the job, and never edit the kit's own files to get a look.

## 1. Tokens on `:root`

The kit's colors, type, spacing, radii, and shadows are custom properties on `:root`. Redefine it and everything that reads it follows. The [tokens page](/api/foundations/tokens/) lists them all with their resolved light and dark values.

```css
@layer overrides {
  :root {
    --color-primary: light-dark(oklch(0.35 0.12 260), oklch(0.85 0.1 260));
    --color-primary-foreground: light-dark(white, oklch(0.2 0.05 260));
    --radius-multiplier: 0;
    --font-family-heading: "Fraunces", var(--font-sans-fallback);
    --spacing: 0.3rem;
  }
}
```

`--spacing: 0.3rem` pins the spacing unit. To keep it fluid at a new size, set its two ends instead: `--spacing-min: 0.275rem; --spacing-max: 0.3rem`. The type scale works the same way through `--typeset-base-min`/`-max` and `--typeset-scale-min`/`-max`. To fit a new typeface's spacing, shift every role at once with `--tracking-modifier` (a length such as `-0.01em`) and the `--leading-heading-multiplier` and `--leading-body-multiplier` factors. The [typography](/api/foundations/typography/) page has the details.

The theme builder on the [home page](/) writes this block for you: pick neutral, primary, secondary, and tertiary colors, set the spacing, radius, and shadow angle, then copy the variables you changed.

Write the block in `@layer overrides` (or import your stylesheet into it) so it outranks the kit's `variables` layer. Color roles are `light-dark()` pairs; keep them that way and dark mode keeps working with no extra rules.

The text-selection highlight is the `--color-selection` / `--color-selection-foreground` pair, which defaults to the primary pair. Unlike the other roles, it only takes effect on `:root`: the kit styles `::selection` there once and every selection inherits it, so the pair set on a subtree changes nothing.

## 2. Hooks on a subtree

Every primitive reads `--ui-<primitive>-<utility>` hooks that inherit, so a hook set on a region themes every instance inside it while each keeps its own states. Where a primitive has a state, it also reads a state hook.

```html
<nav style="--ui-button-px: 2; --ui-button-radius: var(--radius-full); --ui-button-corner-shape: round; --ui-button-bg--hover: var(--color-muted)">
  …every button in here…
</nav>
```

A pill radius set through a hook needs `--ui-button-corner-shape: round` next to it, or the buttons keep the theme's superellipse corners. On one element, `--radius: full` or `--radius: var(--radius-full)` switches the corner shape by itself.

The widest lever is the `--ui-field-*` family: inputs, selects, and textareas read it directly, and button, tabs, checkbox, radio, badge, menu, and command metrics default to it, so `--ui-field-h: 2.75rem` retunes a whole form row. Each primitive's hooks, with defaults, are on its [API page](/api/).

## 3. Utilities on one element

A style utility is the escape hatch for one element: `style="--bg: var(--color-muted); --radius: 4.5"`. On a primitive it flattens the states it touches (`--bg` on a button is that color on hover too), so add the state tier or use the hook when the states matter. For a style no utility, hook, or preset expresses, write a BEM-style class (`.block__element--modifier`) in your stylesheet; keep custom `data-*` attributes for your scripts, and keep `style` to utilities and `--ui-*` hooks.

## Dark mode

`:root` declares `color-scheme: light dark`, and every color role is a `light-dark()` pair, so the page follows the system scheme with no second stylesheet. `data-theme="dark"` or `data-theme="light"` on any element pins a scheme for that subtree by setting `color-scheme`; scopes nest, so a dark sidebar can hold a light card.

The head's theme script reads `localStorage.theme` and sets `data-theme` on `<html>` before first paint. A toggle writes the same two things:

```js
function setTheme(value) {
  const root = document.documentElement;
  if (value === "light" || value === "dark") {
    root.dataset.theme = value;
    localStorage.setItem("theme", value);
  } else {
    delete root.dataset.theme;
    localStorage.removeItem("theme"); // follow the system
  }
}
```

Roles are deliberately unregistered properties so they re-resolve per element inside a pinned subtree. Shadows tint through `--color-shadow` globally or `--shadow-tint` on a subtree, and `--default-shadow-angle` sets the direction the light comes from. `--default-shadow-intensity`, `--default-shadow-blur`, and `--default-shadow-distance` are multipliers on every shadow (`1` is the default).

## A brand block

A complete brand is a few dozen lines: the role colors, the scales they draw from, type, radius, and a handful of hooks.

```css
@layer overrides {
  :root {
    /* neutrals and brand scales */
    --color-neutral-900: oklch(0.2 0.01 60);
    --color-secondary-500: oklch(0.85 0.17 90);

    /* roles */
    --color-background: light-dark(oklch(0.98 0.005 80), var(--color-neutral-900));
    --color-primary: light-dark(var(--color-neutral-900), oklch(0.98 0.005 80));
    --color-secondary: var(--color-secondary-500);

    /* shape and type */
    --radius-multiplier: 0;
    --font-family-heading: "Fraunces", var(--font-sans-fallback);

    /* primitives */
    --ui-field-h: 2.75rem;
    --ui-button-font-weight: 600;
    --ui-card-border-width: 1px;
  }
}
```

## Fonts

The family tokens (`--font-family-body`, `--font-family-heading`, `--font-family-mono`) are system stacks by default; the kit's CSS loads no font files. To use your own fonts, load them in the head and point the tokens at them, keeping the system stack as the fallback:

```html
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@100..900&display=swap">
<style>
  @layer overrides {
    :root {
      --font-family-body: "Inter", var(--font-sans-fallback);
      --font-family-heading: var(--font-family-body);
    }
  }
</style>
```

`buildHead()` still writes a Geist block by default. It loads Geist without applying it, so set the tokens as above to use it, or pass `fontDisplay: false` (`init --no-fonts` in the CLI) to skip the request.
