Design Systems That Build Themselves, Using Style Dictionary + TailwindCSS
Most teams build design systems to keep their UI consistent. But the hardest part isn’t making pretty buttons, it’s keeping style tokens, colors and spacing consistent across codebases. That’s where Style Dictionary and Tailwind CSS work beautifully together. Style Dictionary becomes your source of truth, and Tailwind consumes it. Let’s see how to set this up step by step.
1. What’s a Design Token?
Design tokens are small, reusable values that define your visual language —
like colors, typography, and spacing.
Instead of hardcoding values (e.g., #1D4ED8), you define them once in a token file and let your tools generate CSS variables.
2. Create Your Project Structure
your-project/
├── tokens/
│ └── colors.json
├── design-system/
│ └── tokens.css # Generated by Style Dictionary
├── tailwind.config.ts
├── globals.css
└── package.json3. Define Tokens
Create a file at tokens/colors.json:
{
"color": {
"brand": {
"primary": {
"50": { "value": "#EFF6FF" },
"100": { "value": "#DBEAFE" },
"200": { "value": "#BFDBFE" },
"500": { "value": "#3B82F6" },
"700": { "value": "#1D4ED8" }
}
}
}
}This is your source of truth.
4. Install and Configure Style Dictionary
Install it via:
npm install style-dictionary --save-devThen create a config file at style-dictionary.config.json:
{
"source": ["tokens/**/*.json"],
"platforms": {
"css": {
"transformGroup": "css",
"buildPath": "build/",
"files": [
{
"destination": "tokens.css",
"format": "css/variables"
}
]
}
}
}Now you can define the following scripts in package.json:
"tokens:build": "style-dictionary build --config style-dictionary.config.json",
"tokens:clean": "style-dictionary clean --config style-dictionary.config.json",
"tokens:watch": "style-dictionary build --watch --config style-dictionary.config.json"From now on, running:
npm run tokens:buildwill generate CSS tokens in design-system/tokens.css that look like this:
:root {
--color-brand-primary-50: #EFF6FF;
--color-brand-primary-100: #DBEAFE;
--color-brand-primary-200: #BFDBFE;
--color-brand-primary-500: #3B82F6;
--color-brand-primary-700: #1D4ED8;
}5. Connect Style Dictionary to Tailwind
In your globals.css, import both Tailwind and the generated tokens:
@import "tailwindcss";
@import "../design-system/tokens.css";
@layer utilities {
/* Brand Primary Colors */
.text-brand-primary-50 {
color: var(--color-brand-primary-50);
}
.text-brand-primary-100 {
color: var(--color-brand-primary-100);
}
.text-brand-primary-200 {
color: var(--color-brand-primary-200);
}
.bg-brand-primary-500 {
background-color: var(--color-brand-primary-500);
}
}Now you can use your tokens directly in your components:
<button class="bg-brand-primary-500 text-white px-4 py-2 rounded">
Save
</button>Final Thoughts
You don’t need a huge atomic system to build scalable UIs. Start with tokens, automate them with Style Dictionary, and apply them through Tailwind. Once this foundation is set, you can grow your system safely, without breaking your brand or your sanity.