Sub topic 3
Contrast and color: making the cue visible to everyone
This chapter assumes you know basic HTML, CSS selectors, the box model, color values, and pseudo-classes. You should also be able to open your browser's developer tools. The goal is to make sure the cues that mark an element as clickable can be seen by everyone, including people with low vision or color blindness.
Why contrast matters for clickable things
A button or link signals "click me" through its color, shape, and underline. If a person cannot see those cues, the element is effectively not clickable for them. Two problems cause most failures:
- Low contrast. The difference between two colors is too small, so text or borders fade into the background.
- Color-only signals. The only difference between a link and plain text is its color. Users who cannot tell the two colors apart see no difference.
Measuring contrast
The Web Content Accessibility Guidelines (WCAG) measure contrast as a ratio from 1:1 (identical colors) to 21:1 (black on white). Your tools compute this from the relative luminance of the two colors, so you don't need to do the math by hand.
| What you are checking | Minimum ratio (WCAG AA) |
|---|---|
| Normal text, including button and link text | 4.5:1 |
| Large text (about 24px, or 18.66px bold) | 3:1 |
| Borders and icons that identify a control | 3:1 against the adjacent color |
The third row matters for buttons. Under WCAG 1.4.11 (Non-text Contrast), a visible boundary that you rely on to show where a control is must reach 3:1 against its surroundings. A pale gray outline on white fails that check, even if the label text passes.
Check the button text against the button's own background, and check the button's edge (or fill) against the page behind it. If the button has a filled background that already stands out from the page, the border does not need its own contrast.
Contrast in the button example
Here is the primary button from the earlier styling, with its colors checked:
.btn {
background: #1d4ed8;
border: 2px solid #1d4ed8;
color: #ffffff;
}White text on #1d4ed8 has a ratio of roughly 6.7:1, which passes the 4.5:1 requirement. The blue fill against a white page is also well above 3:1, so the button's shape is visible. The secondary variant uses #1d4ed8 text and border on a transparent background. On white, that text has the same ratio, so it passes as well.
Do not rely on color alone
Suppose a paragraph uses dark gray text and your links are blue with no underline. The two colors differ only slightly in brightness. A user with color blindness, or anyone on a washed-out screen, may not see the links. WCAG 1.4.1 (Use of Color) says color must not be the only way to convey information.
The fix is to add a second cue that does not depend on hue:
a {
color: #1d4ed8;
text-decoration: underline;
text-underline-offset: 0.15em;
}The underline is the second cue. Other second cues include a border, an icon, bold weight, or a filled shape. For buttons, the fill and border already provide one.
A simulation helps here. If you convert your page to grayscale and the links disappear, you are relying on color alone.
html {
filter: grayscale(1);
}Add that rule temporarily while testing, then remove it.
Checking contrast in developer tools
Most browsers show contrast data in their inspector.
- Right-click a link or button and choose Inspect.
- In the Styles pane, click the color swatch next to the
colorproperty. - Read the contrast ratio shown in the color picker. It marks whether the value passes AA.
- Repeat for each state you style: normal, hover, and disabled.
Hover and focus colors are easy to forget. A hover color that darkens the button, such as #1e40af, usually raises contrast. A hover color that lightens it can lower the ratio below the limit.
Common errors
- Light gray placeholder-style link text on white that fails 4.5:1.
- A button with a pale border and a white fill, so its edge disappears.
- Links inside body text that differ from it only by hue.
- Checking the default state only and skipping hover and disabled colors.
Exercise
A link inside a paragraph is blue (#1d4ed8) and the body text is dark gray (#374151). The link has no underline. Which WCAG requirement does this risk failing, and what is the simplest fix?
Show answer
It risks failing Use of Color (1.4.1), because color is the only cue separating the link from the text, and the two colors are close in brightness. The simplest fix is to add text-decoration: underline, which gives a second cue that does not depend on hue.
Exercise
A secondary button has a 1px border of #cbd5e1 on a white page, a white fill, and dark text that passes 4.5:1. Does it meet the contrast guidance for the button's boundary, and how would you fix it?
Show answer
No. #cbd5e1 on white is well below 3:1, so the boundary is hard to see. Darken the border, for example to #1d4ed8 or another color that reaches 3:1 against white, and consider using a 2px width.