# Theming

## Two tiers of tokens

All tokens are [custom properties](https://www.w3.org/TR/css-variables-1/) on `:root`
with the `--dui-` prefix.

| Tier | File | Named by | Example | Public? |
| --- | --- | --- | --- | --- |
| Primitive | `css/tokens/primitives.css` | What it is | `--dui-color-indigo-9: oklch(53% 0.215 272);` `--dui-space-5: 1rem;` | No. Internal, may change in any release. |
| Semantic | `css/tokens/semantic.css` | What it is for | `--dui-color-accent: light-dark(var(--dui-color-neutral-12), var(--dui-color-neutral-dark-12));` | **Yes.** The stable theming API. |

**Base, layout, utility and component CSS reference only semantic tokens.** They never use
primitives and never hard-code colors or sizes (`0`, `1px` hairlines, percentages, `fr`,
`currentcolor`, `inherit`, `transparent` and system colors are fine). `npm test` enforces
this with `scripts/check-tokens.mjs` (`npm run lint:tokens`), which also rejects literal
colors in `semantic.css`.

**Our choice:** the `--dui-` prefix, so tokens never collide with your own custom properties.

## Color

Color primitives are [`oklch()`](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/color_value/oklch) in [OKLCH](https://www.w3.org/TR/css-color-4/#ok-lab) (CSS Color 4), inside the sRGB gamut. Neutral and indigo each have 12 steps in light and in dark. The step number is the role:

| Step | Role |
| --- | --- |
| 1 | Page |
| 2 | Raised |
| 3 | Sunken or element |
| 4 | Hover |
| 5 | Active or selected |
| 6 | Subtle border |
| 7 | Border |
| 8 | Control border |
| 9 | Solid |
| 10 | Solid hover |
| 11 | Muted or accent text |
| 12 | Text |

On a Display P3 screen ([`@media (color-gamut: p3)`](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/At-rules/@media/color-gamut)) the accent solids (indigo 9 and 10) and the status solids (step 9) take more chroma at the same lightness and hue: the sRGB chroma times how much further P3 reaches there, so they are as saturated relative to P3 as they are to sRGB, and stay inside it ([gamut mapping](https://www.w3.org/TR/css-color-4/#gamut-mapping)). Contrast pairs keep their ratios, and `npm test` checks them with P3 emulated. Text steps (11 and 12) and neutrals do not change. [Geist](https://vercel.com/geist/colors) also uses P3 where supported, for comparison.

Red, green, amber and blue have steps 3, 9 and 11. [Radix Colors](https://www.radix-ui.com/colors/docs/palette-composition/understanding-the-scale) numbers a scale the same way. [Tailwind v4](https://tailwindcss.com/docs/colors) and [Geist](https://vercel.com/geist/colors) also ship OKLCH ramps. Those are other systems, for comparison.

**Our choice:** the default is warm paper. Neutrals are ivory on the pale steps and brown ink on step 12 (hue 85 toward 45, chroma 0.035 at most), and step 2 (raised) is lighter than step 1 (the page), so cards and panels sit on the page like brighter paper. `--dui-color-primary` is neutral step 12, the ink (brown on a light page, ivory on a dark one), and `--dui-color-primary-contrast` is the paper on that fill. `--dui-color-primary-hover` is a [relative color](https://www.w3.org/TR/css-color-5/#relative-colors) of the primary ([MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Colors/Using_relative_colors)), so it keeps the primary's hue. Primary buttons and `type="submit"` read these three. The accent is clay, `oklch(57% 0.17 42)`, the same in both schemes: links (as the accent text), focus, checks, switches and selection. Titles (h1 to h3) use the transitional serif stack (`--dui-font-display`), and a dotted grid (`--dui-pattern-image`) sits on the page and an app shell's frame. The earlier achromatic look, closer to [shadcn/ui's neutral theme](https://ui.shadcn.com/docs/theming), is the opt-in `neutral` theme. `--dui-color-accent-indigo` keeps an indigo solid for themes such as calm.

`--dui-color-accent-text` is a relative color of `--dui-color-accent`: the same hue, with lightness and chroma set for [1.4.3 Contrast (Minimum)](https://www.w3.org/WAI/WCAG22/Understanding/contrast-minimum.html). `--dui-color-link` points at it. `--dui-color-focus` is the accent solid in light and the accent text in dark, so the ring meets [1.4.11 Non-text Contrast](https://www.w3.org/WAI/WCAG22/Understanding/non-text-contrast.html) on a dark page. **Our choice:** an achromatic accent (chroma 0, fading in up to 0.02) instead gives the text color for `--dui-color-accent-text` and a mid gray at 3:1 for the focus ring, so the neutral default looks like shadcn/ui's while a hued accent behaves as before. The ring is 3px and hugs the edge, like shadcn/ui's, but opaque rather than a translucent halo, so it keeps 3:1. `--dui-color-accent-hover` and `--dui-color-accent-surface` are derived from the accent too, so a theme that sets only `--dui-color-accent` still gets a matching link, hover and tint. `--dui-color-accent-contrast` is white, except on the neutral dark accent, where it is the dark page color.

`--dui-color-border` is the ink at about 14% alpha, a warm hairline. `--dui-color-border-control` stays an opaque step at 3:1 for fields, selects, checkboxes, radios and switches, whose boundary is what shows where to click or type. **Our choice:** the secondary button's border, `--dui-color-border-button`, is a softer step, because its visible text label identifies it and [1.4.11](https://www.w3.org/WAI/WCAG22/Understanding/non-text-contrast.html) asks for 3:1 only for the visual information needed to identify a component. `--dui-color-shadow` is a warm brown at low alpha.

Light and dark values use [`light-dark()`](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/color_value/light-dark) ([CSS Color 5](https://www.w3.org/TR/css-color-5/)). `tests/contrast.js` checks the pairs below, and the status and code colors, against these thresholds. It takes a theme scope, so another theme can reuse it.

## A theme is a semantic-token override

No build step. Override semantic tokens on `:root` for the whole page, or on any element
with a `data-theme` attribute or a `theme-*` class to scope it:

```css
[data-theme="forest"] {
  --dui-color-surface: light-dark(#f7f5ef, #141a16);
  --dui-color-text: light-dark(#1d2a22, #e4ebe3);
  --dui-color-accent: light-dark(#2f6b3f, #7fcf95);
  --dui-color-accent-contrast: light-dark(#fff, #0f1a13);
  --dui-color-primary: light-dark(#173528, #d7f5e3);
  --dui-color-primary-contrast: light-dark(#fff, #0f1a13);
}
```

```html
<section data-theme="forest">…</section>
```

[`examples/theming.html`](https://domestic-ui.odonckers.dev/principles/theming.md) shows a full scoped theme next to the default.

A theme has three inputs: the neutrals (surface and text), the accent, and contrast. Linear builds its themes from
the same trio ([how they redesigned the UI](https://linear.app/blog/how-we-redesigned-the-linear-ui)), for comparison.
`--dui-contrast` (default `1`) is the contrast input. Above `1`, `--dui-color-text-muted` moves toward
`--dui-color-text` with [`color-mix()`](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/color-mix)
(halfway at `1.5`), the alpha of `--dui-color-border` scales through a
[relative color](https://www.w3.org/TR/css-color-5/#relative-colors), and `--dui-tint-amount` and
`--dui-border-tint-amount` scale, so tinted surfaces and borders stand out more.
[`prefers-contrast: more`](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/At-rules/@media/prefers-contrast)
sets it to `1.5`, and so does `data-contrast="more"` on any element for its subtree. An empty `data-contrast`
scopes your own value. Forced colors are handled separately. Our choice: below `1` only hairlines and tints
soften and muted text never moves, and there is no "less" value, so text stays at 4.5:1
([1.4.3](https://www.w3.org/WAI/WCAG22/Understanding/contrast-minimum.html)) and control boundaries at 3:1
([1.4.11](https://www.w3.org/WAI/WCAG22/Understanding/non-text-contrast.html)) at every setting. `npm test`
checks the pairs at 0.8, 1 and 1.5. A theme that sets `--dui-color-text-muted` or `--dui-color-border` itself
(the soft theme does) takes those values as they are.
Shape has one knob: `--dui-radius-scale` multiplies `--dui-radius-control` (8px) and
`--dui-radius-surface` (12px). `0` gives square corners and `1.5` rounder ones, while pills stay round.
Radix Themes has the same idea ([`--radius-factor`](https://www.radix-ui.com/themes/docs/theme/radius)), for comparison.

Nested corners are concentric: an item inside a rounded container takes the container's radius less the
padding between them, never below 0, so the two curves share a centre. `--dui-radius-nested` is
`max(0px, calc(--dui-radius-surface - --dui-space-gap-tight))`, used by menu items, listbox options and the
links in a horizontal nav dropdown ([`border-radius`](https://developer.mozilla.org/en-US/docs/Web/CSS/border-radius),
[`calc()`](https://developer.mozilla.org/en-US/docs/Web/CSS/calc), [`max()`](https://developer.mozilla.org/en-US/docs/Web/CSS/max)).
It follows `--dui-radius-scale` and density, and at scale `0` it is square. Apple's
[2025 design language](https://www.apple.com/newsroom/2025/06/apple-introduces-a-delightful-and-elegant-new-software-design/)
and Vercel's [Web Interface Guidelines](https://vercel.com/design/guidelines) ask for the same, for comparison.
Our choice: nav rows in a sidebar, code blocks in cards and the floating panels keep their own radii, because
their padding is as large as the outer radius or larger, so the concentric value would be square.
Type has one opt-in: link `css/fonts/inter.css` and set `--dui-font-body: Inter, system-ui, sans-serif` to use the
self-hosted Inter instead of the system stack (see "Opinions we hold"). Nothing else changes.
Check your theme's contrast in both schemes. `tests/tokens.spec.js` shows how.

## Prebuilt themes

Four opt-in themes ship in `css/themes/`. `css/domestic.css` imports none of them, so the default ships no
extra bytes. Link one after `css/domestic.css` and put its name in `data-theme` on `:root` or any element
([`examples/themes.html`](https://domestic-ui.odonckers.dev/principles/themes.md)). Each file sets semantic tokens only (`npm run lint:tokens`
checks it), with light and dark values, so scopes nest, and forced colors keep the base behavior.

| Theme | `data-theme` | Tokens it changes |
| --- | --- | --- |
| Calm | `calm` | `--dui-color-accent` is `--dui-color-accent-indigo`, and `--dui-color-primary`, `-primary-hover` and `-primary-contrast` follow it (white text), so links and focus are indigo too; `--dui-color-shadow` tinted with the accent hue. Radius and density stay the default. |
| Soft | `soft` | Warm neutrals (hue 70, chroma 0.02 at most) for every surface, text and border token; `--dui-color-accent` terracotta `oklch(55% 0.15 40)` as the primary with white text; `--dui-radius-scale` 1.5 (12 / 18px); `--dui-density-scale` 1.25 (roomier padding); `--dui-elevation-strength` 80% and a warm `--dui-color-shadow`. |
| Compact | `compact` | `--dui-color-accent` blue `oklch(53% 0.15 250)`; `--dui-radius-scale` 0.25 (2 / 3px); `--dui-density-scale` 0 (32px controls, 44px under a coarse pointer); `--dui-elevation-strength` 35%, so hairlines carry the edges. |
| Neutral | `neutral` | The achromatic look that was the default before ivory: white page (chroma 0) and near-black text for every surface, text and border token; `--dui-color-accent` and `--dui-color-primary` are the text color, so links read as underlined text; `--dui-color-surface-frame` raised; cards and the content panel on the page color; sans titles (`--dui-font-display` is `--dui-font-heading`); no page pattern (`--dui-pattern-image: none`). Muted text and hairlines still follow `--dui-contrast`. |

To write your own, copy one of these files: keep the `@layer` statement and the `@layer tokens` block,
set only semantic tokens, give each color a light and a dark value, and add your scope to
`registerContrastTests` in `tests/tokens.spec.js`. **Our choice:** each file repeats the layer order and
puts its overrides in the tokens layer, so it works linked before or after `css/domestic.css` and your
unlayered CSS still wins. Themes never change type sizes. Density changes spacing and targets only.
Radix Themes, shadcn/ui and Carbon ship themes the same way, as token sets, for comparison.

A few semantic tokens are defined in terms of others (`--dui-color-accent-text`,
`--dui-color-link`, `--dui-color-focus`, `--dui-color-accent-hover` and
`--dui-color-accent-surface` follow `--dui-color-accent`; `--dui-color-primary-hover`
follows `--dui-color-primary`; the badge tints `--dui-color-*-surface` mix a tone into
`--dui-color-surface`). A custom property's `var()` is
resolved on the element that declares it ([CSS Variables, "Resolving dependency cycles"](https://www.w3.org/TR/css-variables-1/#cycles)),
so these, plus `color`, `background-color` and `font-family`, are re-applied on every
`[data-theme]`, `.theme-*` and `[data-color-scheme]` element.
**Our choice:** `data-theme` (or a `theme-*` class) as the single scoping API, so one attribute
makes an element a theme root. An override on any other selector (say `.sidebar`) still
reaches properties that read the token directly on an element (borders, buttons, links,
headings, controls), but not inherited text color, background or derived tokens. Add
`data-theme` to that element to get the full effect.

## Semantic tokens (public API)

Renaming or removing a semantic token is a **breaking change** (see [Versioning](https://domestic-ui.odonckers.dev/contributing.md#versioning)). Primitives are internal and
may change. Fluid `--dui-step-*` values are `clamp()` expressions. See `primitives.css`.

| Token | Purpose | Default (primitive, light / dark) |
| --- | --- | --- |
| `--dui-color-surface` | Page and control background: ivory paper (neutral step 1) | light: `neutral-1` (`oklch(96.6% 0.012 85)`)<br>dark: `neutral-dark-1` (`oklch(18.5% 0.012 55)`) |
| `--dui-color-surface-raised` | Brighter paper on the page: cards, panels, table row hover (step 2) | light: `neutral-2` (`oklch(98.8% 0.006 85)`)<br>dark: `neutral-dark-2` (`oklch(21.5% 0.014 55)`) |
| `--dui-color-surface-sunken` | Recessed areas: code, button hover (step 3) | light: `neutral-3` (`oklch(93.8% 0.014 82)`)<br>dark: `neutral-dark-3` (`oklch(22% 0.015 55)`) |
| `--dui-color-surface-hover` | Hover fill of quiet buttons, nav, menu and listbox rows (step 4) | light: `neutral-4` (`oklch(92.4% 0.016 80)`)<br>dark: `neutral-dark-4` (`oklch(27% 0.016 55)`) |
| `--dui-color-surface-active` | Pressed fill of quiet buttons (step 5) | light: `neutral-5` (`oklch(89.8% 0.018 78)`)<br>dark: `neutral-dark-5` (`oklch(31% 0.018 55)`) |
| `--dui-color-surface-frame` | Background of an app shell's frame: the app bar and sidebars sit on it, around the main content panel | `--dui-color-surface` |
| `--dui-color-text` | Body text: the ink (step 12) | light: `neutral-12` (`oklch(28% 0.035 45)`)<br>dark: `neutral-dark-12` (`oklch(95% 0.012 85)`) |
| `--dui-color-text-muted` | Secondary text, captions, list markers (step 11, still 4.5:1). Above `--dui-contrast` 1 it moves toward `--dui-color-text` | light: `neutral-11` (`oklch(49% 0.03 55)`)<br>dark: `neutral-dark-11` (`oklch(75% 0.02 70)`) |
| `--dui-color-border` | Decorative hairline: the ink at about 14% alpha, times `--dui-contrast` | light: `neutral-12` at 14% (`oklch(28% 0.035 45 / 14%)`)<br>dark: `neutral-dark-12` at 12% (`oklch(95% 0.012 85 / 12%)`) |
| `--dui-color-border-control` | Boundaries of fields, selects, checkboxes, radios and switches (step 8, 3:1) | light: `neutral-8` (`oklch(57% 0.03 60)`)<br>dark: `neutral-dark-8` (`oklch(57% 0.025 60)`) |
| `--dui-color-border-control-hover` | Field border on hover (step 9) | light: `neutral-9` (`oklch(50% 0.03 55)`)<br>dark: `neutral-dark-9` (`oklch(66% 0.022 65)`) |
| `--dui-color-border-button` | Secondary button border (step 6): softer, because the visible label identifies the button | light: `neutral-6` (`oklch(86% 0.02 75)`)<br>dark: `neutral-dark-6` (`oklch(35% 0.02 55)`) |
| `--dui-color-primary` | Primary action fill: the ink (neutral step 12) | light: `neutral-12` (`oklch(28% 0.035 45)`)<br>dark: `neutral-dark-12` (`oklch(95% 0.012 85)`) |
| `--dui-color-primary-contrast` | Text on the primary fill: paper on ink | light: `neutral-2` (`oklch(98.8% 0.006 85)`)<br>dark: `neutral-dark-1` (`oklch(18.5% 0.012 55)`) |
| `--dui-color-accent` | Accent solid for selection, checks, switches and focus, and the hue of links: clay | `clay-9` (`oklch(57% 0.17 42)`) |
| `--dui-color-accent-indigo` | An indigo accent solid, more vivid on a Display P3 screen; the calm theme's accent | light: `indigo-9` (`oklch(53% 0.215 272)`)<br>dark: `indigo-dark-9` (`oklch(53% 0.215 272)`) |
| `--dui-color-accent-contrast` | Text on the accent fill, white in both schemes | `white` (`oklch(100% 0 0)`) |
| `--dui-color-link-visited` | Visited links | light: `purple-11` (`oklch(46.2% 0.195 299)`)<br>dark: `purple-dark-11` (`oklch(80.1% 0.127 306)`) |
| `--dui-color-danger` | Errors, :user-invalid borders (red step 11) | light: `red-11` (`oklch(48% 0.16 27)`)<br>dark: `red-dark-11` (`oklch(80% 0.114 27)`) |
| `--dui-color-success` | Success messages (green step 11) | light: `green-11` (`oklch(47% 0.128 150)`)<br>dark: `green-dark-11` (`oklch(80% 0.12 150)`) |
| `--dui-color-warning` | Warning badges and messages (amber step 11) | light: `amber-11` (`oklch(47% 0.098 75)`)<br>dark: `amber-dark-11` (`oklch(80% 0.12 75)`) |
| `--dui-color-info` | Informational alerts and toasts (blue step 11, separate from the accent, so a brand color never reads as a status) | light: `blue-11` (`oklch(48% 0.12 245)`)<br>dark: `blue-dark-11` (`oklch(80% 0.108 245)`) |
| `--dui-color-mark` | mark and ::selection background | light: `yellow-3` (`oklch(95.3% 0.093 99)`)<br>dark: `yellow-dark-9` (`oklch(83.4% 0.141 97)`) |
| `--dui-color-mark-text` | Text on mark | `neutral-12` (`oklch(28% 0.035 45)`) |
| `--dui-color-backdrop` | dialog::backdrop | light: `black-a40` (`oklch(0% 0 0 / 40%)`)<br>dark: `black-a60` (`oklch(0% 0 0 / 60%)`) |
| `--dui-color-shadow` | Shadow color: warm brown at low alpha | light: `neutral-shadow` (`oklch(30% 0.04 45 / 10%)`)<br>dark: `neutral-dark-shadow` (`oklch(10% 0.02 45 / 50%)`) |
| `--dui-color-code-keyword` | JS keywords and CSS at-rules in highlighted code (4.5:1 on surface-sunken) | light: `purple-11` (`oklch(46.2% 0.195 299)`)<br>dark: `purple-dark-11` (`oklch(80.1% 0.127 306)`) |
| `--dui-color-code-string` | Strings and HTML attribute values in highlighted code (4.5:1 on surface-sunken) | light: `green-11` (`oklch(47% 0.128 150)`)<br>dark: `green-dark-11` (`oklch(80% 0.12 150)`) |
| `--dui-color-code-comment` | Comments in highlighted code (4.5:1 on surface-sunken) | light: `neutral-11` (`oklch(49% 0.03 55)`)<br>dark: `neutral-dark-11` (`oklch(75% 0.02 70)`) |
| `--dui-color-code-tag` | HTML tag names and CSS selectors in highlighted code (4.5:1 on surface-sunken) | light: `blue-11` (`oklch(48% 0.12 245)`)<br>dark: `blue-dark-11` (`oklch(80% 0.108 245)`) |
| `--dui-color-code-attribute` | HTML attribute names in highlighted code (4.5:1 on surface-sunken) | light: `amber-11` (`oklch(47% 0.098 75)`)<br>dark: `amber-dark-11` (`oklch(80% 0.12 75)`) |
| `--dui-color-code-property` | CSS and JS properties in highlighted code (4.5:1 on surface-sunken) | light: `teal-11` (`oklch(49.1% 0.081 203)`)<br>dark: `teal-dark-11` (`oklch(77.3% 0.099 203)`) |
| `--dui-color-code-number` | Numbers and units in highlighted code (4.5:1 on surface-sunken) | light: `red-11` (`oklch(48% 0.16 27)`)<br>dark: `red-dark-11` (`oklch(80% 0.114 27)`) |
| `--dui-color-code-punctuation` | Brackets, braces and separators in highlighted code (4.5:1 on surface-sunken) | light: `neutral-punctuation` (`oklch(37% 0.03 45)`)<br>dark: `neutral-dark-punctuation` (`oklch(84% 0.015 75)`) |
| `--dui-font-body` | Body font stack | `--dui-font-stack-system-ui` (`system-ui`, `-apple-system`, `"Segoe UI Variable Text"`, `"Segoe UI"`, Roboto, `"Noto Sans"`, `"Helvetica Neue"`, Arial, `sans-serif`) |
| `--dui-font-mono` | Code font stack | `--dui-font-stack-monospace` (`ui-monospace`, …, `monospace`) |
| `--dui-font-weight-body` | Body weight | `font-weight-400` (400) |
| `--dui-font-weight-strong` | strong, legends, th | `font-weight-600` (600) |
| `--dui-font-weight-ui` | Interface labels: buttons, nav rows and field labels | `font-weight-500` (500) |
| `--dui-font-weight-heading` | h1–h6 | `font-weight-600` (600) |
| `--dui-step--1` | small, captions, and the UI text size | `font-size-0-875` (0.875rem, 14px) |
| `--dui-step-0` | Body text, h6 | `font-size-1` (1rem) |
| `--dui-step-1` | h5 | `font-size-1-125` (1.125rem) |
| `--dui-step-2` | h4 | `font-size-1-375` (1.375rem) |
| `--dui-step-3` | h3, page titles | `font-size-fluid-3` (`clamp()`, 1.5rem to 1.875rem) |
| `--dui-step-4` | h2 | `font-size-fluid-4` (`clamp()`, 1.75rem to 2.375rem) |
| `--dui-step-5` | h1, docs and marketing heroes | `font-size-fluid-5` (`clamp()`, 2rem to 3rem) |
| `--dui-font-size-ui` | Interface text: buttons, fields, selects, nav, menu and listbox items, tabs, tooltips, table cells | `--dui-step--1` (14px) |
| `--dui-font-size-field` | Text in fields, selects and text areas: the UI size, at least 16px under a coarse pointer | `--dui-font-size-ui`; `max(--dui-font-size-ui, --dui-step-0)` under `pointer: coarse` |
| `--dui-font-size-badge` | Badge text, as shadcn/ui sets its badge | `font-size-0-75` (0.75rem, 12px) |
| `--dui-font-size-page-title` | The `h1` of a page header or an app shell | `--dui-step-4` (2.375rem at most, one step above h2) |
| `--dui-font-size-code` | code, kbd, samp, pre (relative) | `font-size-relative-90` (0.9em) |
| `--dui-line-height-body` | Body text | `leading-150` (1.5) |
| `--dui-line-height-heading` | Headings, buttons, pre | `leading-120` (1.2) |
| `--dui-line-height-display` | h1 | `leading-110` (1.1) |
| `--dui-letter-spacing-heading` | h2, h3 | `tracking-tight` (-0.02em) |
| `--dui-letter-spacing-display` | h1 | `tracking-tighter` (-0.03em) |
| `--dui-measure` | Max line length for prose | `size-60ch` (60ch) |
| `--dui-space-3xs` | Space scale | `space-1` (0.125rem) |
| `--dui-space-2xs` | Space scale | `space-2` (0.25rem) |
| `--dui-space-xs` | Space scale | `space-3` (0.5rem) |
| `--dui-space-s` | Space scale | `space-4` (0.75rem) |
| `--dui-space-m` | Space scale; default flow rhythm and .stack gap | `space-5` (1rem) |
| `--dui-space-l` | Space scale; default .grid gap | `space-6` (1.5rem) |
| `--dui-space-xl` | Space scale; space above h1–h3 | `space-7` (2rem) |
| `--dui-space-2xl` | Space scale | `space-8` (3rem) |
| `--dui-space-3xl` | Space scale | `space-9` (4rem) |
| `--dui-size-target` | Comfortable control height (WCAG 2.5.8 needs 24px; this gives 36px) | `size-2-25` (2.25rem); `size-2-75` (2.75rem) under `pointer: coarse` |
| `--dui-size-target-compact` | Compact control height | `size-2` (2rem); `size-2-75` under `pointer: coarse` |
| `--dui-size-target-small` | Small buttons (32px, 44px under a coarse pointer) | `size-2` (2rem) |
| `--dui-size-target-large` | Large buttons | `size-2-5` (2.5rem); `size-3-25` (3.25rem) under `pointer: coarse` |
| `--dui-size-target-row` | Comfortable row height of nav, menu, listbox and list items | `size-2` (2rem); `size-2-75` under `pointer: coarse` |
| `--dui-size-target-row-compact` | Compact row height | `size-1-75` (1.75rem); `size-2-75` under `pointer: coarse` |
| `--dui-size-check` | Checkbox and radio size | `size-1-25` (1.25rem) |
| `--dui-size-column-min` | Default .grid min column width | `size-16` (16rem) |
| `--dui-size-menu-min` | Min width of menus and nav dropdowns | `size-12` (12rem) |
| `--dui-size-drawer` | Drawer width (all of the viewport when narrower) | `size-24` (24rem) |
| `--dui-size-page` | Max inline size of a page's content column (the examples' header, main and footer) | `size-72` (72rem) |
| `--dui-size-icon` | Decorative icons beside a label: nav links and group summaries | `size-1-25` (1.25rem) |
| `--dui-size-icon-inline` | Icons inside buttons, menu items, options and toolbars | `size-1` (1rem) |
| `--dui-icon-stroke-width` | Stroke width of `[data-icon]` SVGs, set with the CSS `stroke-width` property | `stroke-1-75` (1.75) |
| `--dui-size-sidebar` | Inline size of an app shell's primary sidebar beside main | `size-16` (16rem) |
| `--dui-size-sidebar-aux` | Inline size of an app shell's auxiliary (inline-end) sidebar beside main | `size-20` (20rem) |
| `--dui-size-pane` | Max block size of a pane that scrolls on its own beside others (the detail of a list-detail when side by side) | `size-100svh` (100svh, the small viewport height) |
| `--dui-radius-scale` | Radius knob: multiplies the control and surface radii; `0` gives square corners | `factor-1` (1) |
| `--dui-radius-control` | Controls, buttons, inline code | `radius-2` (0.5rem, 8px) × `--dui-radius-scale` |
| `--dui-radius-surface` | Panels, cards, pre, dialog, details, media | `radius-3` (0.75rem, 12px) × `--dui-radius-scale` |
| `--dui-radius-nested` | Items inside a surface padded by `--dui-space-gap-tight` (menu, listbox, nav dropdown): concentric corners | `--dui-radius-surface` − `--dui-space-gap-tight`, at least 0 (8px at scale 1) |
| `--dui-radius-pill` | Fully rounded ends (not scaled) | `radius-round` (999rem) |
| `--dui-space-panel-inset` | Gap between a floating panel and the viewport or frame edge | `--dui-space-xs` (0.5rem) |
| `--dui-border-width` | Hairline width | `border-1` (1px) |
| `--dui-border-width-emphasis` | blockquote rule, alert start rule, invalid field | `border-4` (0.25rem) |
| `--dui-border-width-indicator` | The selected tab's and the current nav item's bar in forced colors only | `border-3` (3px) |
| `--dui-underline-offset` | Link underline offset | `underline-offset-015em` (0.15em) |
| `--dui-underline-thickness` | Link underline | `underline-1` (0.0625em) |
| `--dui-underline-thickness-hover` | Link underline on hover | `underline-2` (0.125em) |
| `--dui-focus-width` | Focus ring width | `border-3` (3px) |
| `--dui-focus-offset` | Focus ring offset: the ring hugs the edge | `border-0` (0) |
| `--dui-motion-scale` | Multiplies every motion duration | `factor-1` (1) |
| `--dui-motion-movement` | Lets things slide, lift and zoom (1) or not (0); `0` with reduced motion | `factor-1` (1) |
| `--dui-motion-enabled` | `0` with `data-motion="none"`: every duration is `0s`, whatever scale is set inside | `factor-1` (1) |
| `--dui-motion-easing-standard` | State changes that stay on screen: hover, press, switch | `easing-ease-out` (`cubic-bezier(0.2, 0, 0, 1)`) |
| `--dui-motion-easing-enter` | Things arriving: dialogs, drawers, popovers, toasts | `easing-decelerate` (`cubic-bezier(0, 0, 0, 1)`) |
| `--dui-motion-easing-exit` | Things leaving | `easing-accelerate` (`cubic-bezier(0.3, 0, 1, 1)`) |
| `--dui-motion-easing-spring` | Popover, menu and drawer entrances | `easing-spring` (a [`linear()`](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/easing-function/linear) spring with no overshoot); `--dui-motion-easing-enter`'s curve where `linear()` is unsupported |
| `--dui-elevation-strength` | How much of `--dui-color-shadow` each shadow uses (0% to 100%) | `mix-100` (100%) |
| `--dui-elevation-surface-step` | Dark scheme: text color mixed into the surface per level | `mix-3` (3%) |
| `--dui-density-scale` | Density knob: `1` comfortable, `0` compact (`data-density`); in between interpolates, never below `0` | `factor-1` (1) |
| `--dui-opacity-disabled` | Disabled controls, `disabled` and `aria-disabled="true"` | `opacity-60` (0.6) |
| `--dui-contrast` | Contrast knob: `1` default, `1.5` under `prefers-contrast: more` or `data-contrast="more"`; below `1` softens hairlines and tints only | `factor-1` (1) |
| `--dui-tint-amount` | How much of a tone goes into a tinted surface | `mix-8` (8%) × `--dui-contrast` |
| `--dui-border-tint-amount` | How much of the text color goes into a tinted border (badges) | `mix-35` (35%) × `--dui-contrast` |
| `--dui-color-accent-text` | Accent as text (links, quiet buttons, accent badges). Relative color of `--dui-color-accent` | light: `oklch(47% 0.19 272)`<br>dark: `oklch(78% 0.11 272)` |
| `--dui-color-link` | Links | `--dui-color-accent-text` |
| `--dui-color-focus` | Focus ring (3:1 against surfaces) | light: `--dui-color-accent`<br>dark: `--dui-color-accent-text` |
| `--dui-color-accent-hover` | Accent solid hover | `oklch(from --dui-color-accent)` with lightness 0.02 lower |
| `--dui-color-primary-hover` | Primary fill hover | light: `oklch(26% 0.002 0)`<br>dark: `oklch(90% 0.004 0)`, hue from `--dui-color-primary` |
| `--dui-font-heading` | Heading font stack | `--dui-font-body` |
| `--dui-color-accent-surface` | Accent badge background | `color-mix()` of `--dui-tint-amount` `--dui-color-accent` into `--dui-color-surface` |
| `--dui-color-success-surface` | Success badge background | same, with `--dui-color-success` |
| `--dui-color-warning-surface` | Warning badge background | same, with `--dui-color-warning` |
| `--dui-color-danger-surface` | Danger badge and alert background | same, with `--dui-color-danger` |
| `--dui-color-info-surface` | Info alert background | same, with `--dui-color-info` |
| `--dui-color-surface-inverse` | Tooltip background | `--dui-color-text` |
| `--dui-color-text-inverse` | Tooltip text | `--dui-color-surface` |
| `--dui-motion-duration-fast` | Hover, press, switch, popovers and menus | `duration-120` (120ms) × `--dui-motion-scale` × `--dui-motion-enabled` |
| `--dui-motion-duration-normal` | Dialogs and toasts | `duration-200` (200ms) × `--dui-motion-scale` × `--dui-motion-enabled` |
| `--dui-motion-duration-slow` | The drawer | `duration-300` (300ms) × `--dui-motion-scale` × `--dui-motion-enabled` |
| `--dui-motion-distance` | How far a dialog or toast lifts as it fades in | `space-4` (0.75rem) × `--dui-motion-movement` |
| `--dui-motion-zoom` | Scale a popover or menu grows from | 0.95, or 1 when `--dui-motion-movement` is 0 |
| `--dui-motion-press-scale` | Scale of a pressed (`:active`) button | 0.98, or 1 when `--dui-motion-movement` is 0 |
| `--dui-elevation-shadow-color` | Shadow color after strength | `color-mix()` of `--dui-color-shadow` at `--dui-elevation-strength` |
| `--dui-elevation-ring` | The 1px ring in the hairline color that every elevated level includes | `0 0 0 1px` `--dui-color-border` |
| `--dui-elevation-highlight` | Dark scheme only: a 1px top inset highlight on levels 2 to 4 | `inset 0 1px 0 0`, transparent in light, the dark text color at 6% in dark |
| `--dui-size-control` | Min block size of controls, buttons and check labels | `--dui-size-target` (36px), `--dui-size-target-compact` (32px) when compact; 44px under `pointer: coarse` |
| `--dui-size-row` | Min block size of nav, menu, listbox, combobox option and list-detail items | `--dui-size-target-row` (32px), `--dui-size-target-row-compact` (28px) when compact; 44px under `pointer: coarse` |
| `--dui-space-control-block` | Block padding of controls, buttons and items | `space-3` (0.5rem), `space-2` (0.25rem) when compact |
| `--dui-space-control-inline` | Inline padding of text fields and items | `space-4` (0.75rem), `space-3` (0.5rem) when compact |
| `--dui-space-button-inline` | Inline padding of buttons and tabs | `space-5` (1rem), `space-4` (0.75rem) when compact |
| `--dui-space-gap` | Gap between the parts of a control (icon and label, check and label) | `space-3` (0.5rem), `space-2` (0.25rem) when compact |
| `--dui-space-gap-tight` | Gap and padding in groups of controls: field, toolbar, pagination, menu | `space-2` (0.25rem), `space-1` (0.125rem) when compact |
| `--dui-space-cell` | Table cell padding | `space-3` (0.5rem), `space-2` (0.25rem) when compact |
| `--dui-elevation-control` | A 1px shadow under secondary buttons, without the ring (they have a border) | `0 1px 2px -1px` `--dui-elevation-shadow-color` |
| `--dui-elevation-0` … `--dui-elevation-4` | Shadow per level | `none`; level 1 is the ring and `0 1px 2px -1px`; levels 2 to 4 add the dark highlight, the ring and two layers with a negative spread |
| `--dui-elevation-0-surface` … `--dui-elevation-4-surface` | Surface per level | light: `--dui-color-surface`<br>dark: `--dui-color-surface` with N × `--dui-elevation-surface-step` of `--dui-color-text` |
| `--dui-elevation-flat`, `-raised`, `-overlay`, `-popover`, `-dialog` | Shadow by role | levels 0, 1, 2, 3, 4 |
| `--dui-elevation-flat-surface`, `-raised-surface`, `-overlay-surface`, `-popover-surface`, `-dialog-surface` | Surface by role | level 0 to 4 surfaces |
| `--dui-elevation-panel` | Shadow of floating panels: the app shell's main content panel | `--dui-elevation-1` |
| `--dui-elevation-panel-surface` | Surface of floating panels | `--dui-color-surface` |
| `--dui-shadow-raised` | **Deprecated**, removed in the next release: use `--dui-elevation-raised` | `--dui-elevation-1` |
| `--dui-duration-fast` | **Deprecated**, removed in the next release | `--dui-motion-duration-fast` |
| `--dui-duration-normal` | **Deprecated**, removed in the next release | `--dui-motion-duration-normal` |
| `--dui-easing-standard` | **Deprecated**, removed in the next release | `--dui-motion-easing-standard` |

Derived (re-resolved on each theme scope and on every `[data-motion]`, `[data-density]` and `[data-contrast]` element): `--dui-color-text-muted`, `--dui-color-border`, `--dui-tint-amount`, `--dui-border-tint-amount`, `--dui-color-accent-text`, `--dui-color-link`,
`--dui-color-focus`, `--dui-color-accent-hover`, `--dui-color-primary-hover`, `--dui-font-heading`, `--dui-font-size-ui`, `--dui-font-size-field`, `--dui-font-size-page-title`, `--dui-color-accent-surface`,
`--dui-color-success-surface`, `--dui-color-warning-surface`, `--dui-color-danger-surface`,
`--dui-color-info-surface`, `--dui-color-surface-inverse`, `--dui-color-text-inverse`, `--dui-radius-control`, `--dui-radius-surface`, `--dui-radius-nested`, every
`--dui-motion-duration-*`, `--dui-motion-distance`, `--dui-motion-zoom`, `--dui-motion-press-scale`, every `--dui-elevation-*`
except the two knobs, the eight density tokens (`--dui-size-control`, `--dui-size-row` and the `--dui-space-control-*`,
`-button-inline`, `-gap*` and `-cell` spaces), and the deprecated aliases.

## Density

`data-density="compact"` on any element tightens every component inside it. `data-density="comfortable"`
is the default and restores it inside a compact area. Density changes space only: control heights
(36px to 32px), row heights (32px to 28px), padding, gaps and table cells. Text size never changes, and every target stays at least
24 by 24 CSS pixels ([2.5.8 Target Size (Minimum)](https://www.w3.org/WAI/WCAG22/Understanding/target-size-minimum.html)).

- The attribute sets one knob, `--dui-density-scale` (`1` comfortable, `0` compact). Components read the
  density tokens above, each derived from the knob between its comfortable and compact value, and
  re-declared on every `[data-density]` element like the theme tokens, so nesting works both ways.
- Comfortable values point at other semantic tokens (`--dui-size-target`, the space scale), so a theme
  that changes those moves density with it. `small` and `large` buttons keep their sizes at every density.
- **Our choice:** an attribute on any ancestor, not a media query, because density follows the task (a data
  table, a toolbar), not the device, and one page often mixes both.
- **Our choice:** no [`zoom`](https://developer.mozilla.org/en-US/docs/Web/CSS/zoom) or font-size scaling,
  because both shrink text against the user's text size and scale targets below 24px.

[`examples/patterns/density.html`](https://domestic-ui.odonckers.dev/patterns/density.md) shows the same form, table and toolbar at
both densities side by side. [`explainers/density.md`](https://domestic-ui.odonckers.dev/explainers/density.md) has the full contract.

## Live example

### Forest theme

```html
<section class="panel stack" data-theme="forest" aria-labelledby="forest-title">
  <nav aria-label="Breadcrumb, forest theme" data-breadcrumb>
    <ol>
      <li><a href="#forest-title">Home</a></li>
      <li><a href="#forest-title">Releases</a></li>
      <li><a href="#forest-title" aria-current="page">Release notes</a></li>
    </ol>
  </nav>
  <h2 id="forest-title">Forest theme</h2>
  <p>Release notes are ready for review. <a href="#forest-title">Read the summary</a> before the meeting.</p>
  <p class="cluster">
    <span data-badge>Draft</span>
    <span data-badge="accent">New</span>
    <span data-badge="success">Passing</span>
    <span data-badge="warning">Review</span>
    <span data-badge="danger">Blocked</span>
  </p>
  <form action="#forest-title" class="stack">
    <div data-field>
      <label for="forest-email">Email</label>
      <input id="forest-email" name="email" type="email" autocomplete="email" value="ada@" aria-invalid="true" aria-describedby="forest-email-hint forest-email-error">
      <p id="forest-email-hint" data-field-hint>Release notes go to this address.</p>
      <p id="forest-email-error" data-field-error>Error: enter an email address like name@example.com.</p>
    </div>
    <label><input type="checkbox" role="switch" name="notify" checked> Notify subscribers</label>
    <div class="cluster">
      <button type="submit">Publish</button>
      <button type="button" data-button="secondary">Save draft</button>
      <button type="button" data-button="quiet">Discard</button>
    </div>
  </form>
  <div data-alert="warning">
    <p><strong>Warning:</strong> Two checks are still running.</p>
  </div>
  <dui-tabs>
    <nav aria-label="Release, forest theme">
      <ul>
        <li><a href="#forest-tab-notes">Notes</a></li>
        <li><a href="#forest-tab-checks">Checks</a></li>
      </ul>
    </nav>
    <section id="forest-tab-notes">
      <h3>Notes</h3>
      <p>Two bug fixes and a new token.</p>
    </section>
    <section id="forest-tab-checks">
      <h3>Checks</h3>
      <p>Lint passed. Tests are running.</p>
    </section>
  </dui-tabs>
  <article data-card="link">
    <h3><a href="#forest-title">Upgrade guide</a></h3>
    <p>What to change when you update.</p>
  </article>
  <details>
    <summary>What changed?</summary>
    <p>Two bug fixes and a new <code>--dui-color-success</code> token.</p>
  </details>
</section>
```

### Forest theme CSS

In the `<head>` of the live example above.

```html
<style id="forest-theme">
  [data-theme="forest"] {
    --dui-color-surface: light-dark(#f7f5ef, #141a16);
    --dui-color-surface-raised: light-dark(#eeeadf, #1d2620);
    --dui-color-text: light-dark(#1d2a22, #e4ebe3);
    --dui-color-border: light-dark(#d8d1bf, #34433a);
    --dui-color-accent: light-dark(#2f6b3f, #7fcf95);
    --dui-color-accent-contrast: light-dark(#fff, #0f1a13);
    --dui-color-primary: light-dark(#173528, #d7f5e3);
    --dui-color-primary-contrast: light-dark(#fff, #0f1a13);
    --dui-font-display: var(--dui-font-body);
    --dui-radius-control: 0.125rem;
    --dui-radius-surface: 0.25rem;
  }
</style>
```

### Radius scale

```html
<div class="grid">
  <section class="radius-panel stack" data-theme style="--dui-radius-scale: 0" aria-labelledby="radius-0-title">
    <h3 id="radius-0-title">Scale 0</h3>
    <p><button type="button">Secondary</button> <button type="submit">Save</button></p>
    <dui-menu>
      <button type="button" popovertarget="radius-0-menu">Menu</button>
      <div id="radius-0-menu" popover data-popover>
        <button type="button">Rename</button>
        <button type="button">Archive</button>
      </div>
    </dui-menu>
    <article data-card>
      <h4>A card</h4>
      <p>Square corners.</p>
    </article>
  </section>
  <section class="radius-panel stack" data-theme style="--dui-radius-scale: 1" aria-labelledby="radius-1-title">
    <h3 id="radius-1-title">Scale 1</h3>
    <p><button type="button">Secondary</button> <button type="submit">Save</button></p>
    <dui-menu>
      <button type="button" popovertarget="radius-1-menu">Menu</button>
      <div id="radius-1-menu" popover data-popover>
        <button type="button">Rename</button>
        <button type="button">Archive</button>
      </div>
    </dui-menu>
    <article data-card>
      <h4>A card</h4>
      <p>The default corners.</p>
    </article>
  </section>
  <section class="radius-panel stack" data-theme style="--dui-radius-scale: 1.5" aria-labelledby="radius-15-title">
    <h3 id="radius-15-title">Scale 1.5</h3>
    <p><button type="button">Secondary</button> <button type="submit">Save</button></p>
    <dui-menu>
      <button type="button" popovertarget="radius-15-menu">Menu</button>
      <div id="radius-15-menu" popover data-popover>
        <button type="button">Rename</button>
        <button type="button">Archive</button>
      </div>
    </dui-menu>
    <article data-card>
      <h4>A card</h4>
      <p>Rounder corners.</p>
    </article>
  </section>
</div>
```

### Contrast

```html
<div class="grid">
  <section class="radius-panel stack" data-contrast style="--dui-contrast: 0.8" aria-labelledby="contrast-08-title">
    <h3 id="contrast-08-title">0.8</h3>
    <p>Body text. <span class="muted">Muted text stays at 4.5:1.</span></p>
    <p><span data-badge="accent">New</span> <span data-badge="danger">Overdue</span></p>
    <div data-alert="info">
      <p><strong>Info:</strong> A tinted surface with a tinted border.</p>
    </div>
  </section>
  <section class="radius-panel stack" data-contrast aria-labelledby="contrast-1-title">
    <h3 id="contrast-1-title">1, the default</h3>
    <p>Body text. <span class="muted">Muted text.</span></p>
    <p><span data-badge="accent">New</span> <span data-badge="danger">Overdue</span></p>
    <div data-alert="info">
      <p><strong>Info:</strong> A tinted surface with a tinted border.</p>
    </div>
  </section>
  <section class="radius-panel stack" data-contrast="more" aria-labelledby="contrast-more-title">
    <h3 id="contrast-more-title">More</h3>
    <p>Body text. <span class="muted">Muted text, closer to the body text.</span></p>
    <p><span data-badge="accent">New</span> <span data-badge="danger">Overdue</span></p>
    <div data-alert="info">
      <p><strong>Info:</strong> A tinted surface with a tinted border.</p>
    </div>
  </section>
</div>
```

### Inverse band

```html
<section class="radius-panel stack" data-surface="inverse" aria-labelledby="inverse-band-title">
  <h3 id="inverse-band-title">Selected work</h3>
  <nav aria-label="Work">
    <ul class="cluster">
      <li><a href="#inverse-band-title" aria-current="page">All</a></li>
      <li><a href="#inverse-band-title">Apps</a></li>
      <li><a href="#inverse-band-title">Writing</a></li>
    </ul>
  </nav>
  <figure>
    <blockquote><p>Plain HTML that looks finished.</p></blockquote>
    <figcaption>A caption in muted text, still 4.5:1.</figcaption>
  </figure>
  <p><a href="#inverse-band-title">Read the case study</a></p>
</section>
```
