<figure>
Example
<div class="figure">
<img src="chart.png" alt="Sales by month">
<p class="caption">Sales grew in spring.</p>
</div><figure>
<img src="chart.png" alt="Sales by month">
<figcaption>Sales grew in spring.</figcaption>
</figure><figcaption> names the <figure> for assistive tech, which a styled <p> cannot do.
Common mistakes
- Wrapping every image in
<figure>, including decorative ones. - Skipping
altbecause the caption already describes the image.
Key points
<figure>wraps self-contained content that could move elsewhere without breaking the text.- A
<figcaption>is the first or last child of<figure>. - An image in a figure still has its own
alt, even with a caption.
Interview questions
Can figure hold code or a quote instead of an image?
Yes, <figure> can hold any flow content, such as code listings, quotes, tables or videos.
Should alt repeat the figcaption text?
No, alt describes the image and the caption adds context. Avoid making both say the same thing.