Figure & Caption
<figure> and <figcaption> — the semantically correct pattern for photos, diagrams, and code snippets with captions.
figure Groups Content With Its Caption
<figure> wraps self-contained content — usually an image — along with an optional <figcaption> that describes it. The pairing is semantically linked: assistive technology understands the caption belongs to that specific content.
<figure> <img src="chart.png" alt="Bar chart of quarterly revenue" width="400" height="250"> <figcaption>Fig. 1 — Revenue grew 18% quarter over quarter.</figcaption> </figure>
alt vs figcaption — Different Jobs
These two often get confused. alt describes what the image literally shows, for when the image can't be seen. figcaption adds context, commentary, or a citation — visible to everyone, sighted or not.
<figure> <img src="team.jpg" alt="Five people standing in front of a whiteboard" width="500" height="300"> <figcaption>The BitWithBite team at the 2026 planning offsite.</figcaption> </figure>
figcaption Can Go First
figcaption doesn't have to come after the image — placing it first, before the image, is equally valid and sometimes reads better (a caption that introduces what you're about to see).
<figure> <figcaption>Before and after: the homepage redesign</figcaption> <img src="redesign.jpg" alt="Split screen comparing old and new homepage layouts" width="500" height="280"> </figure>
figure Isn't Just for Images
figure can wrap a code snippet, a quote, a chart built with SVG, or any standalone unit of content referenced from the main text — anything that could be moved to an appendix without breaking the flow of the article.
<figure> <pre><code>function greet() { console.log("Hello!"); }</code></pre> <figcaption>Listing 1 — a minimal greeting function</figcaption> </figure>
Create 3 <figure> elements, each with an image and a figcaption:
1. A "before" photo with a caption describing the starting state
2. An "after" photo with a caption describing the result
3. A code snippet wrapped in figure with a figcaption acting as a listing number/title
💡 Show hints if you're stuck
- Each figure needs its own alt text on the img AND its own figcaption — they shouldn't just repeat each other
- Code figure:
<figure><pre><code>...</code></pre><figcaption>...</figcaption></figure>