Skip to content

Theming

Design tokens

Semantic tokens that power var-ui components and layouts.

Design tokens

var-ui exposes semantic tokens for color, spacing, typography, motion, and elevation. Components reference tokens (e.g. t.color.tone.accent.foreground) instead of hard-coded values so themes can swap palettes without touching recipes.

Using tokens

Import the shared refs from core:

TS
import { designTokens } from '@var-ui/core';

designTokens.color.text.primary; // var(--var-ui-color-text-primary)
designTokens.space.md;
designTokens.fontSize.md;

Default registered values live in tokenValues (used as the built-in from preset base).

Listing tokens

designTokens is typed from the schema, so editors autocomplete every path. At runtime it has no enumerable keys (Object.keys(designTokens.space) is []). To list or search tokens, use listDesignTokens():

TS
import { listDesignTokens } from '@var-ui/core';

listDesignTokens().filter((token) => token.path.startsWith('space.'));
// [{ path: 'space.md', cssVar: '--var-ui-space-md', ref: 'var(--var-ui-space-md)', value: '1rem' }, …]

Each entry has the dot path, the cssVar name, the ref (var(--…), the same string as designTokens.<path>.var) and the default value (colours carry { light, dark }). The CSS variables page shows the whole list, searchable.

Spacing

designTokens.space.*: the gap and padding scale, in rem.

none0rem
xxs0.25rem
xs0.5rem
sm0.75rem
md1rem
lg1.5rem
xl2rem
xxl2.5rem
xxxl3rem
xxxxl4rem

Radius

designTokens.radius.*: sm and md for controls, lg and xl for surfaces, full for pills.

none0
sm0.25rem
md0.375rem
lg0.75rem
xl1rem

Type scale

designTokens.fontSize.*: the control and UI text scale (the display steps are fluid).

xs0.75rem Precise, calm, confident
sm0.8125rem Precise, calm, confident
md0.875rem Precise, calm, confident
lg1.0625rem Precise, calm, confident
xl1.25rem Precise, calm, confident
xxl1.5rem Precise, calm, confident
xxxl1.8125rem Precise, calm, confident

Theme overrides

Theme overrides use two layers:

  • tokens on createDesignTheme — mode-invariant patches; the light color face lives here by default
  • colorMode — TypeStyles ThemeColorModePatches ({ light?, dark? } namespace overrides; patch the color namespace for semantic tokens, compiled to light-dark())

Custom namespaces from createDesignTheme({ tokens }) appear on the theme’s .tokens object alongside built-in refs, with the same { name, var } leaves: theme.tokens.space.md.var and theme.tokens.app.heroCover.var. The tokens passed to components factories have the same shape.

An app that only needs a few values of its own adds a namespace on a child of the default theme (extend adds namespaces; tokens patches existing ones), with no need to rebuild the whole token tree:

TS
import { defaultTheme } from '@var-ui/core';

export const libraryTheme = defaultTheme.override({
  name: 'library',
  extend: { app: { heroCover: '18rem', heroTitle: 'clamp(2rem, 5vw, 3.5rem)' } },
});
export const appTokens = libraryTheme.tokens.app; // appTokens.heroCover.var

Syntax-highlighting colors live under color.code (designTokens.color.code). lightSyntaxValues / darkSyntaxValues are exported aliases for theme presets.

Syntax highlighting

var-ui defines semantic code colors but does not ship highlighter-specific CSS. Map color.code to your toolchain:

  • highlight.js — CSS rules targeting .hljs-* classes (see this site’s docs/src/styles/codeHighlight.ts for a reference mapping)
  • Shiki — build a theme object from the token values at compile time
  • Prism — map token groups to Prism’s theme format

Override defaults via createDesignTheme({ tokens: { color: { code: … } } }) or colorMode.dark. Token groups:

TokenTypical use
baseDefault foreground
keywordKeywords, types
titleTitles, class/function names
attrAttributes, numbers, operators, variables
stringStrings, regexps
builtInBuilt-ins, symbols
commentComments
nameTags, pseudo-selectors
sectionHeadings
bulletList bullets
addition / additionBackgroundDiff additions
deletion / deletionBackgroundDiff deletions

See the Colors reference for palette ramps and semantic color swatches, Shadows for the shadow scale, and CSS variables for the full custom property catalog. Example theme presets live under docs/src/themes/.