<figure>

Term side of the Card.
Topic: Images & Icons
Unit title: <figure>
Categories: Tag
Explanation side of the Card

Explanation: The element that represents self-contained content, such as an image with an optional caption, code snippet or diagram. It's used to group media and its associated text, allowing for more flexible placement and styling.

Browser compatibility:
  • The chrome browser supports this feature starting from version 8.
  • The edge browser supports this feature starting from version 12.
  • The firefox browser supports this feature starting from version 4.
  • The safari browser supports this feature starting from version 5.1.
Availability: 

Example

Wronghtml
<div class="figure">
  <img src="chart.png" alt="Sales by month">
  <p class="caption">Sales grew in spring.</p>
</div>
Righthtml
<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 alt because 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.

Analytics cookiesWe'd like to use analytics cookies to see which pages are useful. They're set only if you accept. Privacy Policy