# Design tokens, dark mode and themes

> iVOLT design tokens: palette, semantic colours, spacing, type, radius, shadow, focus, motion and breakpoints, with light, dark and system themes.

Source: https://ivolt.intervolutions.com/foundations/tokens-and-themes · iVOLT 1.1.2 · English

Every visual decision is a custom property prefixed `--iv-`, generated from one JSON source. Override any of them on `:root` or on a scope; nothing needs recompiling.

```
:root {
  --iv-color-primary: #4338CA;      /* your brand */
  --iv-color-on-primary: #FFFFFF;
  --iv-radius-md: 0.25rem;
}
.checkout { --iv-button-radius: var(--iv-radius-full); }  /* component-local */
```

New in 1.1 · the headline

## One colour repaints the whole system.

Pick a primary. Buttons and their gradient, focus rings, links, badges, progress, switches, chips and gradient text follow it, because iVOLT 1.1 mixes every token that depends on it in CSS, with color-mix(). No build, no JavaScript, no fifteen variables by hand.

Cobalt

Rose

Violet

Emerald

Amber

Graphite

Or your own

Measured contrast (WCAG 2), worst case of the text on the button (at rest and on hover) and the colour as a link:light **7.0:1** · dark **8.2:1**light **6.2:1** · dark **6.9:1**light **7.1:1** · dark **8.0:1**light **5.4:1** · dark **9.6:1**light **5.0:1** · dark **11.1:1**light **14.8:1** · dark **14.6:1**

All it takes

```
:root {
  --iv-color-primary: #BE123C;
  --iv-color-on-primary: #FFFFFF;
}
```

Gradient text

Deploy

Preview

Beta

New

Filter

A text link

Auto deploy

Focus ring

Ten tokens, one seed

- `--iv-color-primary`the seed
- `--iv-color-primary-hover`hover
- `--iv-color-primary-active`pressed
- `--iv-color-primary-subtle`tint
- `--iv-color-primary-border`edge
- `--iv-color-focus`focus ring
- `--iv-glow-primary`glow
- `--iv-focus-halo`halo
- `--iv-gradient-brand`brand gradient
- `--iv-gradient-primary`button gradient

Sample controls: they do nothing here.

## Where the mixing happens, and palettes

New in 1.1 The ten derived tokens are declared once, as `color-mix(in oklab, var(--iv-color-primary), var(--iv-mix-<name>))`, on `:root`, on every `[data-iv-theme]` scope and on every `[data-iv-palette]` scope. That is where you set the primary: on `:root` for the whole site, or on one of those scopes for a part of it. On any other element the derived tokens are already computed by the time they are inherited, so changing the primary on a plain `<div>` recolours the primary itself but not its hover or its gradient — add `data-iv-palette` (with no value) to that element and it re-mixes them. The defaults resolve to the 1.0 values within ΔE2000 < 1, checked in a browser on every build, so a site that never touches the primary sees no change.

`data-iv-palette` with a value points the primary of a subtree at another role of the theme: `accent`, `success`, `warning`, `danger`, `info` or `neutral` (the text colour on the page colour). The primary and the ink drawn on it change together, and every derived token follows — a danger zone in a settings page, a success panel, a monochrome footer, with one attribute and no new classes.

Couldn't load the demo. [Open alone](https://ivolt.intervolutions.com/stage/theme/one-colour.html?id=fx-theme-one-colour)

