Skip to main content

HTML Tags

HTML <figure> Tag

Written by Updated HTML <figure> Tag exercises

The figure tag groups an image, chart, code sample or video with its caption, so they belong together. If you could move it to an appendix and refer to it as "see figure 3", it is a figure.

The caption goes in a figcaption tag, as the first or last child of <figure>. Screen readers then announce the caption as the figure's name.

Syntax

html

<figure>
  <img src="nature.jpg" alt="A calm forest">
  <figcaption>Morning view of a green forest</figcaption>
</figure>

There are no special attributes, only the global ones such as id and class.

Example

html

<h2>Example: Image with Caption</h2>
<figure>
  <img src="https://picsum.photos/seed/picsum/400/300" alt="Dense forest with sunlight" width="400">
  <figcaption>A random Image</figcaption>
</figure>

The image appears with the caption "A random Image" below it. Browsers give <figure> a margin by default, so it is slightly indented.

Not only for images

A code sample as a figure

html

<figure>
  <pre><code>console.log("Hello");</code></pre>
  <figcaption>Listing 1: printing a message</figcaption>
</figure>

A figure can hold a diagram, a table, a quote, a video or several images together.

Browser Support

Chrome
Edge
Firefox
Safari
Opera
IE9+
YesYesYesYesYesYes

Good to know

  • The caption does not replace alt. Alt describes the image for people who cannot see it; the caption adds information everyone sees. Do not repeat the same text in both.
  • Do not wrap every image in <figure>. Decorative images and images inside the text flow do not need it.
  • Remove the default indent with figure { margin: 0; }.

HTML <figure> Tag exercises

Wrap an image

Put this image, described as A star, in a figure with the caption Five points: https://html5andcss3.org/samples/star.svg

Result

Check your answer to see it here.