Design Tokens vs CSS Variables
Teams adopting a design system often ask whether they should maintain design tokens or just write CSS variables (--primary, --radius-md) in globals.css. The short answer is that they sit at different layers of the same pipeline:
- Design tokens are platform-agnostic design decisions stored as structured, machine-readable data (such as
DESIGN.mdYAML frontmatter or W3C DTCG JSON). - CSS variables (officially CSS custom properties) are a browser runtime feature that carries resolved values through the CSS cascade, inheritance, media queries, and theme classes like
.dark.
In practice, design tokens are the source of truth, and CSS variables are the browser output compiled from them.
Side-by-side comparison
| Dimension | Design Tokens (DESIGN.md / DTCG) | CSS Variables (--* custom properties) |
|---|---|---|
| Role | Authoritative specification of visual decisions | Runtime delivery mechanism in browsers |
| Format | Structured YAML or JSON (colors, typography, rounded, spacing, components) | Flat key-value declarations inside CSS selectors (:root, .dark, [data-theme]) |
| Composite values | Native structured objects (a single typography.body holds family, size, weight, lineHeight) | Scalar strings only — composite tokens must be expanded into multiple --font-* lines |
| Alias resolution | Resolved and linted statically ("{colors.primary}", cycle & missing-key detection) | Resolved lazily at runtime via var(--primary) (typos silently fall back or break) |
| Accessibility lint | Automated WCAG contrast checks across foreground/background token pairs before build | No built-in contrast validation |
| Cross-platform use | Compiles to CSS, Tailwind v4 @theme, shadcn/ui, iOS/Android, Figma, and AI agent prompts | Web browsers only |
| Dynamic runtime use | Static at authoring time | Live cascade: responds to .dark, @media (prefers-color-scheme), and inline styles |
Why CSS variables alone fall short as a source of truth
CSS custom properties are indispensable at runtime—without them, switching themes requires shipping duplicate stylesheets or mutating inline styles in JavaScript. Relying on a hand-edited globals.css as your only design system file breaks down in three situations:
- Silent reference bugs: writing
color: var(--text-mutd)produces no CSS parse error and no build warning; the declaration silently drops to inherited text color. - No composite structure or rationale: a CSS variable cannot express that
typography.headingcouplesGeist Sans,38px, weight700, and1.15line-height—or explain when to use--surfaceversus--background. - AI coding agents lose context: when an agent reads a 200-line
:rootblock without hierarchy rules or Do’s and Don’ts, it picks technically valid variable names in the wrong roles (for instance applying an accent variable to a card border).
Keeping a single DESIGN.md at the repository root solves all three: tokens are schema-checked, paired with explicit usage rules, and compiled directly into CSS variables for the browser.
How they work together: DESIGN.md → CSS Variables
Start from a single DESIGN.md that defines semantic colors, dark-mode overrides, composite typography, radii, and spacing:
---
name: Starter Design System
version: 1.0.0
description: A starter palette for a product interface.
colors:
primary: "#5645d4"
background: "#ffffff"
text: "#111827"
border: "#e5e3df"
dark:
primary: "#a78bfa"
background: "#111827"
text: "#f9fafb"
typography:
body:
fontFamily: Inter
fontSize: 16px
fontWeight: 400
lineHeight: 1.5
rounded:
md: 8px
spacing:
md: 16px
---Instead of translating every key by hand, compile the file in the CSS Variables Generator:
- Open /css-variables-generator and paste your
DESIGN.md(or click Load a DESIGN.md example to inspect the mapping immediately). - The generator parses your YAML locally in the browser and outputs a ready-to-import
tokens.cssblock:colors.<key>becomes--<key>inside:root, whilecolors.dark.<key>is emitted inside.dark.- Composite
typography.<key>objects expand into--font-<key>,--font-<key>-size,--font-<key>-weight, and--font-<key>-line-height. rounded.<key>andspacing.<key>emit--radius-<key>and--spacing-<key>.
- Click Copy or Download (
tokens.css) and import it at the top of your stylesheet.

Components then consume only the generated CSS variables:
.card {
background: var(--background);
color: var(--text);
border: 1px solid var(--border);
border-radius: var(--radius-md);
padding: var(--spacing-md);
font-family: var(--font-body);
font-size: var(--font-body-size);
line-height: var(--font-body-line-height);
}When .dark is toggled on <html>, --background, --text, and --primary update automatically without touching component CSS.
When to use which
- Plain CSS variables alone are enough for a small, single-page web project with no design handoff, no cross-tool exports, and no AI-agent workflow.
- Design tokens (
DESIGN.md) compiled to CSS variables pay off as soon as you maintain light and dark themes, share tokens across Tailwind / shadcn / plain CSS, enforce WCAG contrast in CI, or collaborate with AI coding agents like Cursor and Claude Code.
Try the tool
Turn your DESIGN.md tokens into clean :root and .dark CSS custom properties directly in your browser:
- Open the CSS Variables Generator — paste any
DESIGN.mdand downloadtokens.csswith zero setup. - Tailwind CSS v4 Theme Generator — compile the same tokens into a Tailwind v4
@themeblock instead of plain:rootvariables. - Next: Design Tokens for Cursor — connect your validated tokens to Cursor rules so Composer and Agent modes stay on-spec.