The figure element represents self-contained content, potentially with an
optional caption, which is specified
using the figcaption element
The figure, its caption, and its contents are referenced as a single unit
A caption can be associated with the figure element by inserting a
figcaption inside it (as the first or the last
child) (MDN)
The first figcaption element child of the element, if any, represents the
caption of the figure element's contents
If there is no child figcaption element, then there is no caption
The figure element can be used to annotate illustrations, diagrams, photos,
code
listings, etc, that are referred to from the main content of the document, but that
could,
without affecting the flow of the document, be moved away from that primary content,
e.g. to
the side of the page, to dedicated pages, or to an appendix
Example (Apples)
HTML
<figure>
<figcaption>A Picture of Apples (webp format)</figcaption>
<img src="../images/apples.webp" alt="Picture of Apples">
</figure>
Example (Quote)
HTML
<figure>
<figcaption>
<b>Edsger Dijkstra:</b>
</figcaption>
<blockquote>
If debugging is the process of removing software bugs,
then programming must be the process of putting
them in
</blockquote>
</figure>
Example (Poem)
HTML
<figure>
<p class="poem">
Bid me discourse, I will enchant thine ear, Or like a fairy trip upon the
green, Or, like a nymph, with long dishevelled hair, Dance on the sands, and
yet no footing seen: Love is a spirit all compact of fire, Not gross to
sink, but light, and will aspire.
</p>
<figcaption>
<cite>Venus and Adonis</cite>, by William Shakespeare
</figcaption>
</figure>
CSS
.poem {
white-space: pre;
}
Example (Code, W3C)
In listing 4 we see the primary core interface
API declaration.
HTML (W3C)
<p>
In
<a href="#l4">listing 4</a>
we see the primary core interface API declaration.
</p>
<figure id="l4">
<figcaption>
Listing 4. The primary core interface API declaration.
</figcaption>
<pre>
<code>
interface PrimaryCore {
boolean verifyDataLine();
void sendData(in sequence<byte> data);
void initSelfDestruct();
}
</code>
</pre>
</figure>