Design and Social Media

How to Turn Design Tokens into Code for Web, iOS and Android

What design tokens are, the W3C DTCG format, aliases and naming, and how to generate CSS variables, Tailwind, Swift and Android resources from one file.

Saizul Amin
Saizul Amin2 Nov 2026 · 3 min read
How to Turn Design Tokens into Code for Web, iOS and Android

How to Turn Design Tokens into Code for Web, iOS and Android

A design system often starts as a page of colour swatches and spacing rules. Then the web team types the colours into CSS, the iOS team into Swift and the Android team into XML, and within months the three blues no longer match. Design tokens fix this by keeping each decision once, in a data file, and generating code for every platform from it. This guide explains the idea, the emerging standard format and a practical workflow, using the Design Tokens Code Generator.

What a token is

A token is a named design decision with a value and a type: color.brand.primary is #0ea5e9, space.md is 16px, radius.md is 8px, motion.fast is 150ms. Tokens can describe colours, dimensions, font families and weights, durations, easing curves, shadows and composite typography styles. Naming them by purpose rather than appearance (color.text.muted rather than grey-700) means you can change the look without renaming anything.

The W3C DTCG format

The Design Tokens Community Group, a W3C community group with members from design tool makers and large design systems, publishes a format for token files. Each token is an object with $value and usually $type, plus an optional $description. Groups are plain objects that nest tokens and can set a $type for all their children. Tools such as Tokens Studio for Figma and Style Dictionary support it, which makes tokens portable between design and code.

Aliases build layers

The most powerful feature is aliasing. A token's value can be a reference such as {color.neutral.900}. Systems usually have layers:

  • Primitive tokens: the raw palette and scales, such as neutral.900 or blue.500.
  • Semantic tokens: purposes, such as text.default or surface, pointing at primitives.
  • Component tokens: specific uses, such as button.background, pointing at semantic tokens.

Changing one primitive updates everything that refers to it. A generator must resolve aliases, detect references to tokens that do not exist and catch circular references.

Naming for every platform

Each platform has its own conventions. CSS custom properties use kebab case (--color-brand-primary), Swift uses camel case (colorBrandPrimary) and Android resources use snake case (color_brand_primary). A good generator converts names consistently, so a token is easy to find on every platform. Prefixes such as --ds- avoid clashes with other variables on the page.

Platform details that matter

  • Colours: CSS takes hex or rgb, Android expects #AARRGGBB with alpha first, SwiftUI uses Color with red, green and blue between 0 and 1.
  • Dimensions: web uses px or rem, Android uses dp for layout and sp for text so users' font settings are respected, iOS uses points. Converting rem assumes a base, usually 16 px.
  • Tailwind: version 4 reads @theme variables in CSS, version 3 reads a JavaScript config.

Accessibility checks belong here

Because tokens define colour pairs, they are the right place to check contrast. WCAG 2 requires a contrast ratio of at least 4.5 to 1 for normal text and 3 to 1 for large text at level AA, and 7 to 1 for AAA. Checking text tokens against surface tokens before release prevents inaccessible combinations from reaching every product at once.

A workflow that scales

  1. Keep the tokens file in a repository, reviewed like code.
  2. Designers edit tokens in their tool and export JSON, or edit the file directly.
  3. A generator produces CSS, Tailwind, Swift and Android outputs.
  4. Each platform imports the generated files rather than hand-written values.
  5. Version the package and write a short changelog for every release.

Limits

A generator follows general naming and conversion rules that may not match every team's conventions, and multi-theme setups such as light and dark modes usually need separate token sets. The DTCG format is still a draft, so details may change. Review generated files before publishing a new design system release.

Completely freeNo cost, no sign-up
Files stay privateEverything runs in your browser
Easy in your languageAvailable in many languages