Alt Text for Images

Images need alt text to be understood by screen reader users. Learn the difference between informative, decorative, and functional images.

beginner
1.1.1 Non-text Content (Level A)
❌

The Bad (Inaccessible)

<img src="https://images.unsplash.com/photo-1557683316-973673baf926?auto=format&fit=crop&q=80&w=800" alt="hero banner">
βœ…

Accessibility-Ready Code

<img src="https://images.unsplash.com/photo-1460925895917-afdab827c52f?auto=format&fit=crop&q=80&w=800" alt="Bar chart showing a 40% increase in sales Q3.">

The Standard

The alt attribute provides a text alternative for images. Without it, screen readers either skip the image entirely or read the file nameβ€”often a jumbled mess like β€œIMG_2048.jpg”.

WCAG Criteria

  • 1.1.1 Non-text Content (Level A): All non-text content must have a text alternative that serves the equivalent purpose.

❌ The Bad (Inaccessible)

What’s Wrong?

  1. Missing alt: The browser may read the file path, which is useless.
  2. Lazy alt: β€œimage” tells the user nothing. What kind of image?

βœ… The Good (Accessibility-Ready Code)

<!-- βœ… Describe the content of the image -->
<img src="https://images.unsplash.com/photo-1460925895917-afdab827c52f?auto=format&fit=crop&q=80&w=800" alt="Bar chart showing a 40% increase in sales Q3.">

Why This Works

<!-- βœ… Describe the content of the image -->
<img src="https://images.unsplash.com/photo-1460925895917-afdab827c52f?auto=format&fit=crop&q=80&w=800" alt="Bar chart showing a 40% increase in sales Q3.">
<!-- βœ… An empty alt signals that the image is decorative -->
<img src="https://images.unsplash.com/photo-1502691876148-a84978f5d88b?auto=format&fit=crop&q=80&w=400" alt="">
<!-- βœ… The alt text describes the link destination, not the icon -->
<a href="/home">
  <svg aria-hidden="true" width="24" height="24" viewBox="0 0 24 24"><path fill="currentColor" d="M10,20V14H14V20H19V12H22L12,3L2,12H5V20H10Z" /></svg>
  <span class="sr-only">Go to homepage</span>
</a>

Informative Image (Content-Rich)

<!-- βœ… Describe the content of the image -->
<img src="https://images.unsplash.com/photo-1460925895917-afdab827c52f?auto=format&fit=crop&q=80&w=800" alt="Bar chart showing a 40% increase in sales Q3.">

Decorative Image (No Content)

<!-- βœ… An empty alt signals that the image is decorative -->
<img src="https://images.unsplash.com/photo-1502691876148-a84978f5d88b?auto=format&fit=crop&q=80&w=400" alt="">
<!-- βœ… The alt text describes the link destination, not the icon -->
<a href="/home" class="home-link">
  <svg aria-hidden="true" width="24" height="24" viewBox="0 0 24 24"><path fill="currentColor" d="M10,20V14H14V20H19V12H22L12,3L2,12H5V20H10Z" /></svg>
  <span class="sr-only">Go to homepage</span>
</a>

Accessibility Checklist

  • Every <img> tag must have an alt attribute.
  • Informative: Describe the image’s meaning or content.
  • Decorative: Use an empty alt="" to hide from screen readers.
  • Functional: Describe the action, not the icon (e.g., β€œSubmit form”, not β€œarrow icon”).
  • Keep alt text conciseβ€”ideally under 125 characters.
πŸ“ Perfect Implementation Reference
<!-- Informative image -->
<img src="https://images.unsplash.com/photo-1537151608828-ea2b11777ee8?auto=format&fit=crop&q=80&w=400" alt="A golden retriever playing in a park">

<!-- Decorative image -->
<img src="https://images.unsplash.com/photo-1579546929518-9e396f3cc809?auto=format&fit=crop&q=80&w=400" alt="">

Technical Deep Dive

The Accessibility Tree

With alt="" (correct):

Role: img (removed from tree)
Name: (none)

With meaningless alt (wrong):

Role: img
Name: "decorative swirl image"

Decision Flowchart

  1. Does the image convey information? β†’ Add descriptive alt text.
  2. Is the image purely decorative? β†’ Use alt="".
  3. Is there adjacent text that describes it? β†’ Use alt="" + aria-hidden="true".
πŸ§ͺ

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 Image Pattern

🌐 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