References

Beginner-friendly references for web development, with live, editable examples.

The HTML <figure> tag

Element All modern browsers Updated
Quick answer

The HTML <figure> element groups self-contained content — an image, diagram, chart, code listing or quotation — that is referenced from the main text, optionally with a <figcaption> caption.

Overview

The <figure> element wraps self-contained content that the surrounding text refers to as a single unit — most often an illustrative <img>, but equally a diagram, a <pre> code listing, a chart, or a quotation. The defining trait is that it could be moved elsewhere — to a sidebar, the top of the page, an appendix — without breaking the flow of the prose that mentions it.

Add a <figcaption> as the figure's first or last child to caption it — a figure number, a credit line, or an explanation. When a caption is present, it supplies the figure's accessible name, tying caption and content together for assistive technology.

Reach for <figure> when the relationship between content and caption matters semantically. If you only need a styled box around an image, a plain <img> (or a <div>) is enough.

Syntax

<figure>
  <img src="chart.png" alt="Q4 revenue chart">
  <figcaption>Q4 revenue grew 18%.</figcaption>
</figure>

Example

Live example
<figure style="margin:0;">
  <img src="https://codeshack.io/web/img/icon.png" alt="CodeShack logo" width="64" height="64">
  <figcaption style="color:#64748b;font-size:.9rem;">Figure 1: the logo.</figcaption>
</figure>

Best practices

  • Use it for content referenced as a unit — images, diagrams, code listings or quotations.
  • Caption it with a <figcaption> as the first or last child.
  • Reserve it for content that could be relocated without breaking the surrounding text.
  • Keep the alt text on the image even when a caption is present — they serve different purposes.

Frequently asked questions

When should I use the figure element?
For self-contained content the text refers to as a unit — an image, diagram, code listing or quote — that could be moved elsewhere without breaking the flow.
Does a figure need a caption?
No, the <figcaption> is optional, but it is common and provides the figure's accessible name when present.
What is the difference between alt text and a figcaption?
The alt describes the image for people who cannot see it; the caption is visible text that labels or explains the figure for everyone. Use both.
Can a figure contain code or a quote?
Yes. A <figure> is not just for images — a <pre> code listing, chart or <blockquote> works too.