Figure with Caption
Proper use of semantic figure and figcaption elements for images and illustrations.
The Bad (Inaccessible)
<div class="image-box">
<img src="https://images.unsplash.com/photo-1464822759023-fed622ff2c3b?auto=format&fit=crop&q=80&w=400" alt="A mountain ranch">
<p>A beautiful ranch nestled in the Swiss Alps.</p>
</div>
Accessibility-Ready Code
<!-- Gold Standard: Semantic grouping of image and description -->
<figure class="accessible-figure">
<img
src="https://images.unsplash.com/photo-1464822759023-fed622ff2c3b?auto=format&fit=crop&q=80&w=800"
alt="Three mountain peaks covered in snow under a clear blue sky"
loading="lazy"
>
<figcaption>
<strong>Figure 1:</strong> The Eiger, Mönch, and Jungfrau peaks in the Swiss Alps.
</figcaption>
</figure>
// Gold Standard: Semantic grouping of image and description
figure.accessible-figure
img(
src="https://images.unsplash.com/photo-1464822759023-fed622ff2c3b?auto=format&fit=crop&q=80&w=800"
alt="Three mountain peaks covered in snow under a clear blue sky"
loading="lazy"
)
figcaption
strong Figure 1:
| The Eiger, Mönch, and Jungfrau peaks in the Swiss Alps.
const AccessibleFigure = ({ src, alt, caption, id }) => (
<figure className="accessible-figure">
<img src={src} alt={alt} loading="lazy" />
<figcaption id={`caption-${id}`}>
{caption}
</figcaption>
</figure>
);
<template>
<figure class="accessible-figure">
<img :src="src" :alt="alt" loading="lazy">
<figcaption>
<slot name="caption" />
</figcaption>
</figure>
</template>
<figure class="overflow-hidden rounded-lg border border-slate-200 bg-white p-2">
<img
src="https://images.unsplash.com/photo-1464822759023-fed622ff2c3b?auto=format&fit=crop&q=80&w=800"
alt="Three mountain peaks covered in snow"
class="w-full rounded-md"
>
<figcaption class="mt-2 text-sm text-slate-600 italic px-1">
The Eiger, Mönch, and Jungfrau peaks.
</figcaption>
</figure>
The Standard
The <figure> and <figcaption> elements provide a semantic way to associate a piece of content (like an image, chart, or code snippet) with its description. This relationship is programmatically exposed to assistive technology, unlike a simple div and p combo.
WCAG Criteria
- 1.1.1 Non-text Content: Images must have text alternatives.
- 1.3.1 Info and Relationships: Information and relationships conveyed through presentation are programmatically determinable.
❌ The Bad (Inaccessible)
What’s Wrong?
- Broken Relationship: Screen readers treat the image and the text as two unrelated elements.
- Generic Container: Using a
divprovides no semantic context about the grouping.
✅ The Good (Accessibility-Ready Code)
Why This Works
- Semantic Grouping: The
<figure>element creates a logical container that groups the content and its label. - Implicit Labeling: Browser accessibility APIs automatically use the content of
<figcaption>as the accessible name for the<figure>. - Structured Data: Helps search engines and assistive tools understand the hierarchy of the page.
Accessibility Checklist
- Use
<figure>for content that is referenced from the main text but can be moved to another part of the document. - Place
<figcaption>as the first or last child of the<figure>. - Ensure the
<img>still has a descriptivealtattribute even if the caption is detailed. - Avoid redundant text (e.g., “Image of a mountain” in alt and “A mountain” in caption).
- Use
aria-labelledbyif you need a more complex title relationship.
<figure>
<img src="https://images.unsplash.com/photo-1533154683836-84ea7a0bc310?auto=format&fit=crop&q=80&w=400" alt="Ancient stone castle on a hill">
<figcaption>Figure 1: Warwick Castle at sunset.</figcaption>
</figure>
Technical Deep Dive
Screen Reader Announcements
- NVDA: “Figure, Three mountain peaks covered in snow under a clear blue sky, Figure 1: The Eiger, Mönch, and Jungfrau peaks in the Swiss Alps.”
- VoiceOver: “Figure 1: The Eiger, Mönch, and Jungfrau peaks in the Swiss Alps., figure”
Best Practice: Alt vs Caption
The alt text should describe the visual content for users who can’t see the image. The figcaption should provide context, credit, or a title that is useful for all users.
Interactive Behavioral Lab
Interactive Sandbox
🔬 Technical Internals
Understand how this component is processed by the browser and Assistive Technology (AT). This section bridges the gap between visual code and the hidden logic that powers accessibility.
🌲 Accessibility Tree
The data structure used by screen readers to "see" your page. It translates HTML roles and attributes into standardized objects.
⚙️ Event Logic
Expected behavioral standards for keyboard navigation and state transitions. Crucial for users who don't use a mouse.
- Focus: Highlights via
:focus-visible - Activation: Responds to
EnterandSpace - Role: Identified as
Figure