0Pricing
Frontend Academy · Lesson

Design Tokens with Style Dictionary

Define colour, spacing, and typography tokens in JSON, transform them with Style Dictionary into CSS variables, JS constants, or iOS/Android formats.

Design Tokens with Style Dictionary is a free Frontend Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Frontend Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

What Are Design Tokens?

Design tokens are the named, primitive values of a design system: colours, spacing, font sizes, border radii, shadows. They're the source of truth — every component derives styles from them.

Why Tokens Matter

Tokens decouple design decisions from implementation. Change color.primary from blue to green once, and every component using it updates. They also let you ship the same design to web, iOS, and Android.

Token Storage

Store tokens in JSON or YAML — neutral format consumable by tools across platforms. JSON is most common.

// tokens/color.json
{
  "color": {
    "brand": {
      "primary": { "value": "#2563eb" },
      "secondary": { "value": "#7c3aed" }
    },
    "text": {
      "default": { "value": "#111827" },
      "muted": { "value": "#6b7280" }
    }
  }
}

Style Dictionary

Style Dictionary (Amazon) is the de facto build tool for design tokens. It reads tokens and transforms them to multiple output formats: CSS variables, SCSS, JS constants, iOS Swift, Android XML.

npm install -D style-dictionary

Configuration

Create style-dictionary.config.js describing input tokens and output platforms.

// style-dictionary.config.js
module.exports = {
  source: ['tokens/**/*.json'],
  platforms: {
    css: {
      transformGroup: 'css',
      buildPath: 'build/css/',
      files: [{ destination: 'tokens.css', format: 'css/variables' }]
    },
    js: {
      transformGroup: 'js',
      buildPath: 'build/js/',
      files: [{ destination: 'tokens.js', format: 'javascript/es6' }]
    },
    ios: {
      transformGroup: 'ios',
      buildPath: 'build/ios/',
      files: [{ destination: 'Tokens.swift', format: 'ios-swift/class.swift' }]
    }
  }
};

Running the Build

Run the CLI to emit all platforms.

npx style-dictionary build

# Output:
# build/css/tokens.css     — CSS variables
# build/js/tokens.js       — JS constants
# build/ios/Tokens.swift   — Swift constants

Generated CSS Output

CSS variables with a consistent naming scheme (kebab-case with namespace).

:root {
  --color-brand-primary: #2563eb;
  --color-brand-secondary: #7c3aed;
  --color-text-default: #111827;
  --color-text-muted: #6b7280;
}

Generated JS Output

JS object for use in JS/TS code (Tailwind config, CSS-in-JS).

export const ColorBrandPrimary = '#2563eb';
export const ColorBrandSecondary = '#7c3aed';
export const ColorTextDefault = '#111827';

Token Naming Conventions

Use semantic names (color.primary) over literal (color.blue-500). Semantic tokens let you change values without renaming. Two-tier system: literal palette (blue-500) → semantic alias (primary).

{
  "color": {
    "palette": {
      "blue-500": { "value": "#2563eb" }
    },
    "brand": {
      "primary": { "value": "{color.palette.blue-500.value}" }
    }
  }
}

Theming with Tokens

Build multiple platforms with different inputs to support themes (light/dark) — same names, different values.

// Light theme:
--color-bg: white;
--color-text: black;

// Dark theme:
--color-bg: #111;
--color-text: white;

Token Categories

Common categories: color, spacing, typography (font-family, size, line-height, weight), border (radius, width), shadow, transition (duration, easing), z-index, breakpoint.

Token Registry Tools

Beyond Style Dictionary: Tokens Studio (Figma plugin), Specify, Supernova. They let designers manage tokens in Figma and sync to the codebase automatically.

Quick Check

What is the main benefit of using design tokens with Style Dictionary?

Recap: Design Tokens

Tokens are named primitive values (colour, spacing, type) — the source of truth for a design system. Store as JSON. Style Dictionary transforms to CSS vars, JS, iOS, Android. Semantic naming (primary) over literal (blue-500). Two-tier: palette → semantic alias. Themes via separate builds. Sync from Figma via Tokens Studio.

Frequently asked questions

Is the “Design Tokens with Style Dictionary” lesson free?

Yes — the full text of “Design Tokens with Style Dictionary” is free to read here on the web, and the Frontend Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Frontend Academy course, upgrade to CoddyKit PRO.

What will I learn in “Design Tokens with Style Dictionary”?

Define colour, spacing, and typography tokens in JSON, transform them with Style Dictionary into CSS variables, JS constants, or iOS/Android formats. You practise Frontend Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Frontend Academy?

No prior experience is required. Frontend Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Design Tokens with Style Dictionary” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Frontend Academy lesson?

Yes. Every Frontend Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Storybook: Stories Controls and Docs
  2. Design Tokens with Style Dictionary
  3. Versioning and Publishing to npm
  4. Consuming a Design System
← Back to Frontend Academy