Color contrast check

Docs

The Color Contrast Check grades every text and control pair the kit paints, in both themes at once, and repairs the failing ones by moving a foreground along its ramp. It opens from the score's Contrast row.

The Color Contrast Check dialog: the Semantic tab with light and dark columns of colours, ratio and level, a status per row and Fix all failing in the footer

How to use it

Two tabs, each labelled with its passing count: Semantic (the palette's pairs) and Component (what each component paints from its own tokens). The dialog opens on Semantic, or on Component when nothing on Semantic fails and a component row does.

Each row shows, per theme, the two colours, the ratio and a level (AAA, AA or fail), and a status: a check when both themes pass, amber when either fails, a dash when a token is missing. A failing required row carries Fix, which repairs that row in every theme where it fails and names the sibling rows the same foreground drags along (also moves Muted). Fix all failing in the footer repairs every required row; Undo fixes puts them back. Repairs land as unsaved edits, so Discard undoes them too.

The three advisory rows (Border, Input, Sidebar border) sit under a folded group at the end of the Semantic table; each has its own Fix, and Fix all leaves them alone.

An amber info popover beside a Component row's label says why it is off: bg points at design.color.amber.50, not primary. A failing Component row carries its own Fix, and that tab's footer has its own Fix all failing, which runs every row's fix at once.

How it works

Text pairs need 4.5:1 and non-text pairs 3:1 (WCAG 2.2). A required pair is one a reader depends on: every text pair, the focus ring, the sidebar's and the chart series' rows, and every component pair. An advisory pair is decoration, a divider or a field outline: measured and shown, never counted against the score, never moved by a bulk repair. The lists are on Contrast pairs.

The semantic fixer moves foregrounds only. For each failing required row it searches the project's own design colours, same ramp first and least change in lightness next, for a shade that clears every required pair that foreground sits in, so one pass converges and a repair never breaks a sibling. A light plan writes the light reference and a dark plan the dark one, so both themes repair in one press.

The component fixer makes one of two moves on the component's own reference: a slot that left its seed semantic is pointed back; a slot that still follows its seed and fails anyway (slider, progress and switch grade pairs no semantic row mirrors) is moved to the nearest colour that clears the threshold in both themes, a design colour if one does, else a semantic that resolves per theme. A row with no move shows its reason and no button.

A gradient is graded where its text is read: on every stop and between the stops. A project holds up to three gradients, and each grades the text it carries: the primary gradient grades primary-foreground (Primary gradient start, end, and middle with a third stop), the accent gradient grades accent-foreground (Accent gradient …), and the page wash grades foreground, muted-foreground and primary (Page wash …, … muted …, … primary …). Fix never recolours your brand for a primary row; change the wash or the primary yourself. Each row covers its stop and the stretch of gradient halfway to the next one, so the rows together cover the whole gradient. When the text's lightness sits between two stops' lightness, the gradient passes through the text's own lightness somewhere between them, so the row fails at 1:1 even though both stops pass, and says The text matches the gradient's own lightness between its start and end. Otherwise the row reports the lowest ratio along its stretch, measured both as a browser blends the gradient and as Figma does. The Component tab grades a button's, badge's or card's own label on each stop of the gradient it paints, instead of on the solid fill the gradient covers. No fixer moves a stop, because the gradient is a brand choice: Fix moves the label, and only to a colour that reads on the whole gradient. A stop row whose text is shared with other rows, and that no shared colour can fix, says so; on the primary gradient it says to fix the button's own label on the Component tab. A Component row with no move says No label colour reads on every stop of this gradient.

A pair whose token the project lacks is unscored and shows a dash. A dash on a required row keeps the score's Contrast row from full marks.

What can go wrong

  • A row with no Fix: no foreground satisfies every pair it sits in; move the background by hand, or accept the row.
  • Fix all repaired the semantics and a component row still fails: the component's own reference strayed from its seed; its row's Fix points it back.
  • A project created before a pair existed shows its row unscored.