VIS-002 Use each colour token only for the role and the pairs it was made for
- Level
- Rule
- Verdict
- Unanimous (3 of 3)
- Status
- proposed, version 1.1.0
Rule
Use a *-foreground token only on its own fill, border-input for the edges of controls, and a state colour such as ring, destructive or accent only for its state. Never use raw palette classes such as text-gray-500 for something that carries meaning.
Examples
Live examples built with Justified's components. Try them with the mouse, the keyboard or a screen reader.
Do: Each text colour on its own fill
Light theme
Order 2291
Payment failed
3 plants, delivery on Friday
- text-destructive on the card: measuring …
- text-muted-foreground on bg-muted: measuring …
- text-primary-foreground on bg-primary: measuring …
Dark theme
Order 2291
Payment failed
3 plants, delivery on Friday
- text-destructive on the card: measuring …
- text-muted-foreground on bg-muted: measuring …
- text-primary-foreground on bg-primary: measuring …
text-destructive on the card, text-muted-foreground on bg-muted and text-primary-foreground on bg-primary are the pairs Justified tests. Switch the page theme and the figures follow, because every colour is named by its role.Don't: A foreground on someone else's fill
Light theme
- text-primary-foreground on bg-muted: measuring …
- text-muted-foreground on bg-primary: measuring …
- text-accent-foreground on bg-destructive: measuring …
Dark theme
- text-primary-foreground on bg-muted: measuring …
- text-muted-foreground on bg-primary: measuring …
- text-accent-foreground on bg-destructive: measuring …
Do: The accent fill for the chosen card
bg-accent fill, a check and the word Selected. The focus ring is a separate thing: it is only on the card you are on.Don't: Selection drawn as focus
border-ring ring-2 ring-ring. Before you touch anything it already looks as if it has focus. Press Tab into the group and the real focus ring is hard to tell from it; press Tab again and the chosen card still looks focused.Why
A token is a promise about where a colour goes. primary-foreground was chosen to be read on primary, input to mark the edge of a field, ring to show focus. Justified's contrast test checks those pairs in both themes, and a theme change reaches every place that uses them by name. A colour borrowed for another job keeps none of that. It was never measured where it now sits, it does not follow the theme, and when the palette changes it breaks without anyone noticing. A colour that has one meaning also keeps that meaning: once red marks a sale price, it no longer warns of an error. No WCAG criterion asks for tokens. What the law asks is the measured result, in VIS-001 for text and VIS-004 for borders and graphics. Using colours by role is how the judges keep that result true across themes and later changes, and it keeps colour cues readable in the sense of WCAG 2.2, 1.4.1 Use of Color. Following the pairs does not prove contrast on its own; only measuring does.
Do
- Pair each
*-foregroundwith its own fill:text-card-foregroundonbg-card,text-popover-foregroundonbg-popover,text-primary-foregroundonbg-primary.foregroundandmuted-foregroundgo onbackground, andmuted-foregroundalso onmuted. - Use the status colours as Justified tests them:
text-destructive,text-success,text-warningandtext-infoas text on the page, and each status fill under its own*-foreground. An order in a plant nursery's shop that could not be charged reads "Payment failed" intext-destructive. - Edge every field with
border-input: anInput, a custom select, a combobox trigger, a date picker button. Their edge is the only sign of where they are. Keepborder-borderfor dividers and the edge of aCard, where nothing depends on seeing it. - Keep
ringfor the focus indicator that KBD-001 describes. Show a chosen plan or an active tab some other way, as VIS-003a says. - Keep
bg-accentfor items that are hovered, highlighted, pressed or selected, which is how shadcn's menus andToggleuse it. Give a static panelbg-mutedorbg-card, so an item that turnsbg-accentinside it still shows. Whether hover and press looks exist at all is VIS-008; whenbg-accentdraws both hover and selected, VIS-008b asks the selected item for a cue the hover does not use. - When the product needs a colour it does not have, such as a soft badge of
bg-primary/10withtext-primaryfor Ships in 2 days, add it to the tokens with a name for its role and add the pair to the contrast test, so it is measured in both themes. This step is our own choice. - Give brand colours the same treatment: a token with a role and a tested pair, not a one-off class.
- Treat an inverse surface, such as a dark tooltip in the light theme, as a pair like any other.
Don't
- Use raw palette classes such as
text-gray-500,bg-slate-100,text-blue-600orborder-gray-200, or a hex value instyle. Such a colour has no role, so nothing says where it may go. It does not follow the theme, and nobody has tested it. - Put a foreground on someone else's fill:
text-primary-foregroundonbg-muted,text-muted-foregroundonbg-primary,text-accent-foregroundonbg-destructive. Each is tested only against its own partner. - Use
text-destructivefor a sale price or a New label,bg-successas a brand accent, ortext-warningfor a heading. DLG-005 keeps the destructive button for actions that destroy something. - Mark a selected card with
border-ringorring-2 ring-ring. Selection then looks like focus. - Draw an
Inputoverride, a custom select or a combobox trigger withborder-border. It measures about 1.4:1 against the light page and 1.5:1 against the dark one, made for a divider, not for the only edge of a control; VIS-004 gives the law's side. - Mix systems in one pair, as in
bg-card dark:bg-zinc-900. The pair now depends on two palettes, and the test sees only one. - Reuse chart colours for status, or status colours for chart series in a chart that is not about status. shadcn's
--chart-1to--chart-5are a role of their own; Justified does not define or test them.
Exceptions
- Colours that carry nothing. An illustration or a photo is outside the rule. A colour that people read, or that marks a control, a state or a boundary, is inside it.
- Text over a photo or video. Text in
text-whiteortext-blackon a photo or a video, laid on a scrim such asbg-black/60, may keep that colour. No token is made to pair with a picture, and the picture looks the same in both themes. VIS-001 asks for the text to be measured against the lightest spot behind it. This is our own choice. - Loading signs. A spinner, such as shadcn's
Spinner, counts as an icon. Beside a word that says what is happening it only decorates (STR-005), so its colour carries nothing; as the only sign of a wait, it takes a token like any icon that carries meaning. This is our own choice. - Neighbouring rules. The contrast a pair must reach is VIS-001 for text and VIS-004 for borders and graphics. The second cue next to a colour is VIS-003a. The focus ring itself is KBD-001. Hover and press looks are VIS-008, and a lasting state kept apart from them is VIS-008b.
Verdict
Unanimous (3 of 3). Only the judges decide; the expert witnesses are shown but do not vote. How verdicts work
| Source | Role | Stance | Page |
|---|---|---|---|
| WCAG 2.2 | Law | Supports | 1.4.3 Contrast (Minimum) |
| WCAG 2.2 | Law | Supports | 1.4.11 Non-text Contrast |
| WCAG 2.2 | Law | Supports | 1.4.1 Use of Color |
| Material Design | Judge | Supports | Color roles Badges: accessibility |
| Apple Human Interface Guidelines | Judge | Supports | Color |
| Carbon Design System | Judge | Supports | Color |
| GOV.UK Design System | Expert witness | Supports | Colour |
| Nielsen Norman Group | Expert witness | No position |
Each stance links to the page it rests on, read on the date in the source register. This page never repeats what a source says; read the source itself.
History
- Version 1.1.0, : Two new exceptions, both our own choice, so the rule agrees with VIS-001 and the lint check. White or black text on a scrim over a photo or video may keep that colour, and a spinner counts as an icon. Points to VIS-008 and VIS-008b for hover, press and selected looks.
- Version 1.0.0, : First version.
Last checked against the other rules for conflicts on .
More in Colour and motion: 11 rules and 0 guidelines · All rules
Justified is an independent project. It is not affiliated with, sponsored or endorsed by the organisations whose guidance it cites. Read the full statement.
Apple is a trademark of Apple Inc., registered in the U.S. and other countries and regions.