DevTools Logo

Design Tokens to Code

Design Tokens to Code

Convert W3C Design Tokens (DTCG) into CSS, Tailwind, JavaScript or SwiftUI. Aliases are resolved and errors are listed.

Runs in your browser
4 tokens converted
Try an example

W3C token JSON

42 lines · 686 chars

Generated code

CSS custom properties
:root {
  --color-link: #6750A4;
  --color-primary: #6750A4; /* Brand color */
  --shadow-card: 0px 2px 8px #0002;
  --spacing-md: 16px;
}

    Examples

    Alias chain resolves to the value

    Input
    { "a": { "b": { "$type": "color", "$value": "{b.c}" } }, "b": { "c": { "$type": "color", "$value": "#112233" } } }
    Output
    --a-b: #112233;
    --b-c: #112233;

    a.b follows b.c to the literal, so both CSS variables carry the resolved hex with no errors.

    Multi-layer shadow

    Input
    { "el": { "$type": "shadow", "$value": [{ "color": "#000", "offsetX": "0px", "offsetY": "2px", "blur": "4px" }, { "color": "#fff", "offsetX": "0px", "offsetY": "1px" }] } }
    Output
    0px 2px 4px #000, 0px 1px #fff

    Each layer joins offsetX/offsetY/blur/color with spaces and layers join with commas.

    About this tool

    Design Tokens to Code ingests W3C-DTCG-style JSON with formatDesignTokens(source, target) for css, tailwind, tailwind-config, and swift targets. collect walks nested groups depth-first in sorted key order, inheriting $type down the tree; a node with $value becomes a token at its dot path (e.g. color.primary) while typeless or type-unknown nodes push Missing or unsupported $type instead of throwing. Six types are accepted: color, dimension, fontFamily, fontWeight, shadow, and borderRadius.

    Aliases use {path} syntax in both exact ({color.primary}) and embedded (1px solid {color.primary}) forms, with an optional $ prefix stripped before lookup. Resolution is recursive through the token map, so chains like a.b → b.c → #112233 settle to the final value, while unknown names throw Unknown alias and revisiting a path in the resolution stack throws Alias cycle: a → b → a — both reported as per-path errors with valid tokens still emitted. Resolved values are validated per type (dimension/borderRadius need {value, unit}, color needs a string or colorSpace+components, shadow needs a non-empty layer or object) or reported as Invalid <type> token value.

    Emission is deterministic and per-target: css and tailwind render :root/@theme blocks with kebab-case --path-name variables, tailwind-config renders an extend map, and swift renders Color/Font extensions filtered by type with quoted-string escaping. Multi-layer shadows join layers with commas (0px 2px 4px #0003, 0px -1px #fff), font families quote whitespace-containing faces, and srgb component triples convert to hex with alpha suffixes. Malformed JSON returns a JSON-path error with empty output rather than throwing.

    How to use this tool

    1. Paste DTCG JSON

      Provide nested groups with $type and $value (e.g. color.primary as color #336699). Tokens collect in sorted path order; typeless nodes report errors.

    2. Link with aliases

      Reference other tokens as {color.primary} alone or embedded in strings. Chains resolve transitively; cycles and unknown names become errors.

    3. Pick a target

      Choose css (:root variables), tailwind (@theme), tailwind-config (extend map), or swift (Color/Font extensions) and copy the output block.

    Use cases

    Shipping themed CSS

    Export resolved --color-* and --spacing-* variables from one token file into :root or @theme blocks.

    Keeping aliases honest

    Catch Unknown alias and Alias cycle errors plus invalid $type values before tokens reach production.

    Feeding native apps

    Render the swift target to get typed Color/Font extensions alongside the web CSS from the same source.

    Common mistakes

    Mistake:Omitting $type on a leaf token.

    Fix:Every $value node needs a supported $type (or an inherited one from its group); otherwise it reports Missing or unsupported $type and is skipped.

    Mistake:Creating an alias loop.

    Fix:a → b → a throws Alias cycle with the path chain. Break the loop so one token holds the literal value.

    Mistake:Feeding a raw dimension string where an object is required.

    Fix:dimension and borderRadius validate as {value, unit} after resolution — supply {"value": 8, "unit": "px"} rather than "8px" when the target must type-check.

    Frequently asked questions

    What does this tool do?

    It converts W3C-DTCG-style JSON into css, tailwind, tailwind-config, or swift output with formatDesignTokens: sorted dot-path tokens in six types (color, dimension, fontFamily, fontWeight, shadow, borderRadius), recursive {path} aliases, per-type validation, and deterministic variable emission.

    How do alias chains, cycles, shadows, and bad types behave?

    a.b → {b.c} → #112233 resolves both variables to #112233; an x↔y loop reports Alias cycle without throwing; a two-layer shadow renders 0px 2px 4px #000, 0px 1px #fff; and $type wat reports Missing or unsupported $type as a per-path error.

    Is my token file uploaded or stored?

    No. Collection, alias resolution, validation, and target rendering are pure client-side string math — token files never leave your browser.

    Why is a token missing from the output?

    It failed validation: typeless leaves report Missing or unsupported $type, wrong shapes report Invalid <type> token value, and unresolvable aliases report Unknown alias or Alias cycle. Fix the flagged path; valid tokens still emit.

    References & standards