Tailwind Design Tokens for AI Agents: Using @theme
By @andymarrows · Updated · 6 min read
The short answer
In Tailwind CSS v4, design tokens live in a @theme block in your CSS: theme variables such as --color-accent, --font-sans, --spacing and --radius-card, which decide which utility classes exist (bg-accent, font-sans, p-4, rounded-card). Name them by role, remove the defaults you don't want agents reaching for, and add a short rule file telling the agent to use only those utilities. The tokens pin the values; the rules say where each one goes.
What are Tailwind theme variables?
Tailwind's docs define them plainly: "Theme variables are special CSS variables defined using the @theme directive that influence which utility classes exist in your project." Define --color-mint-500 and bg-mint-500 exists; define --radius-card and rounded-card exists.
Because theme variables decide which utilities exist, @theme is the natural place for a design system an agent can use. The agent doesn't need to remember hex codes: it writes bg-accent and gets the right one, in every file.
| Namespace | Utilities it creates | Example |
|---|---|---|
| --color-* | Colour utilities (bg-*, text-*, border-*, …) | --color-accent: #0d7268 → bg-accent |
| --font-* | Font family utilities | --font-sans: "Inter", sans-serif → font-sans |
| --spacing | Spacing and sizing (p-*, m-*, gap-*, w-*, …), as multiples of one base | --spacing: 0.25rem → p-4 is 1rem |
| --radius-* | Border radius utilities | --radius-card: 12px → rounded-card |
| --text-* | Font size utilities | --text-display: 3.5rem → text-display |
| --shadow-* | Box shadow utilities | --shadow-card: 0 1px 2px rgb(0 0 0 / 0.05) → shadow-card |
How should I name tokens for an agent?
By role, not by value. An agent given --color-teal-600 still has to decide where teal goes. Given --color-accent and --color-surface, it can't put them in the wrong place.
@import "tailwindcss";
@theme {
/* Colours by role */
--color-bg: #ffffff;
--color-surface: #f4f4f2;
--color-fg: #151513;
--color-muted: #5c5a54;
--color-border: #e4e2dc;
--color-accent: #0d7268;
--color-on-accent: #ffffff;
/* Type */
--font-sans: "Inter", ui-sans-serif, system-ui, sans-serif;
--text-display: 3.5rem;
--text-display--line-height: 1;
/* Shape */
--radius-card: 12px;
--radius-pill: 999px;
}For dark mode, keep the same role names and change their values under a dark selector, so one component works in both themes.
How do I stop agents using Tailwind's defaults?
Agents know Tailwind's default palette by heart, so they reach for bg-blue-500 and shadow-lg out of habit. Two things help.
- Clear the namespaces you don't want: setting a namespace to initial in @theme (for example --color-*: initial;) removes Tailwind's defaults for it, so only your tokens exist.
- Say it in a rule: "Use only the theme's utilities: bg-bg, bg-surface, text-fg, text-muted, border-border, bg-accent. Never use Tailwind's palette colours or shadow-* utilities."
Put the rule where your agent reads it: CLAUDE.md or a skill for Claude Code, a project rule for Cursor, AGENTS.md for Codex.
Are tokens enough on their own?
No. Tokens say what values exist; they don't say when to use them. A design system for an agent also needs:
- Rules: one accent per screen, borders instead of shadows, headings that tighten as they grow.
- Components: how a button, an input and a card are built, with hover and focus states.
- Layout and motion: container width, section rhythm, durations and easing.
- A process: audit first, ask, then change one area at a time.
A Livery kit carries all of this, measured from a real site, with tokens.json you can turn into a @theme block, so your agent gets the values and the reasons together.
Questions
- Where do design tokens go in Tailwind v4?
- In a @theme block in your CSS. Each theme variable creates utilities: --color-accent gives bg-accent, text-accent and border-accent.
- What's the difference between @theme and :root?
- Tailwind's docs say to use @theme when a design token should map directly to a utility class, and :root for regular CSS variables that shouldn't have utilities.
- How do I make Claude Code use my Tailwind tokens?
- Name the tokens by role, clear Tailwind's default palette if you don't want it, and add a rule (in CLAUDE.md or a skill) to use only the theme's utilities.
- Can I convert DTCG tokens.json to Tailwind?
- Yes. Tokens are plain values, so a short script or a tool such as Style Dictionary can write them out as CSS variables, which you place inside @theme.
In short
In Tailwind CSS v4, design tokens live in a @theme block in your CSS: theme variables such as --color-accent, --font-sans, --spacing and --radius-card, which decide which utility classes exist (bg-accent, font-sans, p-4, rounded-card).
Sources
Try it on a site you love
Paste a link and get an installable design kit in about a minute. Free.
Read next
- 5 Best Tools to Turn Any Website Into a Design System
- Livery vs brandmd: Website Design for Your Coding Agent
- Livery vs DesignRail: Website Design Systems for AI Agents
- How to Make Lovable, Bolt and v0 Apps Look Custom
- Best Design Skills for Claude Code, Cursor and Codex
- How to Give Claude Code a Design System