```html
<div class="iv-stack iv-u-gap-6">
  <p class="iv-u-m-0 iv-u-text-sm iv-u-text-muted">Sample controls: nothing here does anything. The three panels use the same markup. The first keeps the default cobalt; the second sets one variable, <code>--iv-color-primary</code> (and the text drawn on it), on a scope marked <code>data-iv-palette</code> — a rose mixed with the text colour of the theme, so it stays readable in light and dark; the third points the primary at the success role with <code>data-iv-palette="success"</code>. Hover states, tints, focus rings, glows and gradients are mixed from that one colour.</p>

  <div class="iv-grid iv-u-gap-4 iv-u-grid-cols-1 iv-u-lg-grid-cols-3">
    <section class="iv-card" aria-labelledby="oc-default">
      <div class="iv-card__body iv-stack iv-u-gap-4">
        <h3 class="iv-card__title" id="oc-default">Default cobalt</h3>
        <div class="iv-cluster">
          <button class="iv-button iv-button--primary" type="button">Deploy</button>
          <button class="iv-button iv-button--secondary" type="button">Preview</button>
        </div>
        <div class="iv-cluster">
          <span class="iv-badge iv-badge--primary">Beta</span>
          <span class="iv-badge iv-badge--solid iv-badge--primary">New</span>
          <a href="#oc-default">A text link</a>
        </div>
        <progress class="iv-progress" value="64" max="100" aria-label="Sample progress, 64 percent"></progress>
        <label class="iv-switch"><input type="checkbox" checked><span class="iv-switch__track" aria-hidden="true"><span class="iv-switch__thumb"></span></span>Auto deploy</label>
        <p class="iv-gradient-text iv-u-m-0 iv-u-text-xl iv-u-font-bold">Gradient text</p>
      </div>
    </section>

    <section class="iv-card" aria-labelledby="oc-custom" data-iv-palette style="--iv-color-primary: color-mix(in oklab, #E91E63 72%, var(--iv-color-text)); --iv-color-on-primary: var(--iv-color-bg)">
      <div class="iv-card__body iv-stack iv-u-gap-4">
        <h3 class="iv-card__title" id="oc-custom">One variable: rose</h3>
        <div class="iv-cluster">
          <button class="iv-button iv-button--primary" type="button">Deploy</button>
          <button class="iv-button iv-button--secondary" type="button">Preview</button>
        </div>
        <div class="iv-cluster">
          <span class="iv-badge iv-badge--primary">Beta</span>
          <span class="iv-badge iv-badge--solid iv-badge--primary">New</span>
          <a href="#oc-custom">A text link</a>
        </div>
        <progress class="iv-progress" value="64" max="100" aria-label="Sample progress, 64 percent"></progress>
        <label class="iv-switch"><input type="checkbox" checked><span class="iv-switch__track" aria-hidden="true"><span class="iv-switch__thumb"></span></span>Auto deploy</label>
        <p class="iv-gradient-text iv-u-m-0 iv-u-text-xl iv-u-font-bold">Gradient text</p>
      </div>
    </section>

    <section class="iv-card" aria-labelledby="oc-success" data-iv-palette="success">
      <div class="iv-card__body iv-stack iv-u-gap-4">
        <h3 class="iv-card__title" id="oc-success">Palette: success</h3>
        <div class="iv-cluster">
          <button class="iv-button iv-button--primary" type="button">Deploy</button>
          <button class="iv-button iv-button--secondary" type="button">Preview</button>
        </div>
        <div class="iv-cluster">
          <span class="iv-badge iv-badge--primary">Beta</span>
          <span class="iv-badge iv-badge--solid iv-badge--primary">New</span>
          <a href="#oc-success">A text link</a>
        </div>
        <progress class="iv-progress" value="64" max="100" aria-label="Sample progress, 64 percent"></progress>
        <label class="iv-switch"><input type="checkbox" checked><span class="iv-switch__track" aria-hidden="true"><span class="iv-switch__thumb"></span></span>Auto deploy</label>
        <p class="iv-gradient-text iv-u-m-0 iv-u-text-xl iv-u-font-bold">Gradient text</p>
      </div>
    </section>
  </div>
</div>
```

```css
.iv-root {
  --iv-color-primary: color-mix(in oklab, #E91E63 72%, var(--iv-color-text));
  --iv-color-on-primary: var(--iv-color-bg);
}
```

`--iv-color-on-primary`, the colour of text drawn on the primary, is not derived: CSS in the browsers iVOLT supports cannot pick a contrasting colour. Set it with the primary and check the pair; the measured figures above show how much room each sample colour leaves. The recipes themselves are public tokens, one per derived value and per theme, in the form `<colour> <percentage>`; they can be tuned, and their values may be refined in a minor release:

| Recipe | Light | Dark |
| --- | --- | --- |
| `--iv-mix-primary-hover` | `oklab(0.0308 0.0244 -0.0642) 13%` | `oklab(0.9857 -0.0058 0.0019) 27%` |
| `--iv-mix-primary-active` | `oklab(0.0545 0.0176 -0.0069) 32%` | `oklab(0.5901 -0.045 -0.218) 50%` |
| `--iv-mix-primary-subtle` | `oklab(0.9998 -0.0049 -0.0042) 93%` | `transparent 88%` |
| `--iv-mix-primary-border` | `transparent 45%` | `transparent 50%` |
| `--iv-mix-focus` | `transparent 0%` | `var(--iv-color-accent) 100%` |
| `--iv-mix-focus-halo` | `transparent 65%` | `transparent 68%` |
| `--iv-mix-glow-primary` | `transparent 65%` | `transparent 55%` |
| `--iv-mix-glow-secondary` | `transparent 70%` | `transparent 60%` |
| `--iv-mix-brand-start` | `transparent 0%` | `oklab(0.9983 -0.1379 0.0123) 42%` |
| `--iv-mix-brand-end` | `oklab(0.4576 0.1379 -0.1885) 20%` | `oklab(0.1329 0.2574 -0.5042) 20%` |
| `--iv-mix-gradient-start` | `oklab(0.7927 -0.0692 -0.1693) 20%` | `oklab(0.9994 -0.0912 0.0098) 50%` |
| `--iv-mix-gradient-end` | `oklab(0.4576 0.1379 -0.1885) 20%` | `oklab(0.5621 0.2798 -0.2486) 20%` |

