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:
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():
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.
Radius
designTokens.radius.*: sm and md for controls, lg and xl for surfaces, full for pills.
Type scale
designTokens.fontSize.*: the control and UI text scale (the display steps are fluid).
Theme overrides
Theme overrides use two layers:
tokensoncreateDesignTheme— mode-invariant patches; the lightcolorface lives here by defaultcolorMode— TypeStylesThemeColorModePatches({ light?, dark? }namespace overrides; patch thecolornamespace for semantic tokens, compiled tolight-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:
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.varSyntax-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’sdocs/src/styles/codeHighlight.tsfor 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:
| Token | Typical use |
|---|---|
base | Default foreground |
keyword | Keywords, types |
title | Titles, class/function names |
attr | Attributes, numbers, operators, variables |
string | Strings, regexps |
builtIn | Built-ins, symbols |
comment | Comments |
name | Tags, pseudo-selectors |
section | Headings |
bullet | List bullets |
addition / additionBackground | Diff additions |
deletion / deletionBackground | Diff 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/.