HTML course menu
HTML figure and figcaption: Captions for Images, Code and Charts
Learn the HTML figure and figcaption elements: how to caption images, diagrams, code listings and quotations, how a caption differs from alt text, and when to use figure.
On this page
A figure is self-contained content, such as an image, diagram, chart or code listing, that the main text refers to. In books, figures have captions like "Figure 3: Rainfall by month". HTML has elements for exactly this: <figure> and <figcaption>.
Captioning an image#
<figure>
<img src="/lesson-assets/landscape-300.svg" alt="Green hills under a blue sky with a yellow sun" width="300" height="200">
<figcaption>Figure 1: The view from the hill station at noon.</figcaption>
</figure><figure>wraps the content and its caption. Browsers indent it by default.<figcaption>is the caption. It must be the first or last child of the<figure>.
The caption is linked to the figure, so assistive technology can announce them together.
Caption versus alt text#
They do different jobs, and a captioned image still needs alt:
Do not repeat the caption word for word in the alt text, or screen reader users hear it twice.
Figures are not only images#
Anything that can stand on its own and be referred to can be a figure.
A code listing#
<figure>
<figcaption>Listing 1: A minimal HTML page.</figcaption>
<pre><code><!DOCTYPE html>
<title>Hello</title>
<p>Hi!</p></code></pre>
</figure>A quotation with its source#
<figure>
<blockquote>
<p>A journey of a thousand miles begins with a single step.</p>
</blockquote>
<figcaption>From the <cite>Tao Te Ching</cite></figcaption>
</figure>When to use figure#
Ask: could this be moved to an appendix or the side of the page without breaking the flow of the text? If yes, it is a figure. A small icon inside a sentence or a decorative background image is not a figure.
Practice#
Practice exercise
Make a figure using /lesson-assets/mango.svg (160 × 160) with the caption "Figure 3: Alphonso mangoes are grown in Maharashtra." and suitable alt text.
Show solution
<figure>
<img src="/lesson-assets/mango.svg" alt="Drawing of a ripe yellow mango with a leaf" width="160" height="160">
<figcaption>Figure 3: Alphonso mangoes are grown in Maharashtra.</figcaption>
</figure>Key takeaway#
Finished this lesson?