Sub topic 15
Accessibility: Contrast Checks and Alternative Text
This chapter assumes you can place text over an image, use a scrim, and read a CSS rule. It covers two things: measuring whether text can be read, and describing images for people who cannot see them. Both checks come at the end of the workflow, but they are cheaper to pass if you plan for them from the start.
Why a layout can look fine and still fail
Your monitor, your eyesight and your office lighting are not your reader's. A reader may use a phone in sunlight, have low vision or color blindness, or use a screen reader that never shows the image. Accessibility checks replace "it looks readable to me" with numbers and written descriptions anyone can verify.
Measuring contrast
WCAG (the Web Content Accessibility Guidelines) defines contrast as a ratio between the relative luminance of two colors. The scale runs from 1:1 (identical colors) to 21:1 (black on white). Luminance weights green most and blue least, because the eye is more sensitive to green. Two colors with the same hue difference can therefore have very different ratios.
The thresholds you will use most often are:
| Element | Level AA (minimum) | Level AAA (enhanced) |
|---|---|---|
| Body text | 4.5:1 | 7:1 |
| Large text (18 pt, or 14 pt bold, and up) | 3:1 | 4.5:1 |
| Icons, input borders, chart lines | 3:1 | Not defined |
| Logos and purely decorative text | No requirement | No requirement |
Aim for AA everywhere and for AAA on long reading text. Large text gets a lower threshold because bigger letterforms stay recognizable at lower contrast. Do not stretch that rule to a thin display face, since a hairline weight at 40 pt can still be hard to read.
You can compute the ratio yourself. This script follows the WCAG 2.x formula.
def channel(value):
c = value / 255
return c / 12.92 if c <= 0.03928 else ((c + 0.055) / 1.055) ** 2.4
def luminance(hex_color):
h = hex_color.lstrip("#")
r, g, b = (int(h[i:i + 2], 16) for i in (0, 2, 4))
return 0.2126 * channel(r) + 0.7152 * channel(g) + 0.0722 * channel(b)
def contrast(foreground, background):
lighter, darker = sorted(
(luminance(foreground), luminance(background)), reverse=True
)
return (lighter + 0.05) / (darker + 0.05)
print(round(contrast("#ffffff", "#000000"), 1)) # 21.0
print(round(contrast("#767676", "#ffffff"), 2)) # 4.54, the lightest gray that passes AA on whiteIn day-to-day work you will use a plugin or an eyedropper-based checker in your design tool instead. The formula still explains why a mid-tone background such as #808080 fails for both black and white text. Neither color is far enough from it in luminance.
Checking text that sits on an image
A flat background has one ratio. A photograph has thousands, which makes the check harder in three ways.
- Sample the worst case, not the average. Take the lightest pixels under dark text, or the darkest pixels under light text. A single bright cloud behind a headline can break one word.
- Check every size and crop. A layout that passes at desktop width may place the same text over a different part of the photo on a phone, where the
covercrop shifts. - Check the image as it will be delivered. Compression, color profiles and overlays change the final pixels.
The usual fix is the scrim from the previous chapter. A scrim is a semi-transparent layer between the image and the text, and it raises the minimum contrast in the text zone. Here is the hero from the spine again.
.hero {
position: relative;
min-height: 24rem;
display: flex;
flex-direction: column;
justify-content: flex-end;
padding: 2rem;
color: #fff;
background:
linear-gradient(to top, rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0) 60%),
url("coast.jpg") center / cover no-repeat;
}Consider the worst case: pure white sky behind the text. Black at 70% opacity over white produces about #4d4d4d. White text on that gray has a ratio of roughly 8:1, which passes AA and AAA for body text. A scrim at 30% would leave the same white pixel at about #b3b3b3, and white text on it would fail.
Color alone is not enough
Contrast ratio does not catch every problem. Do not use color as the only signal. A red price and a green price that differ only in hue look identical to someone with red-green color blindness. Pair color with a second cue, such as an icon, a label, a weight change or an underline. A simulation filter for color blindness, available in most design tools, is a fast check.
Alternative text
Alternative text (alt text) is a written equivalent of an image. Screen readers speak it. Browsers display it when the image fails to load. Search engines use it. The core principle is that alt text describes what the image does on this page, not everything visible in it. The same photograph can need different alt text in different layouts.
Start with the role you identified earlier in the tutorial:
| Image role | What to write |
|---|---|
| Content (the photo carries information) | A concise description of what matters |
| Mood or background | An empty `alt=""`, so assistive technology skips it |
| Text baked into the image | The same words as the image text |
| Chart or diagram | A short summary in the alt text, plus the data or a longer description nearby |
| Image inside a link or button | What the link does, such as "Download the 2026 report" |
The spine's figure example shows the content case.
<figure>
<img src="harbor.jpg" alt="Fishing boats moored in a harbor at dawn">
<figcaption>Harbor at dawn, 6:10 a.m.</figcaption>
</figure>The alt text and the caption do different jobs here. The caption adds the time. The alt text describes the scene. If the caption already says everything the alt text would say, an empty alt="" can be better, because a screen reader would otherwise announce the same information twice.
Writing good alt text
- State the content and purpose first. Skip openers such as "Image of" or "Picture of", because the screen reader already announces that it is an image.
- Keep it short, usually one sentence. If you need more, put the full description in the visible text and refer to it.
- Include any text that appears in the image.
- Describe what the reader needs to know. For a team photo on an about page, "The five-person design team in the studio" is enough. A list of clothing is not.
- Never omit the
altattribute. A missing attribute makes some screen readers read out the file name. An empty attribute marks the image as decorative on purpose.
Keep text as text
Headlines that you export as part of a flattened image cannot be resized, selected, translated or read aloud, and they blur at high zoom. In web layouts, keep text live and place it over the image in CSS or in your design file's text layers. If a layout must be exported as one image, such as a social post, put the full text in the alt text or in the post body. In exported PDFs, tag the document and add alt text to images in your layout application's accessibility settings.
Where the checks fit
The loop between steps B and D matters most. Fix contrast by changing the layout, not by dropping the check.
Common mistakes
- Checking contrast against a flat brand color when the text actually sits on a photo.
- Checking only the desktop view.
- Using light gray placeholder or caption text that falls below 4.5:1. Captions are small, so they need the full ratio.
- Giving every image a long, detailed description, including decorative ones.
- Putting keywords in alt text to help search ranking. This makes it worse for screen reader users.
Exercise
A hero image has white text over a photo. The brightest area under the text is a pale sky, close to #e0e0e0, and your scrim is black at 30% opacity there. Roughly what color does the sky become, and will white text pass AA for body text? What would you change?
Show answer
Black at 30% opacity keeps 70% of the original color. #e0 is 224, and 224 × 0.7 is about 157, so the sky becomes roughly #9d9d9d. White on that gray is about 2.7:1, which fails the 4.5:1 minimum for body text (and the 3:1 minimum for large text). Raise the scrim opacity to at least about 65%, which gives a background near #4e4e4e, or move the text to a darker part of the photo. Then re-measure at the worst pixel.
Exercise
A page has a decorative wave pattern behind a section heading, and a photo of a bakery's front window with the shop name visible on the glass. What alt text does each image get?
Show answer
The wave pattern is mood or background, so it gets an empty alt="" and screen readers skip it. The bakery photo is content, and the name on the glass is part of the information, so write something like alt="Front window of Maple Street Bakery with loaves on display", using the real shop name in place of the example.