Skip to content
mentoor

Topic 1 of 5 · 4 min read

Generating and checking design tokens

Goal: Generate a token set with AI in the design-token format and check it for contrast failures, inconsistent names and uneven scales.

An AI can draft a token set in minutes, but it cannot tell you whether the set works. You write the checks, and the checks decide.

Check yourself · 1 of 3

An AI drafts a text colour and says it has a 5.1:1 contrast ratio on white. What should you do?

Choose one answer

A design token is a named value: a colour, a space, a font size. Components point at the name, never at the raw value. Change color.brand.primary once and every button follows. The W3C Design Tokens Community Group publishes a draft file format for this, so Figma, build tools and coding agents can all read one file.

Why it matters

Claude, ChatGPT or Gemini will produce a tidy palette from one sentence. The output looks professional, which is the danger. Models guess at numbers. They will give you ten greys that are almost identical, a spacing scale that jumps from 8 to 12 to 20, and a "text-muted" colour that is too pale to read on white. Nobody sees it until the product ships.

How to do it

  1. Give the model your constraints, not a mood. Brand colour as a hex, base spacing unit (for example 4px), type ratio, the output format, and the naming pattern you want, such as category.role.variant.
  2. Ask for the draft in the W3C format. Each token has a $value and a $type. Aliases such as {color.brand.primary} let a role point at a base colour.
  3. Check contrast with a tool. Text needs at least 4.5:1 against its background under WCAG 2.2 success criterion 1.4.3. Do not ask the model to confirm it. Compute it.
  4. Check names. One pattern throughout. color.text.muted next to colourGreyLight2 means two people, or two prompts, were involved.
  5. Check the scales. Lay the values in a row. Steps should follow a rule (a fixed unit or a ratio). A value that breaks the rule is a mistake or needs a reason.

Before and after

Weak prompt: "Make me a modern colour palette for a finance app."

Better prompt: "Brand colour #1F4EA3. Produce light-theme tokens in the W3C design-token format: a 9-step neutral ramp, text, background and border roles as aliases, names as color.<role>.<variant>. Text roles must reach 4.5:1 on color.background.default. List each text pair and its ratio."

You still compute the ratios yourself. The model's table is a claim, not a result.

What goes wrong

  • Trusting reported contrast ratios. Models state ratios with confidence and get them wrong.
  • Raw values in components. If a role token holds #6B7280 instead of an alias, the system has two sources of truth.
  • Scales that look even but are not. 4, 8, 12, 20, 24 passes a glance and breaks every layout built on multiples.
  • Regenerating the set later. A second prompt gives different names. Edit the file; do not re-roll it.

Examples

A muted-text token that fails

An AI drafts color.text.muted as #9CA3AF on a #FFFFFF background and states "contrast 4.6:1, passes". Running it through a contrast checker gives about 2.5:1, which fails the 4.5:1 text minimum.

The fix is to darken the token (for example #4B5563), re-run the check, and keep the checked ratio in a comment or test next to the token.

Optional: a token pair in the W3C format

A small pair showing an alias, for readers who work in code.

{
  "color": {
    "brand": { "primary": { "$type": "color", "$value": "#1F4EA3" } },
    "action": { "default": { "$type": "color", "$value": "{color.brand.primary}" } }
  }
}

color.action.default points at the brand colour, so changing the brand value updates every action.

Key points

  • A token is a named value that components reference instead of a raw colour or number.
  • Give the model your constraints (base colour, unit, ratio, naming pattern, format), not a mood.
  • Compute contrast with a tool; a model's stated ratio is a claim to check, and text needs 4.5:1 under WCAG 2.2.
  • One naming pattern for the whole set, and roles written as aliases of base values.
  • Edit the accepted token file rather than regenerating it, or names and values drift.

Common mistakes

  • Accepting the model's contrast ratios without computing them with a checker.
  • Letting two prompts produce two naming styles in the same token file.
  • Asking for a full palette with no brand colour, unit or format, so the model fills every gap with a guess.
  • Re-generating the whole set after a small change instead of editing the one token.

Check yourself · 2 of 3

Which spacing scale looks like a mistake in a set built on a 4px unit?

Choose one answer

Check yourself · 3 of 3

In a token file, why does a role such as color.action.default point at {color.brand.primary} instead of repeating the hex value?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic