Colour contrast and motion patterns for shadcn
Rules / Colour and motion: 11 rules and 0 guidelines
Colour and motion are where a theme meets the eyes of the person using it. A grey that looks calm on a good screen can be unreadable in sunlight, and a panel that slides in smoothly for one person brings on dizziness in another. shadcn’s theme gives every colour a name, such as muted-foreground or border-input, and tw-animate-css gives every overlay an entrance. Neither checks what a colour is drawn on once opacity is added, says whether red is the only sign of an error, or stops a carousel. Justified’s contrast test measures the token pairs in both themes; the rules here keep that true in the rest of the app.
Where colour and motion go wrong
opacity-50on a timestamp, or white text on a photo with no scrim, checked only against the token on paper. VIS-001- Raw palette classes such as
text-gray-400, or a foreground token on a fill it was never paired with. VIS-002 - A status shown as a green or red dot, or an active tab told apart only by its text colour. VIS-003a
- A link in a paragraph that is coloured but not underlined, or underlined only on hover. VIS-003b
- A field edged with
border-border, so its outline barely shows against the page. VIS-004 - A clickable card that looks the same under the pointer and when pressed, or a selected tab whose mark disappears on hover. VIS-008, VIS-008b
- A toggle that looks pressed but has no
aria-pressed, so a screen reader hears no state. VIS-008a - A carousel or a logo strip that moves forever with nothing to press. VIS-005
- Panels that slide and zoom for someone who has asked their system for less motion. VIS-006
- A shake as the only sign of a wrong password. VIS-007
How the rules fit together
Three rules cover contrast. VIS-001 sets it for text: 4.5:1, or 3:1 for large text, against the colour the browser actually paints, after opacity, overlays and images, and in every state. VIS-004 sets 3:1 for what people need to see to find a control and tell its state, such as a field’s edge, a checkbox’s tick or a switch’s track, and for the parts of a graphic they need. VIS-002 is how both stay true: every colour that marks something has a role, and each token is used only for that role and the pairs it was made for. A pair the product needs and does not have is added to the tokens and measured, not borrowed.
Two rules keep colour from carrying meaning alone. VIS-003a says a meaning or a state, such as a status, an error or a selection, always has a second sign: text, an icon, a shape or a pattern. VIS-003b is the narrower case of a link in running text, which stands out from the words around it at rest by more than colour; with Justified’s tokens that means an underline. The current page in a menu is the same idea applied to navigation (NAV-002b).
Three rules cover how a control shows its state. VIS-008 changes the look of everything people can press while it is pressed and while the pointer is over it. VIS-008b keeps a state that lasts, such as selected or on, visible during hover, focus and press, and never lets those look like it. VIS-008a sets every state the control shows in code on the control as well, and changes it whenever the look changes.
Three rules cover motion. VIS-005 gives a way to pause, stop or hide content that starts by itself and moves for more than five seconds, or that updates by itself. VIS-006 swaps movement for a short fade or an instant change when the person’s device asks for reduced motion. VIS-007 makes sure that whatever an animation means is also shown in text, an icon or a state that stays. The setting and the pause control do different jobs, so one never stands in for the other. Loaders are STA-001’s, and the focus indicator is KBD-001.
What WCAG requires and what the judges decide
Six rules here come from WCAG 2.2. Text contrast follows from 1.4.3 Contrast (Minimum), non-text contrast from 1.4.11 Non-text Contrast, colour as the only sign and links in text from 1.4.1 Use of Color, pausing motion from 2.2.2 Pause, Stop, Hide, and a state set in code from 4.1.2 Name, Role, Value. For these the law decides. The judges who spoke supported each of them, all three in the case of text contrast.
The other five are decided by the judges; no Level AA criterion requires them. Colour tokens used by role, reduced motion, a change on hover and press, and a lasting state that stays visible had all three in support, and motion that is never the only sign had both who spoke. Reduced motion is asked for at Level AAA, in 2.3.3 Animation from Interactions, which VIS-006 treats as a further aim, not a requirement.
Rules and guidelines
Each one has its own page with the full rule, Do and Don't cases, exceptions and the verdict. A rule is decided by WCAG 2.2 or by the judges. A guideline is our own choice. How the method works
Required by WCAG 2.2
A WCAG 2.2 Level AA criterion requires the behaviour. Where a rule adds advice of its own, it says so.
VIS-001Give text at least 4.5:1 contrast against the colour it is actually drawn onText people need to read reaches 4.5:1 against the colour it is drawn on, or 3:1 when it is large. Measure after opacity, tints, overlays and images have done their work, in every state. Text in an inactive control, decoration and logos are exempt; see Exceptions.VIS-003aNever let colour be the only sign of what something means or which state it is inNever let colour be the only sign of what something means or which state it is in, such as a status, an error or a selection. Add text, an icon, a shape or a pattern. A lightness difference of 3:1 counts too, except where people must know what a particular colour means.VIS-003bMake a link in running text stand out from the words around it by more than colourA link in running text stands out from the words around it at rest, not only on hover or focus: by a cue that is not colour, such as an underline, or by 3:1 lightness against the surrounding text. Justified's tokens close the 3:1 route, so a cue is needed; our own choice is an underline.VIS-004Give the edges and state marks of controls, and the parts of graphics people need, 3:1 contrastThe parts people need to see to find a control and tell its state, and the parts of a graphic they need to understand it, reach 3:1 against the colours next to them. Inactive controls, decoration and graphics whose information is also given in text are exempt.VIS-005Let people pause, stop or hide content that moves or updates by itselfWhen something starts by itself and shares the screen with other content, give a way to pause, stop or hide it if it moves, blinks or scrolls for more than five seconds. If it updates by itself, such as an auto-playing carousel, give that way, or a way to set how often, at any length. Essential motion is exempt.VIS-008aSet every state a control shows in code on the control, and change it whenever the look changesWhen a control shows a state, such as on or off, selected, checked, expanded or unavailable, that state is also set in code on the control itself. Whenever the look changes, the state in code changes with it.
Decided by the judges
No WCAG criterion requires these. The judges who spoke support them, all or most of them.
VIS-002Use each colour token only for the role and the pairs it was made forUse 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.VIS-006Swap movement for a fade or no motion when the person asks for reduced motionWhen the person's device or browser asks for reduced motion, replace movement across the screen, such as sliding, zooming, scaling, parallax and bouncing, with a short fade or an instant change. Stop motion that only decorates and show its final state. Keep motion that is essential.VIS-007Never let motion be the only sign of what happenedNever let an animation be the only way the interface says something. Whatever it means, such as an error, a change, a new item or that something is live, is also shown in text, an icon or a state that stays on screen when the motion has ended or is turned off.VIS-008Show a change on everything people can press, while it is pressed and while the pointer is over itEverything that does something when pressed, including a clickable card, row or list item, changes its look while it is pressed and, where the pointer can hover, while the pointer is over it. A control that is off shows neither change.VIS-008bKeep a selected or on state visible while the item is hovered, focused or pressedA state that lasts, such as selected, checked, on or current, stays visible while the same item is also hovered, focused or pressed. The look of hover, focus or press is never the same as the look of a state that lasts.
All rules · Is shadcn accessible? · Give the rules to an AI agent
Justified by Blackwood & Blake helps you work toward WCAG 2.2 AA. It is not a certification. Read more
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.