DevTools Logo

Design Tokens to Code

Design Tokens to Code

Convert W3C Design Tokens into CSS, Tailwind, or Swift code locally.

W3C token JSON

Supports aliases such as {color.primary} and nested groups.

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

.env Secret Safety Linter

Validate .env syntax and spot likely leaked credentials or placeholder secrets.

.htaccess Generator

Build an Apache .htaccess — HTTPS redirects, rewrites, error pages, security headers, and basic auth

2D Fluid Dynamics & Particle Physics Sandbox

A physics playground with two engines sharing one canvas. The fluid mode runs a real Eulerian Navier-Stokes solver — semi-Lagrangian advection, explicit diffusion, Jacobi pressure projection and vorticity confinement — that you paint with dye and velocity using mouse or touch. The particle mode is a damped Verlet N-body engine with gravity wells, Coulomb attractors and repulsors, spring links, wall restitution and elastic circle collisions. Particle counts adapt to the device (100k target on WebGL2 desktop, 2k-5k on CPU fallback), and every configuration exports as runnable code: a Matter.js world, a PixiJS ticker setup, or a standalone vanilla Canvas engine.

AI Function Calling Schema Generator

Generate function calling JSON schemas from TypeScript interfaces

Algorithm Arena & Data Structure Visualizer

Interactive arena for algorithms and data structures: eight sorting algorithms racing on one seeded input, six pathfinding algorithms walking generated mazes, and BST, AVL, Red-Black, B-tree, heap and trie operations replayed step by step with rotations highlighted. Every run shows the Big-O table and the phase-highlighted reference implementation in four languages, and compared values can be played as pitch (sonification) through the shared audio engine. Everything runs client-side; inputs never leave the browser.

Ansible Playbook Generator

Build an Ansible playbook — hosts, vars, and tasks with modules — as YAML