figure – figure with caption
<figure>…<figcaption>…</figcaption></figure>
Self-contained content that the text refers to and that could be moved elsewhere (to an appendix, to the margin): an image, a chart, a code sample, a quotation, a video. The caption is written in figcaption at the start or the end. The browser indents figure by 40 px on the left and on the right.
- Default display:
display: block - End tag: required
- Content: flow content and at most one
figcaptionas the first or last child - Where it can be used: anywhere flow content is allowed
- DOM interface:
HTMLElement
Attributes
Only global attributes.
Examples
An image with a caption:
<figure> <img src="/img/slider.jpg" alt="A white castle with two towers behind a green lawn" width="250" height="167"> <figcaption>Fig. 1: A castle with towers</figcaption> </figure>
A code sample with the caption at the top:
<figure> <figcaption>Listing 2: Submitting a form</figcaption> <pre><code>form.submit();</code></pre> </figure>
Accessibility
figure has the figure role and figcaption becomes its accessible name. The caption does not replace the alt of an image, though: alt says what is in the image, the caption adds to it (the number of the image, the source, the context). When the caption describes the image fully, alt may be shorter, but it must not be missing.
Things to watch out for
- Not every image belongs in
figure– an icon or an image in the middle of the text that the text does not refer to is just animg. - You usually do not want the default
margin: 1em 40px– reset it in CSS. - Only one
figcaptionis allowed, and only as the first or last child.
Browser support
Baseline – widely available: works in all major browsers and has for a long time (since 2015 at the latest). Since version: Chrome 8, Firefox 4, Safari 5.1. As of October 2026 (MDN browser-compat-data).
Related:
figcaption – caption
img – image
picture – image in several versions
blockquote – block quotation
pre – preformatted text