Customize
The primary way to restyle var-ui is a recipe-shaped override: pass TypeStyles
components on createDesignTheme (keys are TypeStyles recipe namespaces, e.g. button, side-nav — not the camelCase export name).
Overrides use
base / variants / compoundVariants with full CSS properties, autocomplete
variant names from the recipe, and mint custom tokens that participate in light
and dark mode — with no class names in your theme code.
Cascade layers keep overrides winning without specificity fights: recipes live
in components, consumer overrides in overrides.
One theme call
import { badge, button, createDesignTheme } from '@var-ui/core';
import { DesignSystemProvider } from '@var-ui/react';
export const acme = createDesignTheme({
name: 'acme',
// Partial — deep-merged onto the built-in default palette
tokens: {
color: {
accent: {
default: 'oklch(55% 0.2 290)',
hover: 'oklch(48% 0.2 290)',
},
},
// Custom namespaces — string leaves are mode-invariant; { light, dark } follow color mode
brand: {
glow: {
light: '0 0 0 0.1875rem oklch(90% 0.08 290)',
dark: '0 0 1rem oklch(70% 0.18 290)',
},
},
},
colorMode: {
dark: {
color: {
tone: {
accent: {
foreground: 'oklch(72% 0.16 290)',
background: 'oklch(78% 0.14 290)',
},
},
},
},
},
// Per recipe namespace: factory receives `{ tokens, theme }` or pass a plain override object.
components: {
button: ({ tokens: t }) => ({
base: {
borderRadius: '62.4375rem',
boxShadow: t.brand.glow.var,
'&:hover': { boxShadow: 'none' },
},
variants: {
tone: {
accent: { textTransform: 'uppercase' },
},
appearance: {
solid: {},
},
},
compoundVariants: [
{
variants: { tone: 'accent', appearance: 'solid', size: 'lg' },
style: { letterSpacing: '0.08em' },
},
],
}),
badge: {
base: { borderRadius: '62.4375rem' },
},
},
});
// Apply
<DesignSystemProvider customTheme={acme}>{/* app */}</DesignSystemProvider>acme.className— theme surface class (theme-var-ui-acme)acme.tokens.brand.glow— a{ name, var }ref, like everydesignTokensleaf:acme.tokens.brand.glow.varisvar(--var-ui-brand-glow)
Try the Acme (V7 + V8 demo) palette in the vite example app to see this live.
Self-hosted fonts
Register @font-face rules with fonts on createDesignTheme (or on a
from preset). Pair with tokens.fontFamily stacks that reference the same
family names. Use defineFonts to generate stacks from face definitions:
import { createDesignTheme, defineFonts } from '@var-ui/core';
const brand = defineFonts({
body: {
face: {
family: 'Acme Sans',
src: "url('/fonts/acme-sans.woff2') format('woff2')",
fontWeight: '400 700',
fontDisplay: 'swap',
},
fallback: 'system-ui, sans-serif',
},
});
export const acme = createDesignTheme({
name: 'acme',
fonts: brand.fonts,
tokens: { fontFamily: brand.tokens.fontFamily },
});Host font files under your app’s public/fonts/ directory. Root-relative
url('/fonts/…') works with Astro, Vite, and Next static serving.
Font presets
groteskMono(), figtreeGrotesk() and alloGrotesk() are ready-made pairings. They return the
same { fonts, tokens } shape as defineFonts. Var UI does not ship the
font files: the presets point at files you host, under /fonts/ unless you
pass baseUrl. If a file is missing, the @font-face request 404s and text
silently falls back to the next font in the stack.
| Preset | Files to host |
|---|---|
groteskMono() | space-grotesk-latin.woff2, jetbrains-mono-latin.woff2 |
figtreeGrotesk() | figtree-latin.woff2, space-grotesk-latin.woff2, jetbrains-mono-latin.woff2 |
alloGrotesk() | allo-latin.woff2, allo-latin-italic.woff2, space-grotesk-latin.woff2, jetbrains-mono-latin.woff2 |
Each file is the latin subset of the family’s variable font, from Google Fonts
or Fontsource (for example @fontsource-variable/jetbrains-mono).
import { createDesignTheme, groteskMono } from '@var-ui/core';
const fonts = groteskMono({ baseUrl: '/assets/fonts/' });
export const app = createDesignTheme({
name: 'app',
fonts: fonts.fonts,
tokens: { fontFamily: fonts.tokens.fontFamily },
});Loading a family some other way (a Google Fonts <link>) works too. The
default fontFamily stacks already start with "JetBrains Mono".
Split across files
Hoist custom namespaces into a leaf module and type factories with DesignThemeTokens —
avoid typeof theme.tokens in override files (that cycles through the theme).
// acme.tokens.ts
import type { DesignThemeTokens } from '@var-ui/core';
export const acmeCustomTokens = {
brand: {
glow: { light: '…', dark: '…' },
},
} as const;
export type AcmeTokens = DesignThemeTokens<typeof acmeCustomTokens>;
// button.ts
import { button } from '@var-ui/core';
import type { OverrideConfigFor } from '@var-ui/core';
import type { AcmeTokens } from './acme.tokens';
export const buttonOverride = (t: AcmeTokens) =>
({
base: { boxShadow: t.brand.glow.var },
}) satisfies OverrideConfigFor<typeof button>;
// theme.ts
import { button, createDesignTheme } from '@var-ui/core';
import { acmeCustomTokens } from './acme.tokens';
import { buttonOverride } from './button';
export const acme = createDesignTheme({
name: 'acme',
tokens: acmeCustomTokens,
components: {
button: ({ tokens }) => buttonOverride(tokens as AcmeTokens),
},
});Composable primitives
components on createDesignTheme compiles to TypeStyles styles.override under
the theme class. For app-global or ad-hoc restyles, call styles.override
directly:
import { styles, button } from '@var-ui/core';
// App-global restyle — no theme class prefix
styles.override(button, { base: { borderRadius: '62.4375rem' } }, { layer: 'overrides' });
// Theme-scoped (same mechanism as `components` on createDesignTheme)
styles.override(
button,
{ variants: { tone: { danger: { fontWeight: 700 } }, appearance: { solid: {} } } },
{ selectorPrefix: `.${acme.className}`, layer: 'overrides' },
);When to drop down a tier
| Need | Use |
|---|---|
| Bulk restyle / new brand tokens | tokens + components (this page) |
| One property the recipe already exposes as a var | Set the CSS custom property in an override block or stylesheet |
| Nested themes fighting over the same recipe | Prefer component vars (inheritance), or styles.scope() / @scope |
| Hand-written CSS against a public class | Target the stable base/slot class (e.g. .var-ui-button) |
Attribute mode means variant state is data-* on the element
(data-tone="accent" and data-appearance="solid"), not a separate class. Overrides still target the
right selectors via TypeStyles styles.override — you never write those
selectors yourself in the theme config.
Nested themes
Theme components overrides use a descendant selector prefix
(.theme-var-ui-acme .var-ui-button). If two themed regions nest and both override the
same recipe, prefer component CSS variables (Tier 1) or styles.scope() for
proximity-correct CSS. See TypeStyles’ component override contract for details.