Lab 05: Design Tokens

Time: 30 minutes | Level: Advanced | Docker: docker run -it --rm node:20-alpine sh

Overview

Implement a complete Design Token pipeline: W3C Design Token format, three-tier token architecture (primitive → semantic → component), Style Dictionary transformation, and multi-platform output (CSS custom properties, iOS Swift, Android XML).


Step 1: W3C Design Token Format

// tokens.json — W3C Community Group format
{
  "color": {
    "blue": {
      "50":  { "$value": "#eff6ff", "$type": "color", "$description": "Lightest blue" },
      "100": { "$value": "#dbeafe", "$type": "color" },
      "200": { "$value": "#bfdbfe", "$type": "color" },
      "300": { "$value": "#93c5fd", "$type": "color" },
      "400": { "$value": "#60a5fa", "$type": "color" },
      "500": { "$value": "#3b82f6", "$type": "color", "$description": "Brand primary" },
      "600": { "$value": "#2563eb", "$type": "color" },
      "700": { "$value": "#1d4ed8", "$type": "color" },
      "800": { "$value": "#1e40af", "$type": "color" },
      "900": { "$value": "#1e3a8a", "$type": "color", "$description": "Darkest blue" }
    },
    "gray": {
      "50":  { "$value": "#f9fafb", "$type": "color" },
      "100": { "$value": "#f3f4f6", "$type": "color" },
      "500": { "$value": "#6b7280", "$type": "color" },
      "900": { "$value": "#111827", "$type": "color" }
    }
  },
  "spacing": {
    "1": { "$value": "4px",  "$type": "dimension" },
    "2": { "$value": "8px",  "$type": "dimension" },
    "3": { "$value": "12px", "$type": "dimension" },
    "4": { "$value": "16px", "$type": "dimension" },
    "6": { "$value": "24px", "$type": "dimension" },
    "8": { "$value": "32px", "$type": "dimension" }
  },
  "border-radius": {
    "none": { "$value": "0px",     "$type": "dimension" },
    "sm":   { "$value": "4px",     "$type": "dimension" },
    "md":   { "$value": "8px",     "$type": "dimension" },
    "lg":   { "$value": "12px",    "$type": "dimension" },
    "xl":   { "$value": "16px",    "$type": "dimension" },
    "full": { "$value": "9999px",  "$type": "dimension" }
  },
  "font-size": {
    "xs":  { "$value": "12px", "$type": "dimension" },
    "sm":  { "$value": "14px", "$type": "dimension" },
    "md":  { "$value": "16px", "$type": "dimension" },
    "lg":  { "$value": "18px", "$type": "dimension" },
    "xl":  { "$value": "20px", "$type": "dimension" },
    "2xl": { "$value": "24px", "$type": "dimension" },
    "3xl": { "$value": "30px", "$type": "dimension" },
    "4xl": { "$value": "36px", "$type": "dimension" }
  }
}

Step 2: Three-Tier Token Architecture


Step 3: Style Dictionary Configuration


Step 4: Platform Output Examples

CSS Custom Properties output:

iOS Swift output:

Android XML output:


Step 5: Dark Mode Token Overrides


Step 6: Component Token Usage


Step 7: Token Naming Conventions


Step 8: Capstone — Style Dictionary Token Transformer

(Create the file:)

📸 Verified Output:


Summary

Concept
W3C Token Format
Tool

Token file

JSON with $value, $type

Any editor

Transform

Primitive → Semantic → Component

Style Dictionary

CSS output

:root { --token: value; }

css/variables format

iOS output

Swift UIColor/CGFloat

ios-swift format

Android output

res/values/colors.xml

android/colors format

Dark mode

Override semantic tokens

[data-theme="dark"]

References

"{other.token.path}"

Style Dictionary resolves

Component tokens

Component-level CSS vars

Manual or generated

Last updated