The problem with inconsistent design systems
Designers and developers often argue over exact colors or spacing values. Design tokens solve this by creating a shared language between Figma and code.
What are Figma design tokens?
Design tokens are named values for colors, spacing, typography, and more. In Figma, they're called Variables. Instead of hardcoding values, you reference tokens like color.primary.500 or spacing.4.
Setting up tokens in Figma
Step 1: Define token categories
Start with these categories:
Colors
color.primary.50 to color.primary.950
color.neutral.50 to color.neutral.950
color.success, color.warning, color.error
color.background, color.foreground
Spacing
spacing.0 (0px)
spacing.1 (4px)
spacing.2 (8px)
spacing.3 (12px)
spacing.4 (16px)
Border Radius
radius.sm (4px)
radius.md (6px)
radius.lg (8px)
radius.full (9999px)
Typography
font.size.xs (12px)
font.size.sm (14px)
font.size.base (16px)
font.size.lg (18px)
Step 2: Create Variables in Figma
- Open the Variables panel in Figma
- Create collections for each category
- Add Light and Dark modes for colors
For example:
| Token | Light | Dark |
|---|---|---|
| color.background | #FFFFFF | #0A0A0A |
| color.foreground | #0A0A0A | #FAFAFA |
Step 3: Apply Variables to components
Replace hardcoded values in your components with Variables. This makes rebranding and theme switching instant.
Syncing tokens to code
Option 1: Tokens Studio Plugin
The most popular method:
- Use the Tokens Studio plugin in Figma
- Sync token JSON to a Git repo
- Transform JSON to CSS in your build process
Pros: Full control, supports complex relationships
Cons: Requires plugin and CI setup
Option 2: Figma API
Fetch Variables from Figma's REST API:
const response = await fetch(
`https://api.figma.com/v1/files/${FILE_KEY}/variables/local`,
{ headers: { 'X-Figma-Token': FIGMA_TOKEN } }
);
Pros: Uses native Variables
Cons: Requires Figma Enterprise/Professional
Option 3: Manual sync
Maintain tokens in both Figma and code:
:root {
--color-primary-500: #3B82F6;
--spacing-4: 16px;
}
Pros: Simple
Cons: Risk of drift between Figma and code
Using tokens in code
With Tailwind CSS
Map tokens to Tailwind's theme:
module.exports = {
theme: {
extend: {
colors: {
primary: {
500: 'var(--color-primary-500)',
},
},
},
},
};
With shadcn/ui
shadcn/ui already uses CSS variables. Extend the default theme:
:root {
--color-primary-500: #3B82F6;
}
With plain CSS
Reference tokens directly:
.card {
background: var(--color-card);
padding: var(--spacing-4);
}
Dark mode with tokens
Define two sets of values under the same token names:
:root {
--color-background: #FFFFFF;
}
[data-theme="dark"] {
--color-background: #0A0A0A;
}
Common gotchas
- Don't over-tokenize. Start with colors, spacing, and radii.
- Use semantic names like
color.primary, notblue-500. - Set a sync process to keep Figma and code in alignment.
- Define dark mode tokens from the start.
Start by defining base tokens in Figma Variables, apply them to components, and sync to CSS. Use Tailwind or shadcn/ui for faster implementation.
This is a shorter version of a guide I wrote at Frontkit Studio. The full post has the complete walkthrough.
Top comments (0)