Sub topic 6
Captions and other secondary text
This chapter assumes you can write basic HTML and CSS, and that you have read the earlier chapters on semantic structure, the type scale, and body text. Here you apply those ideas to text that supports the main content instead of carrying it.
What secondary text is
Secondary text is text that explains, credits, or qualifies something else. It sits below body text in the hierarchy. Common examples:
- Image and video captions
- Table captions
- Photo credits and publication dates
- Fine print such as legal notes
- Short hints under form fields
Secondary text is quieter than body text, but it must stay readable. Making it quieter means a smaller size, a lighter weight, or a softer color. It does not mean unreadable.
Tie the caption to its content in HTML
A caption is only useful if the page says which content it describes. HTML does this with figure and figcaption. The figcaption must be a direct child of the figure, placed first or last.
<figure>
<img src="ridge.jpg" alt="A hiker walking along a narrow ridge at sunrise">
<figcaption>The ridge route at sunrise. Photo: A. Moreno</figcaption>
</figure>A paragraph with a class="caption" placed under an image looks the same on screen. It has no programmatic link to the image, so assistive technology cannot tell that the two belong together.
Tables have their own element. Put caption as the first child of table:
<table>
<caption>Daily food weight by trip length</caption>
<thead>
<tr><th scope="col">Days</th><th scope="col">Food (kg)</th></tr>
</thead>
<tbody>
<tr><td>3</td><td>2.1</td></tr>
<tr><td>7</td><td>4.9</td></tr>
</tbody>
</table>Use small for side comments such as copyright lines or terms. It means "fine print". Do not use it for general shrinking, because size belongs in CSS.
Caption or alt text?
The alt attribute and the caption do different jobs. The alt text replaces the image for people who cannot see it. The caption is visible to everyone and adds context, such as place, credit, or why the image matters.
| Part | Audience | Purpose |
|---|---|---|
| `alt` attribute | Screen reader users, or anyone when the image fails to load | Describes what the image shows |
| `figcaption` | Everyone | Adds context, source, or interpretation |
Do not copy the caption into alt. A screen reader would read the same sentence twice.
Choosing the element
Style it as secondary
Reuse your type scale. A caption should come from the small step of the scale, not from a one-off value. Keep the line height comfortable, because small text with tight lines is hard to read.
:root {
--text-sm: 0.875rem;
--leading-body: 1.5;
--color-muted: #595959;
}
figcaption,
caption,
small {
font-size: var(--text-sm);
line-height: var(--leading-body);
color: var(--color-muted);
}
figcaption {
margin-top: 0.5rem;
max-width: 65ch;
}
caption {
text-align: left;
padding-bottom: 0.5rem;
}Browsers center table captions by default, so the rule above sets text-align: left. Left alignment usually fits the edge of the table or the text around it.
The rule margin-top: 0.5rem keeps the caption close to its image. Proximity tells the reader that the two belong together. If the gap above a caption is larger than the gap below it, the caption looks like it belongs to the next block.
Common errors
- Too light. Pale gray text on white often fails the contrast minimum of 4.5:1 for normal-size text.
#595959on white passes.#999999does not. - Too small. Going below about 0.75rem makes captions hard to read, especially when zoomed or on phones. Stay at
0.875remor larger. - Pixel sizes. Captions set in
pxignore the user's font-size preference. Userem. - Italic everywhere. Long italic passages are tiring to read. If a caption is short, italics are fine. Otherwise rely on size and color.
- Wrong element for the role. A caption written as a
h4or adivpollutes the heading outline or loses its meaning.
Hints for form fields
Short help text under an input is also secondary text. Style it like a caption, and link it to the input so screen readers announce it with the field:
<label for="phone">Phone number</label>
<input id="phone" name="phone" type="tel" autocomplete="tel" aria-describedby="phone-hint">
<p id="phone-hint" class="hint">Include the country code, for example +44.</p>.hint {
font-size: var(--text-sm);
color: var(--color-muted);
margin-top: 0.25rem;
}The label names the field. The hint is extra information, so it stays visually quieter than the label.
Exercise
A page shows a chart image followed by <p class="caption">Sales by region, 2025</p>. Name two problems with this markup and give the fix.
Show answer
First, the paragraph has no programmatic link to the image, so assistive technology cannot tell it is a caption. Second, the meaning exists only in a class name. Fix it by wrapping both in a figure and changing the paragraph to <figcaption>. Then style figcaption in CSS with the small step of the type scale and a muted color that still passes 4.5:1 contrast.
Exercise
Your caption uses color: #aaaaaa on a white background and font-size: 11px. Which two properties would you change, and to what kind of values?
Show answer
Change color to a darker gray with at least 4.5:1 contrast against white, such as #595959. Change font-size to a rem value from your scale, such as 0.875rem, so it follows the user's font-size settings.