Codectionary / Developer documentation / HTML

<figure>, <figcaption>

The <figure> element wraps self-contained content — typically an image, illustration, diagram, code snippet, or chart — along with an optional caption provided by <figcaption>. Content in a figure is meant to be referenceable independently of the main flow; a reader should be able to move it elsewhere on the page (or even to an appendix) without breaking the document's meaning.

Syntax

<figure>
  <img src="chart.png" alt="Sales chart">
  <figcaption>Figure 1: Quarterly sales</figcaption>
</figure>

Examples

Image with Caption

The most common use of figure: an image with a descriptive caption.

<figure>
  <img src="https://via.placeholder.com/500x300" alt="Mountain landscape at sunset">
  <figcaption>A sunset over the mountains, taken in 2025.</figcaption>
</figure>

Code Snippet as a Figure

Using figure to present a labeled code example.

<figure>
  <pre><code>const sum = (a, b) => a + b;</code></pre>
  <figcaption>Example: an arrow function that adds two numbers</figcaption>
</figure>

Multiple Images in One Figure

Grouping several related images under a single caption.

<figure>
  <img src="before.png" alt="Before redesign">
  <img src="after.png" alt="After redesign">
  <figcaption>Before and after the homepage redesign</figcaption>
</figure>

Best practices

  • Use figure when content (and its caption) should make sense even if moved elsewhere on the page
  • figcaption can appear as either the first or last child of figure — both are valid
  • Not every image needs a figure — use it when a caption or independent referencing genuinely adds value
  • The alt attribute on img still matters even inside a figure; figcaption is a caption, not alt text

At a glance

Purpose
Structure and meaning for web content
File extension
.html · .htm
Runs in
Web browsers
Usually used with
CSS and JavaScript

Specifications & further reading

Related HTML documentation