Figure with Caption

Proper use of semantic figure and figcaption elements for images and illustrations.

beginner
1.1.1 Non-text Content (Level A)1.3.1 Info and Relationships (Level A)

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>

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?

  1. Broken Relationship: Screen readers treat the image and the text as two unrelated elements.
  2. Generic Container: Using a div provides no semantic context about the grouping.

✅ The Good (Accessibility-Ready Code)

Why This Works

  1. Semantic Grouping: The <figure> element creates a logical container that groups the content and its label.
  2. Implicit Labeling: Browser accessibility APIs automatically use the content of <figcaption> as the accessible name for the <figure>.
  3. 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 descriptive alt attribute even if the caption is detailed.
  • Avoid redundant text (e.g., “Image of a mountain” in alt and “A mountain” in caption).
  • Use aria-labelledby if you need a more complex title relationship.
📍 Perfect Implementation Reference
<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

LIVE PREVIEW

🔬 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 Enter and Space
  • Role: Identified as Figure

🌐 Browser & Screen Reader Compatibility

Browser
Screen Reader
Status
🍎 Safari
VoiceOver
✓ Safe
🪟 Chrome
NVDA
✓ Safe
🪟 Edge
JAWS
✓ Safe
🦊 Firefox
NVDA
✓ Safe
📱 iOS Safari
VoiceOver
✓ Safe
🤖 Chrome Android
TalkBack
✓ Safe