A theme of your own can also change a recipe: `--iv-mix-brand-end: var(--iv-color-accent) 35%` ends both gradients a third of the way to your accent, which is what the presets of the [theme gallery](https://ivolt.intervolutions.com/themes) do.

## Themes

`data-iv-theme` accepts `light` (default when absent), `dark` and `system`. Scopes nest and the nearest explicit value wins; `system` follows `prefers-color-scheme` without JavaScript or storage.

Couldn't load the demo. [Open alone](https://ivolt.intervolutions.com/stage/theme/nested.html?id=fx-theme-nested)

```html
<div class="iv-grid iv-u-gap-4 iv-u-grid-cols-1 iv-u-md-grid-cols-3">
  <section class="iv-card" data-iv-theme="light"><div class="iv-card__body"><h3 class="iv-card__title">Light scope</h3><button class="iv-button iv-button--primary" type="button">Primary</button></div></section>
  <section class="iv-card" data-iv-theme="dark"><div class="iv-card__body"><h3 class="iv-card__title">Dark scope</h3><button class="iv-button iv-button--primary" type="button">Primary</button>
    <section class="iv-card iv-u-mt-4" data-iv-theme="system"><div class="iv-card__body"><p class="iv-u-m-0">System inside dark follows the OS.</p></div></section>
  </div></section>
  <section class="iv-card" data-iv-theme="system"><div class="iv-card__body"><h3 class="iv-card__title">System scope</h3><button class="iv-button iv-button--primary" type="button">Primary</button></div></section>
</div>
```

The optional `theme` module adds `getTheme()`, `setTheme(theme, { persist })`, `resolveTheme()` and `restoreTheme()`, and dispatches `iv:themechange` on `document`. Persistence is opt-in. To avoid a flash before the stored theme applies, add a tiny inline script in `<head>`; with a strict CSP allow it by hash or nonce.

### Switching with a view transition

New in 1.1 `@intervolutions/ivolt/theme-transition` exports `setThemeWithTransition(theme, options)`: the same call as `setTheme`, wrapped in `document.startViewTransition` where the browser has it and the reader has not asked for less motion, so the page cross-fades between themes instead of flipping. Elsewhere it is `setTheme` as it was. It returns a promise of the resolved theme, fires `iv:themechange` once the browser has taken its snapshot, and throws an `IvError` synchronously for an invalid theme. It is a subpath of its own, so `theme.js` and the default bundle did not grow.

```
import { setThemeWithTransition } from "@intervolutions/ivolt/theme-transition";
button.addEventListener("click", () => setThemeWithTransition("dark", { persist: true }));
```

## Semantic colours

| Token | Light | Dark |
| --- | --- | --- |
| `--iv-color-bg` | `#FFFFFF` | `#04070F` |
| `--iv-color-surface` | `#F5F7FC` | `#070D1C` |
| `--iv-color-surface-raised` | `#FFFFFF` | `#0C1330` |
| `--iv-color-text` | `#0B1230` | `#EEF2FB` |
| `--iv-color-text-muted` | `#4F5B7A` | `#A8B3CC` |
| `--iv-color-border` | `#D3DAEA` | `#33406A` |
| `--iv-color-border-strong` | `#6B7896` | `#6B7896` |
| `--iv-color-primary` | `#1D4FC4` | `#66B1FF` |
| `--iv-color-on-primary` | `#FFFFFF` | `#06122B` |
| `--iv-color-primary-hover` | `#1A3FA8` | `#8FC6FF` |
| `--iv-color-primary-active` | `#172F7A` | `#3D94FF` |
| `--iv-color-primary-subtle` | `#EAF4FF` | `rgb(102 177 255 / 0.12)` |
| `--iv-color-accent` | `#0B6B8A` | `#73DFFF` |
| `--iv-color-on-accent` | `#FFFFFF` | `#06122B` |
| `--iv-color-success` | `#4F7A12` | `#8BBF3A` |
| `--iv-color-on-success` | `#FFFFFF` | `#06122B` |
| `--iv-color-success-subtle` | `#F1F8E4` | `rgb(139 191 58 / 0.12)` |
| `--iv-color-danger` | `#C22E26` | `#FF9AA4` |
| `--iv-color-on-danger` | `#FFFFFF` | `#06122B` |
| `--iv-color-danger-subtle` | `#FFF1F0` | `rgb(255 154 164 / 0.12)` |
| `--iv-color-warning` | `#8F5C00` | `#FBBF24` |
| `--iv-color-on-warning` | `#FFFFFF` | `#06122B` |
| `--iv-color-warning-subtle` | `#FFF8E6` | `rgb(251 191 36 / 0.12)` |
| `--iv-color-info` | `#3D47C2` | `#8B95FF` |
| `--iv-color-on-info` | `#FFFFFF` | `#06122B` |
| `--iv-color-info-subtle` | `#EEF0FF` | `rgb(139 149 255 / 0.12)` |
| `--iv-color-focus` | `#1D4FC4` | `#73DFFF` |
| `--iv-color-overlay` | `rgb(11 18 48 / 0.55)` | `rgb(2 5 12 / 0.78)` |
| `--iv-color-hover-surface` | `rgb(11 18 48 / 0.04)` | `rgb(230 240 255 / 0.05)` |
| `--iv-color-primary-border` | `rgb(29 79 196 / 0.55)` | `rgb(102 177 255 / 0.5)` |

Contrast targets: text 4.5:1, controls and focus 3:1 on their surfaces. The values above were checked against the WCAG formula; results are re-measured on each release.

## The expressive layer

Six tokens added in v0.6. They name the recipes the polish pass had repeated by hand across a dozen modules — a shadow, a hover tint, a brand edge, a focus halo and two letter spacings — so every module now reads the same value from one place. Nothing changed visually when they landed: they are names for what was already drawn.

| Token | Light | Dark | Where it is used |
| --- | --- | --- | --- |
| `--iv-shadow-ambient` | `0 2px 10px rgb(11 18 48 / 0.10)` | `0 0 1px 1px #1C2544, 0 2px 10px rgb(0 0 0 / 0.5)` | Resting elevation of card, wrapped table, alert, accordion and button. One token instead of five recipes. |
| `--iv-color-hover-surface` | `rgb(11 18 48 / 0.04)` | `rgb(230 240 255 / 0.05)` | Pointer tint on card, dialog and drawer footers, tabs and the picker field. Table and menu rows keep the brand tint of `primary-subtle`. |
| `--iv-color-primary-border` | `rgb(29 79 196 / 0.55)` | `rgb(102 177 255 / 0.5)` | Brand outline: secondary button, field hover, pagination, and anywhere an edge should read as the brand. |
| `--iv-focus-halo` | `0 0 2px 3px rgb(29 79 196 / 0.35)` | `0 0 3px 2px rgb(102 177 255 / 0.32)` | The glow that accompanies the focus ring on fields, buttons, pagination, breadcrumbs, stepper markers and the navbar toggle. Always next to the outline, never instead of it. |
| `--iv-tracking-tight` | `-0.011em` | `-0.011em` | Letter spacing of card, dialog, drawer and stat titles. |
| `--iv-tracking-caps` | `0.06em` | `0.06em` | Letter spacing of small caps: table headers, fieldset legends, megamenu and palette headings, stat labels. |

The two colours also appear in the table above, because they are semantic colours like any other. All six are plain custom properties: override them on `:root` or on a scope and every component that reads them follows.

## Scales

| Family | Tokens |
| --- | --- |
| Space | `--iv-space-0 … 16` (0.25rem steps up to 1.5rem, then 2, 2.5, 3, 4rem) |
| Type | `--iv-text-xs … 4xl`, `--iv-leading-*`, `--iv-weight-*`, `--iv-font-sans\|mono` |
| Shape | `--iv-radius-sm\|md\|lg\|full`, `--iv-border-width`, `--iv-shadow-1\|2\|3` |
| Focus | `--iv-focus-width`, `--iv-focus-offset`, `--iv-color-focus` |
| Motion | `--iv-motion-fast\|base\|slow` (120/180/220 ms; 0 ms under reduced motion), `--iv-ease-out` |
| Layers | `--iv-z-dropdown\|drawer\|dialog\|toast` |
| Measures | `--iv-measure` (68ch), `--iv-container-max` (75rem), `--iv-content-max` (90rem) |
| Breakpoints | sm 30em · md 48em · lg 64em · xl 80em · 2xl 90em. Resolved at build time; not available as custom properties inside media queries. |
