Topic 2.5
Figures and Captions
In one line
figure wraps self-contained content that the main text refers to (an image, chart, code listing or quotation), and figcaption gives it a visible caption that is tied to it in code.
Think of it like this
A picture in a school textbook. The photo of a volcano has a small line under it: "Figure 3: Mount Fuji, Japan". The text says "see Figure 3". The picture and its caption belong together; you could move both to the next page and the chapter would still make sense. That pair is exactly what figure and figcaption are.
Words you'll meet
New words in this topic, in plain English. Come back here whenever one feels fuzzy.
- figure
- A self-contained piece (image, chart, code, quote) that the text refers to and that could be moved without breaking the text.
- figcaption
- The visible caption of a figure. It must be the figure's first or last child.
- Caption
- A short line of text that explains or credits a picture, chart or listing.
- Accessible name
- The name a screen reader announces for an element. For a figure it comes from its figcaption.
- Alt text
- The
altattribute of an image: a text replacement describing what it shows, for people who can't see it. - Self-contained
- Makes sense on its own and can be moved elsewhere without breaking the surrounding text.
Step by step
01Start with an image in text
An image referred to by the text, with a credit line underneath written as a plain paragraph. Visually fine, but nothing ties the line to the image.
<p>The dough doubles in size (see the photo below).</p>
<img src="dough.jpg" alt="A bowl of risen bread dough">
<p>Photo: Asha, after one hour</p>02Wrap both in figure
Put the image and the caption inside figure, and make the caption a figcaption. Now they are one unit with a real link between them.
<p>The dough doubles in size (see Figure 1).</p>
<figure>
<img src="dough.jpg" alt="A bowl of risen bread dough, puffed above the rim">
<figcaption>Figure 1: The dough after one hour. Photo by Asha.</figcaption>
</figure>03Use it for code and quotes too
A code listing with a title, or a quotation with its source, is also a figure. The caption carries the title or attribution.
<figure>
<pre><code>console.log("Hi");</code></pre>
<figcaption>Listing 1: The smallest script</figcaption>
</figure>
<figure>
<blockquote>
<p>Simplicity is prerequisite for reliability.</p>
</blockquote>
<figcaption>Edsger W. Dijkstra</figcaption>
</figure>04Group several items under one caption
A figure can contain more than one image. Each image still needs its own alt; the single caption explains the group.
<figure>
<img src="1.jpg" alt="Dough just mixed, shaggy">
<img src="2.jpg" alt="Dough after kneading, smooth">
<img src="3.jpg" alt="Dough after rising, doubled">
<figcaption>Figure 2: Three stages of bread dough</figcaption>
</figure>05Decide when it isn't a figure
Run the textbook test. Not every image needs figure.
Try it yourself
- 1
Move the caption to the top
In the first example, move
figcaptionabove thesvg. Predict the second console line, then run:Caption is last child: false, but it's still valid, because first child is also allowed. - 2
Reset the default margin
Add
figure { margin: 0; }to the first example's CSS and run. The third line now prints0pxand the figure lines up with the paragraph. - 3
Check the accessible name
Inspect the first example's
figurein Chrome DevTools → Accessibility pane. Its name is computed from the figcaption.
Code & diagrams
The chart is inline SVG so the example needs no image file. The 40px is the browser's default figure margin.
Preview
Console
Nothing logged yet.Expected console output
Caption: Figure 1: Sales per quarter, 2026 (thousands)
Caption is last child: true
Default left margin: 40pxPreview
Console
Nothing logged yet.Break it on purpose
Errors are the best teachers. Make each change, read the error, guess what went wrong, then reveal the answer.
Break #1
Put the caption in the middle
Place figcaption between two images inside one figure.
Break #2
Use the caption instead of alt
Remove the alt attribute from an image because the figure has a caption.
Myth vs fact
Myth
Every image should be wrapped in figure.
Fact
Only images (or other content) that the text refers to or that need a caption. Logos, icons and decorative images are not figures.
Myth
figure is only for images.
Fact
Charts, code listings, quotations, poems, tables, videos and audio can all be figures.
Myth
With a figcaption, the image doesn't need alt.
Fact
Caption and alt do different jobs. Keep a meaningful alt (or alt="" only if the caption fully describes the image).
Pro corner
Extra depth for experienced readers. New to this? Skip it for now and come back later.
- ▸
Per the HTML-AAM spec,
figuremaps to the ARIA rolefigure, and its accessible name is computed from itsfigcaption. Screen readers differ in how much they announce: some read the caption on entering the figure, others only when reading through. - ▸
When the caption fully describes the image (common in data-heavy reports), WAI guidance allows
alt=""on theimgto avoid double reading, but only if the figure has the caption. When unsure, keep a short alt. - ▸
figureis not a sectioning element: headings inside it still join the page outline. Prefer afigcaptionto anh3for figure titles. - ▸
For tables, use the table's own
captionelement (Phase 3) rather than wrapping infigure, unless you need a caption that covers several tables.
Remember this
- 1
<figure>marks self-contained content that is referenced from the main flow but could be moved elsewhere (to an appendix, the side, the next page) without breaking the text. It's not only for images: diagrams, charts, code listings, poems, quotations, tables and videos can all be figures. - 2
<figcaption>is the figure's caption. It must be the first or last child of thefigure, and there can be only one. The browser connects them: thefigcaptionbecomes the figure's accessible name, so a screen reader announces the caption when the user reaches the figure. - 3
Caption vs alt text. The image's
altdescribes what the image shows, for people who can't see it. The caption is visible to everyone and adds context: who, where, when, source, or what to notice. They should not repeat each other: if the caption already says everything, the alt can be short, but it must still be present (Topic 1.7 covers alt rules). - 4
When not to use figure. A logo, a decorative divider or an inline icon isn't a figure: it isn't referenced and has no caption. A product photo in a product card is usually just an
img. Ask: "Would I number this in a printed book and refer to it?" If yes, it's a figure. - 5
A
figurecan hold several items under one caption, like a gallery of three photos captioned "Figure 4: The three stages of bread dough". It can also wrap ablockquotewith the source in thefigcaption, which is the recommended way to attribute a quotation (the attribution isn't part of the quote, so it shouldn't go inside theblockquote). - 6
By default browsers give
figuremargins (1emtop and bottom,40pxleft and right), which is why figures look indented. Reset them in CSS if your design doesn't want them.
Explain it without notes
What kind of content belongs in a figure? Give three examples that aren't photos.
What is the difference between an image's alt text and a figure's caption?
Where can a figcaption go, and how many can a figure have?
Practice
Turn an image of a map with the credit "Map: OpenStreetMap contributors" into a proper figure. Use a fictional file name and good alt text.
Attribute this quote correctly with figure: "Talk is cheap. Show me the code." by Linus Torvalds.
Trade-offs
- ↔
A
figurewith a caption is clearer and more accessible, but adds markup and default margins; for simple decorative or card images, a plainimgis lighter and correct.
Done when you can
I can decide whether content is a figure with the textbook test.
I can write a
figurewith afigcaptionas first or last child.I keep alt text and caption doing different jobs.
I can use
figurefor quotes, code and charts, not only photos.