Developers often face a frustrating problem: designs built in Figma never quite match the shipped product. Colors shift, spacing varies, and border radii differ across pages. This happens because most Figma-to-code workflows rely on eyeballing and manual translation.
The root causes
Manual translation: A designer uses #2563EB in Figma. A developer types bg-blue-600 in Tailwind. These values might match today, but they'll diverge when someone updates the brand color in Figma or the Tailwind config.
Style drift: Over time, products accumulate micro-inconsistencies. A designer updates spacing in one component but not others. A developer uses p-4 in one place and p-5 in another. These small differences erode visual quality.
The solution: design tokens
Design tokens are named, platform-agnostic values for colors, spacing, typography, and more. They act as a shared contract between Figma and your codebase.
Example token
-
Name:
color-primary-600 -
Figma value:
#2563EB(Figma Variable) -
Code value:
var(--color-primary-600)(CSS custom property) -
Tailwind mapping:
primary-600
Setting up Figma variables
Step 1: Create a token collection
In Figma, create a Variable collection called Tokens. Add groups like:
-
color/primary/50tocolor/primary/900 -
spacing/1tospacing/16 -
radius/sm,radius/md, etc.
Step 2: Use modes for themes
Create Light and Dark modes within your color collection. The token names stay the same, but values change per mode.
:root {
--color-primary-600: #2563EB;
}
[data-theme="dark"] {
--color-primary-600: #60A5FA;
}
Step 3: Apply variables consistently
Designers should only use variables, never raw values. If a new color is needed, add a new token.
Mapping tokens to Tailwind
Colors
// tailwind.config.ts
const config = {
theme: {
extend: {
colors: {
primary: {
50: "var(--color-primary-50)",
600: "var(--color-primary-600)",
},
},
},
},
}
Spacing
spacing: {
"token-1": "var(--spacing-1)",
}
Border radius
borderRadius: {
"token-sm": "var(--radius-sm)",
}
Keeping tokens in sync
- Single source of truth: Figma is usually authoritative. Update code when Figma changes.
- Automated export: Use tools like Tokens Studio to export Figma variables as JSON.
- Review changes: Treat token updates like API changes. Flag them for design review in PRs.
Real-world example
A button's background might use bg-primary-600. Its hover state uses bg-primary-700. These map to CSS custom properties, so updating the token updates every instance.
Benefits
- Faster handoffs: Designers and developers share a vocabulary.
- Fewer bugs: Update tokens in one place, fix bugs everywhere.
- Painless rebranding: Change token values, update the entire UI.
- Better collaboration: Shared language reduces miscommunication.
Start by exploring token-based workflows in real projects or set up your own system using Figma variables and CSS custom properties. The key is consistency in using tokens across design and code.
This is a shorter version of a guide I wrote at Frontkit Studio. The full post has the complete walkthrough.
Top comments (0)