Use <figure> and <figcaption> for image captions
Images with visible captions are wrapped in <figure> with a <figcaption> child, creating a semantic association between image and caption.
- Wrap image + visible caption pairs in `<figure>` with `<figcaption>` as a direct child
- `<figcaption>` must be the first or last child of `<figure>`
- Do not duplicate alt text in figcaption—alt is the fallback, figcaption is the visible description
- `<figure>` is appropriate for images, code blocks, diagrams, and charts—not every image
Rule Details
The <figure> element wraps self-contained content, and <figcaption> provides its visible caption. Together they create a semantic relationship between an image and its description.
Code Example
<!-- ❌ Bad: Caption is visually adjacent but semantically unrelated to the image -->
<img src="waterfall.jpg" alt="Waterfall in Costa Rica">
<p>Nauyaca Waterfalls, Dominical, Costa Rica, 2023</p>
<!-- ✅ Good: Semantic association via figure/figcaption -->
<figure>
<img
src="waterfall.jpg"
alt="Nauyaca Waterfalls, a wide two-tier waterfall surrounded by rainforest"
>
<figcaption>Nauyaca Waterfalls, Dominical, Costa Rica — March 2023</figcaption>
</figure>Why It Matters
Using a <p> tag as a caption is invisible to assistive technology as an image description. The <figure>/<figcaption> pattern creates a machine-readable relationship between an image and its caption, which screen readers surface to users. It also communicates to search engines that the caption describes the image, supporting image SEO.
alt vs figcaption
alt and figcaption serve distinct purposes:
alt | figcaption | |
|---|---|---|
| Purpose | Text alternative when image cannot be viewed | Visible caption describing or crediting the image |
| Audience | Screen reader users, image-disabled browsers | All users |
| Content | Conveys the image's meaning or function | Context, attribution, or additional information |
| Visible | No | Yes |
<!-- ✅ alt and figcaption contain different information -->
<figure>
<img
src="chart.png"
alt="Line chart showing website traffic doubled between January and June 2024"
>
<figcaption>
Figure 1: Monthly unique visitors, January–June 2024. Source: Google Analytics.
</figcaption>
</figure>figcaption Placement
<figcaption> must be the first or last child of <figure>.
<!-- ✅ figcaption after the image (most common) -->
<figure>
<img src="portrait.jpg" alt="Portrait of Ada Lovelace">
<figcaption>Ada Lovelace, the world's first computer programmer</figcaption>
</figure>
<!-- ✅ figcaption before the image (e.g., for numbered figure labels) -->
<figure>
<figcaption>Figure 2: System architecture overview</figcaption>
<img src="architecture.png" alt="Diagram showing three-tier architecture with database, API, and frontend layers">
</figure>
<!-- ❌ Bad: figcaption as a middle child -->
<figure>
<img src="portrait.jpg" alt="Portrait">
<figcaption>Caption text</figcaption>
<cite>Source: Wikipedia</cite> <!-- cite should be inside figcaption, not a sibling -->
</figure>Complex Images with Long Descriptions
For charts or diagrams, <figcaption> can contain the full description that supplements a short alt.
<figure>
<img
src="org-chart.png"
alt="Company organisational chart"
aria-labelledby="org-caption"
>
<figcaption id="org-caption">
<strong>Organisational structure as of Q1 2024:</strong>
The CEO oversees three departments. Engineering (12 staff) led by the CTO
handles product development. Marketing (8 staff) led by the CMO handles
growth. Operations (5 staff) led by the COO handles logistics.
</figcaption>
</figure>When NOT to Use figure/figcaption
Not every image needs <figure>. Use it only when an image has a visible caption.
<!-- ✅ Hero image with no caption — plain <img> is correct -->
<img
src="hero.jpg"
alt="Team members collaborating in a modern office"
width="1200"
height="600"
>
<!-- ✅ Decorative icon — no figure needed -->
<img src="checkmark.svg" alt="" aria-hidden="true">Styling
/* Default browser styles vary—reset for consistency */
figure {
margin: 0;
}
figure img {
display: block;
width: 100%;
height: auto;
}
figcaption {
font-size: 0.875rem;
color: #666;
margin-top: 0.5rem;
font-style: italic;
}Standards
- Use these references as the standard for the final image format, delivery, accessibility, and rendering behavior.
- Check the implementation against MDN: Responsive images before treating the rule as satisfied.
- Check the implementation against web.dev: Image performance before treating the rule as satisfied.
Verification
Automated Checks
- Run the W3C HTML validator — it catches
<figcaption>outside<figure>or as a non-first/last child - Use axe DevTools — it flags images missing text alternatives, which may indicate missing figcaption structure
Manual Checks
- Enable VoiceOver (macOS) and navigate with
Wto jump between images — a properly structured figure announces the figcaption as additional context
Use with AI
Copy these prompts to use with your AI assistant, or install the MCP server to use directly from Claude, Cursor, or Windsurf.
Check
Verify implementation
Scan the codebase for images with adjacent visible text that acts as a caption (e.g., a <p> or <span> immediately below an <img> describing it). Verify: 1) Such image-caption pairs are wrapped in <figure>. 2) The caption text is inside a <figcaption> element. 3) <figcaption> is a direct child of <figure>. 4) The alt text on the <img> is not identical to the <figcaption> text—they serve different purposes. Flag any <img> followed by descriptive text that is not structured as figure/figcaption.
Fix
Auto-fix issues
For each image with an adjacent caption: 1) Wrap the <img> and its caption text in a <figure> element. 2) Move the caption text into a <figcaption> element inside <figure>. 3) Review the <img> alt attribute—if the figcaption already fully describes the image for sighted users, the alt can be shorter or empty (alt="") only if the figcaption alone is sufficient for screen readers too; otherwise keep a concise alt. 4) Position <figcaption> as the first or last child of <figure>. Show the corrected HTML.
Explain
Learn more
Explain the semantic meaning of <figure> and <figcaption>. The <figure> element represents self-contained content (an image, code sample, diagram) that is referenced from the main content but could be moved without affecting the document flow. <figcaption> provides a caption or legend for the figure. Screen readers announce the figcaption in association with the figure, giving users context. Without this markup, sighted users see a caption but screen reader users hear only the alt text with no indication that a visible caption exists.
Review
Code review
Review image assets, markup, and delivery configuration related to Use <figure> and <figcaption> for image captions. Flag exact files or components where format choice, sizing, or loading behavior violates the rule, and describe how to confirm the fix in DevTools.