Lesson 20 of 51 · Module 3, lesson 5 of 6 · 3 min
Figures and captions
Give an image a visible caption, and understand how a caption differs from alt text.
What you'll learn
- How to give an image a visible caption with
<figure>and<figcaption>- The difference between a caption and
alttext- What else can go in a figure
Why this matters
A caption tells every reader — sighted or not — what they are looking at, or why it matters. HTML has a pair of elements that tie the caption to its image, so that browsers and screen readers know they belong together.
A figure with a caption
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Fresh bread</title>
</head>
<body>
<h1>Fresh bread</h1>
<figure>
<img src="images/bread.jpg" alt="A round golden loaf of bread with three cuts on top" width="300" height="200">
<figcaption>The loaf after 40 minutes in the oven.</figcaption>
</figure>
<p>Bake the bread until the top is golden.</p>
</body>
</html>
What you'll see: the image, with the caption in normal text right under it. The whole figure is moved in a little from the left edge (the browser's default look).
<figure>wraps the whole thing.<figcaption>holds the caption. Put it first or last inside the<figure>.
Caption or alt?
They do different jobs, so a figure usually needs both:
alt | <figcaption> | |
|---|---|---|
| Who gets it | People who cannot see the image | Everyone |
| What it says | What the image shows | Extra information: who, when, why it matters |
| Visible? | No (unless the image fails to load) | Yes |
Do not copy the same words into both. The screen reader user would hear them twice.
What can be a figure?
A figure is any content that the main text refers to, but that could move — for example to the side, or to the next page — without breaking the text. That can be a photo, a chart, a code example or a quotation:
<figure>
<pre><code><p>Hello!</p></code></pre>
<figcaption>The smallest useful HTML element.</figcaption>
</figure>
Not every image needs to be a figure. A small icon or a decorative image stays a plain <img>.
Try it yourself
- Select the complete example and choose Try it.
- Move the
<figcaption>above the<img>and see where the caption appears. - Make a second figure with
images/salad.jpg, a goodalt, and a caption that adds something the image does not show — for example, who made the salad.
Common mistakes
- Using a normal paragraph as a caption. It looks right but is not connected to the image. Fix: use
<figcaption>inside<figure>. - The same text in
altand in the caption. Fix:altdescribes; the caption adds. - Leaving out
altbecause there is a caption. The image still needs a description. Fix: keep both. - More than one
<figcaption>in a figure. Only one is allowed. Fix: combine the text.
Check yourself
- Which element holds the caption of a figure?
- Should a figure's
altand caption use the same words? - Can a code example be a figure?
Answers
<figcaption>, inside<figure>.- No.
altdescribes the image; the caption adds information for everyone. - Yes. A figure can hold images, charts, code or quotations.
Next: one image size does not fit every screen. The next lesson (optional) shows how to give phones a smaller file.

