Alt Text for Images
Images need alt text to be understood by screen reader users. Learn the difference between informative, decorative, and functional images.
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.">
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.")
<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." />
<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." />
<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."
class="w-full h-auto rounded-lg shadow-md border border-slate-200"
/>
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?
- Missing
alt: The browser may read the file path, which is useless. - 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="">
Functional Image (Inside a Link)
<!-- β
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 analtattribute. - 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.
<!-- 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
- Does the image convey information? β Add descriptive alt text.
- Is the image purely decorative? β Use
alt="". - Is there adjacent text that describes it? β Use
alt=""+aria-hidden="true".
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
Image Pattern