| title | Adapters: Style Dictionary |
|---|---|
| description | Style Dictionary consumes Variable Design Standard (VDS) (DTCG) format and generates platform outputs like CSS variables, TypeScript types, and Tailwind CSS v4 custom properties. |
Style Dictionary consumes Variable Design Standard (VDS) (DTCG) format and generates platform outputs like CSS variables, TypeScript types, and Tailwind CSS v4 custom properties.
Style Dictionary is an output adapter. It reads Variable Design Standard (VDS) JSON and produces files for consumption in code.
Style Dictionary supports DTCG format natively. Use Variable Design Standard (VDS) JSON files directly as Style Dictionary source files.
Example Style Dictionary configuration:
{
"source": ["tokens/**/*.json"],
"platforms": {
"css": {
"transformGroup": "css",
"buildPath": "dist/",
"files": [
{
"destination": "variables.css",
"format": "css/variables"
}
]
},
"typescript": {
"transformGroup": "js",
"buildPath": "dist/",
"files": [
{
"destination": "tokens.ts",
"format": "typescript/es6-declarations"
}
]
}
}
}Style Dictionary can generate:
- CSS variables (
css/variables) - SCSS variables (
scss/variables) - Less variables (
less/variables) - JavaScript/TypeScript (
javascript/es6,typescript/es6-declarations) - JSON (
json/nested,json/flat) - Tailwind CSS v4 (
css/variablesfor@themedirective) - Android resources (
android/resources) - iOS plist (
ios/plist) - And more
Style Dictionary has its own format (legacy), but supports DTCG format:
Legacy Style Dictionary format:
{
"color": {
"primary": {
"value": "#0066cc",
"type": "color"
}
}
}DTCG format (Variable Design Standard (VDS)):
{
"color": {
"primary": {
"$type": "color",
"$value": "#0066cc"
}
}
}Style Dictionary handles both formats. Use DTCG format for Variable Design Standard (VDS) compliance.
Transform groups apply multiple transforms:
css: CSS variable transformsjs: JavaScript/TypeScript transformsscss: SCSS variable transformsandroid: Android resource transformsios: iOS plist transforms
You can create custom transforms for:
- Naming conventions (camelCase, kebab-case, etc.)
- Value transformations (unit conversion, color format)
- Filtering (exclude certain variables)
Example custom transform:
module.exports = {
name: "name/kebab",
type: "name",
transform: function (prop, options) {
return prop.path.join("-");
},
};Style Dictionary resolves references automatically. Variables that reference other variables are resolved to their final values in output files.
Example input:
{
"color": {
"primary": {
"$type": "color",
"$value": "#0066cc"
},
"text": {
"primary": {
"$type": "color",
"$value": "{color.primary}"
}
}
}
}CSS output:
:root {
--color-primary: #0066cc;
--color-text-primary: #0066cc;
}Style Dictionary can generate separate files for each mode or combine modes into a single file with mode selectors.
Example with modes:
{
"color": {
"surface": {
"$type": "color",
"$value": {
"light": "#ffffff",
"dark": "#000000"
}
}
}
}CSS output (separate files):
variables-light.css:
:root {
--color-surface: #ffffff;
}variables-dark.css:
:root {
--color-surface: #000000;
}Typical workflow:
- Store Variable Design Standard (VDS) JSON in
tokens/directory - Configure Style Dictionary to read from
tokens/ - Run Style Dictionary build
- Generated files appear in
dist/ - Import generated files in your code
If Style Dictionary configuration is wrong:
- Missing source files cause empty outputs
- Invalid transforms break value conversion
- Reference resolution failures cause undefined values
- Mode handling errors produce incorrect outputs
Style Dictionary validates:
- JSON syntax
- Reference resolution
- Type correctness (for transforms that check types)
Variable Design Standard (VDS) validation should happen before Style Dictionary build (in CI or pre-commit hooks).
Input (tokens/color.json):
{
"color": {
"primary": {
"$type": "color",
"$value": "#0066cc"
}
}
}Output (dist/variables.css):
:root {
--color-primary: #0066cc;
}Input (same as above)
Output (dist/tokens.ts):
export const color = {
primary: "#0066cc",
};Input (same as above)
Output (dist/theme.css):
@import "tailwindcss";
@theme {
--color-primary: #0066cc;
}Note: Tailwind CSS v4 uses CSS-first configuration. Generate CSS custom properties, not JavaScript config files. See Tailwind Adapter for details.
- Style Dictionary installation and setup (see Style Dictionary docs)
- Custom transform implementation details
- Platform-specific build configurations