Design Tokens: Primitive and Semantic Tokens, from Figma to CSS to Tailwind
A design token is a name for a value, like colour 47 on a paint chart. Build primitive and semantic tokens in tokens.css, reuse the same names in a Tailwind CSS 4 @theme block, and re-skin a card by changing one line.
What you will learn
- Explain a design token as a name for a value
- Split tokens into primitive tokens and semantic tokens
- Use the same token names in plain CSS variables and a Tailwind CSS 4 @theme block
- Re-skin a component by changing one token line
Before you start
- Basic HTML and CSS
- Colour, Contrast and Dark Palettes
Imagine you are painting four rooms, and you tell every painter "use that nice blue". Four painters, four slightly different blues. Nobody notices until it is everywhere.
That is exactly what happens in an app when every file types its own colour code. Now take a paint chart where every colour has a number. You say "colour 47", and everyone paints the same colour. Change the chart once, and every room follows.
A design token is colour 47 on that chart: a name for a value. The whole team uses the name, not the value. In this article you will see tokens in plain CSS first, then the same names in Tailwind CSS 4.
Primitive tokens and semantic tokens
Tokens come in two layers.
- Primitive tokens are the chips on the chart: indigo 600, emerald 600, slate 900, slate 100, white. They say which colours exist. They do not say where to use them.
- Semantic tokens are named by the job:
--color-brandfor buttons and links,--color-inkfor text,--color-surfacefor cards,--color-pagefor the page background. Each one simply points at a chip.
The rule: screens use only the semantic names, and the primitives stay behind the scenes. Tomorrow the brand can move to another chip and no screen needs to know.
The real tokens file
Here is tokens.css from the project, every line of it:
:root {
/* primitives: the paint chart */
--indigo-600: #4f46e5;
--emerald-600: #059669;
--slate-900: #0f172a;
--slate-100: #f1f5f9;
--white: #ffffff;
/* semantic: what each colour is for */
--color-brand: var(--indigo-600);
--color-ink: var(--slate-900);
--color-surface: var(--white);
--color-page: var(--slate-100);
--spacing-card: 24px;
--radius-card: 14px;
--font-body: "Inter", system-ui, sans-serif;
}
It starts with :root, so these variables are available everywhere. First the primitives: five chips with raw values. Then the semantic layer, where --color-brand is var(--indigo-600) and so on. And it is not only colour. --spacing-card is 24px, --radius-card is 14px, and --font-body is Inter with a system font as backup.
The card uses the names
Now card.css uses them:
.card {
background: var(--color-surface);
padding: var(--spacing-card);
border-radius: var(--radius-card);
border-top: 8px solid var(--color-brand);
}
.card h2 { margin: 0 0 6px; font-size: 26px; }
.card p { margin: 0 0 14px; font-size: 18px; }
.bar { height: 12px; border-radius: 99px; background: var(--color-page); margin-bottom: 18px; }
.bar i { display: block; width: 65%; height: 100%; border-radius: 99px; background: var(--color-brand); }
.card button {
background: var(--color-brand);
color: var(--color-surface);
border: 0;
padding: 12px 22px;
border-radius: var(--radius-card);
font: 700 18px var(--font-body);
The card background is var(--color-surface). The padding, the radius and the top border all come from tokens. The button background is the brand colour, and its text is the surface colour. It draws a task card: "Write report", assigned to Emma, due Friday, with a progress bar and a Mark done button.
Notice there is no colour code in this file. Only token names. That is the whole point.
The same tokens as a Tailwind @theme
Now the same tokens in Tailwind CSS 4. This is theme.css:
@import "tailwindcss";
@theme {
--color-brand: #4f46e5;
--color-ink: #0f172a;
--color-surface: #ffffff;
--color-page: #f1f5f9;
--spacing-card: 24px;
--radius-card: 14px;
--font-body: "Inter", system-ui, sans-serif;
}
The first line imports Tailwind, then comes an @theme block with the same names. Plain values this time. Tailwind reads that block and creates the classes for you: bg-brand, text-ink, bg-surface, p-card, rounded-card and font-body. The page from ex02-tailwind-theme/index.html uses them like any other class:
<body class="bg-page text-ink font-body p-7">
<div class="bg-surface p-card rounded-card border-t-8 border-brand">
<h2 class="text-2xl font-bold">Write report</h2>
<p class="mb-4">Assigned to Emma, due Friday</p>
<button class="bg-brand text-white font-bold px-5 py-3 rounded-card">Mark done</button>
</div>
Same names, same values, and Tailwind writes the classes. You do not have to memorise any of this, because AI can write these blocks for you. You only need the foundation, so the code makes sense when your app grows.
Change one line, re-skin the app
The card uses --color-brand, which points at indigo 600. Now change one line in tokens.css:
/* before */
--color-brand: var(--indigo-600);
/* after */
--color-brand: var(--emerald-600);
Nothing else. The top border, the progress bar and the button all turn green. We did not touch card.css. One line changed and everything followed. Now imagine doing that on a hundred screens without tokens.
From Figma to the screen, one source
Where do the tokens come from? In most teams a designer defines them in Figma as variables, and the same name then travels all the way to the screen.
Step one, in Figma: brand equals Indigo 600. Step two, it is exported as a CSS variable in tokens.css. Step three, the same name becomes a Tailwind class through the theme block. Step four, every screen uses the name. Change the token once at the start and every step after it updates. That is what "one source of truth" means.
The next step is to give the same names two sets of values, one for light mode and one for dark. That is in design tokens to a Tailwind theme with dark mode.
Common mistakes
- Using primitives in components.
background: var(--indigo-600)in a card works today, but when the brand moves to emerald, that card stays indigo. Use--color-brand. - Naming semantic tokens by colour.
--color-blueis a primitive in disguise. Name it by the job. - Two sets of names. If Figma says
brandand the CSS saysprimary-blue, the chain breaks and someone copies values by eye. Keep one name all the way.
Recap
| Idea | In one line |
|---|---|
| Design token | A name for a value |
| Primitive token | A raw chip: --indigo-600: #4f46e5 |
| Semantic token | Named by the job: --color-brand: var(--indigo-600) |
Tailwind 4 @theme | The same names become classes like bg-brand |
| One source of truth | Change a value once, the whole app follows |
The same token idea in Figma, with variables, modes and component variants, is in components, variants and variables.
Try it yourself: open the project, point --color-brand at another chip, and watch the card change. Then copy the same names into a Tailwind theme.
StudyEasy AI Community
Learn AI engineering, share what you build, and connect with other learners.
Free resources: lesson files, notebooks and code
Ask questions and join engineering discussions
Meet real people learning and building with AI
Related course on Udemy
The Python Architect Masterclass: Full Stack to AI Engineer
Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)Related posts
One Request, Two Answers: the Same Post as an HTML Page and as JSON
Ask a Django blog for the same post twice: once as a 12,731-byte HTML page built by a template, once as 2,976 bytes of JSON built by a serializer. Compare the headers, see who builds the page, and why the server still owns every write.
A Blog Design from a Prompt: Downloading Figma Make Code and Reading App.tsx and BlogCard.tsx
Make a blog design from a prompt in Figma Make, download src.zip, unzip it with Python's zipfile module, and read the two files that matter: App.tsx with its selectedPost state and BlogCard.tsx with its props.
How a Web Page Works: HTML Tags, Elements and Attributes
A web page is a text file full of labelled pieces. Learn tags, attributes and nesting with three tiny pages, and see what breaks when an attribute or a closing tag is wrong.
Semantic HTML: header, nav, main, aside and footer as Page Landmarks
The same page written as div soup and with semantic tags looks identical, but only one gives screen readers and search engines landmarks and an outline. Plus tables, div, span and the one-main rule.
