Star on GitHub

Token contrast matrix

Paste a design tokens file and see how every text colour reads on every background, in light and in dark. Each pair is scored with WCAG 2.2 and with APCA, and the ones that fall short can be copied out as Markdown. Nothing leaves your browser.

Matrix#

Try an example

10 colour tokens in light. 2 modes found, read from the groups light and dark.

8 of 24 pairs pass AA

AA for body text is 4.5:1. 16 pairs fall short in light.

Show

Translucent backgrounds sit on

Choose rows and columns6 rows, 4 columns

Names with text, fg, foreground, icon, border or on- are foreground and become rows. Names with bg, background, surface, canvas, card or fill are backgrounds and become columns. Anything else is both. Change any token here.

  • color.bg.default
  • color.bg.subtle
  • color.surface
  • color.accent-bg
  • color.text.primary
  • color.text.secondary
  • color.text.muted
  • color.text.link
  • color.on-accent
  • color.border

Each cell is the row's colour as text on the column's colour. Hover, focus or tap a cell for the detail and a fix. Click a swatch to edit a colour.

color.bg.default
color.bg.subtle
color.surface
color.accent-bg
color.text.primary
color.text.secondary
color.text.muted
color.text.link
color.on-accent
color.border
16 pairs in light, weakest first.

How do I use it?#

  1. Paste or drop your file

    Paste the JSON into the box, drop a .json file onto it, press Open a .json file, or load one of the examples. The grid updates as you type. The example loaded at first has a light and a dark theme.

  2. Pick a mode

    If the file has light and dark modes, choose one above the grid. The grid and the export follow the mode you choose.

  3. Read the grid

    Rows are text colours and columns are backgrounds. Each cell shows the pair as it looks, the WCAG ratio, the APCA Lc and a level. Hover, focus or tap a cell for the detail, or filter to the pairs that fall short. Arrow keys move between cells.

  4. Fix, export or check

    Press Suggest a fix on a failing pair to see the nearest colour that reaches 4.5:1, or click a swatch to edit a colour yourself, then copy the updated tokens. Copy the pairs under 4.5:1 as Markdown for an issue or a pull request, or press Check file in validator to check the file against the W3C format first.

How does it score a pair?#

WCAG 2.2. The relative luminance of each colour is worked out from its sRGB channels, as the definition in WCAG 2.2 sets out, and the ratio is (lighter + 0.05) / (darker + 0.05). Black on white is 21:1.

APCA. The algorithm is APCA-W3 version 0.0.98G-4g, with the constants from the reference implementation. Lc is positive for dark text on a light ground and negative for light text on a dark one; its size, not its sign, is the contrast. As a check, #888888 on white scores Lc 63.1 and white on #888888 scores Lc -68.5.

Before either runs, a translucent colour is blended in sRGB the way a browser does it and rounded to eight bits, so the number matches what is on screen. A colour that cannot be read is marked in its cells rather than left out, and Check file in validator shows what is wrong with the file.

Use the design tokens validator to check the file against the W3C format, and the converter to turn it into CSS, Tailwind, SCSS or TypeScript. Orvain UI tokens ship in this format.

Questions#

Is my tokens file uploaded anywhere?

No. The file is read and scored in your browser, so what you paste or drop never leaves the page.

What is the difference between WCAG and APCA?

Which one should I rely on?

What do the levels mean?

How does it handle colours with transparency?

Which colour spaces can it read?

How does it tell light from dark?

How does it decide what is text and what is a background?