Decorative Images
Learn when and how to hide decorative images from assistive technology using empty alt or aria-hidden.
The Bad (Inaccessible)
<!-- Decorative image with meaningless alt -->
<img src="https://images.unsplash.com/photo-1579546929518-9e396f3cc809?auto=format&fit=crop&q=80&w=400" alt="decorative swirl image">
<!-- Icon with redundant description -->
<button>
<svg class="icon" viewBox="0 0 24 24" width="20" height="20"><path fill="currentColor" d="M9.5,3A6.5,6.5 0 0,1 16,9.5C16,11.11 15.41,12.59 14.44,13.73L14.71,14H15.5L20.5,19L19,20.5L14,15.5V14.71L13.73,14.44C12.59,15.41 11.11,16 9.5,16A6.5,6.5 0 0,1 3,9.5A6.5,6.5 0 0,1 9.5,3M9.5,5C7,5 5,7 5,9.5C5,12 7,14 9.5,14C12,14 14,12 14,9.5C14,7 12,5 9.5,5Z" /></svg>
Search
</button>
Accessibility-Ready Code
<!-- Decorative image: empty alt hides from AT -->
<img src="https://images.unsplash.com/photo-1579546929518-9e396f3cc809?auto=format&fit=crop&q=80&w=400" alt="">
<!-- Icon next to text: hide the icon -->
<button class="accessible-button">
<svg aria-hidden="true" class="icon" viewBox="0 0 24 24" width="20" height="20">
<path fill="currentColor" d="M9.5,3A6.5,6.5 0 0,1 16,9.5C16,11.11 15.41,12.59 14.44,13.73L14.71,14H15.5L20.5,19L19,20.5L14,15.5V14.71L13.73,14.44C12.59,15.41 11.11,16 9.5,16A6.5,6.5 0 0,1 3,9.5A6.5,6.5 0 0,1 9.5,3M9.5,5C7,5 5,7 5,9.5C5,12 7,14 9.5,14C12,14 14,12 14,9.5C14,7 12,5 9.5,5Z" />
</svg>
Search
</button>
// Decorative image: empty alt hides from AT
img(src="https://images.unsplash.com/photo-1579546929518-9e396f3cc809?auto=format&fit=crop&q=80&w=400" alt="")
// Icon next to text: hide the icon
button.accessible-button
svg(aria-hidden="true" class="icon" viewBox="0 0 24 24" width="20" height="20")
path(fill="currentColor" d="M9.5,3A6.5,6.5 0 0,1 16,9.5C16,11.11 15.41,12.59 14.44,13.73L14.71,14H15.5L20.5,19L19,20.5L14,15.5V14.71L13.73,14.44C12.59,15.41 11.11,16 9.5,16A6.5,6.5 0 0,1 3,9.5A6.5,6.5 0 0,1 9.5,3M9.5,5C7,5 5,7 5,9.5C5,12 7,14 9.5,14C12,14 14,12 14,9.5C14,7 12,5 9.5,5Z")
| Search
{/* Decorative image: empty alt hides from AT */}
<img src="https://images.unsplash.com/photo-1579547621113-e4bb2a19bdd6?auto=format&fit=crop&q=80&w=400" alt="" />
{/* Icon next to text: hide the icon */}
<button>
<img src="https://images.unsplash.com/photo-1557683316-973673baf926?auto=format&fit=crop&q=80&w=400" alt="" aria-hidden="true" />
Search
</button>
<!-- Decorative image: empty alt hides from AT -->
<img src="https://images.unsplash.com/photo-1579547621113-e4bb2a19bdd6?auto=format&fit=crop&q=80&w=400" alt="">
<!-- Icon next to text: hide the icon -->
<button>
<img src="https://images.unsplash.com/photo-1557683316-973673baf926?auto=format&fit=crop&q=80&w=400" alt="" aria-hidden="true">
Search
</button>
<!-- Decorative image: empty alt hides from AT -->
<img
src="https://images.unsplash.com/photo-1579546929518-9e396f3cc809?auto=format&fit=crop&q=80&w=400"
alt=""
class="max-w-[200px] opacity-30"
>
<!-- Icon next to text: hide the icon -->
<button class="flex items-center gap-2 px-4 py-2 bg-indigo-600 text-white rounded-lg">
<svg aria-hidden="true" class="w-5 h-5" fill="currentColor" viewBox="0 0 24 24">
<path d="M9.5,3A6.5,6.5 0 0,1 16,9.5C16,11.11 15.41,12.59 14.44,13.73L14.71,14H15.5L20.5,19L19,20.5L14,15.5V14.71L13.73,14.44C12.59,15.41 11.11,16 9.5,16A6.5,6.5 0 0,1 3,9.5A6.5,6.5 0 0,1 9.5,3M9.5,5C7,5 5,7 5,9.5C5,12 7,14 9.5,14C12,14 14,12 14,9.5C14,7 12,5 9.5,5Z" />
</svg>
Search
</button>
The Standard
Not all images need to be announced by screen readers. Decorative images (backgrounds, flourishes, icons with text labels) should be hidden from the accessibility tree to reduce noise.
WCAG Criteria
- 1.1.1 Non-text Content (Level A): Decorative images must be implemented so AT can ignore them.
- 1.4.5 Images of Text (Level AA): Decorative text images should be pure CSS when possible.
β The Bad (Inaccessible)
Whatβs Wrong?
- Meaningless Alt Text: βdecorative swirl imageβ adds zero value for a blind user.
- Redundant Icon Description: If the button says βSearchβ, announcing βmagnifying glass icon, Searchβ is noise.
- Cognitive Overload: Every unnecessary announcement slows down screen reader users.
β The Good (Accessibility-Ready Code)
Why This Works
- Empty Alt (
alt=""): Tells screen readers to skip the image entirely. aria-hidden="true": Explicitly removes the element from the accessibility tree.- Text Label Preserved: The buttonβs βSearchβ text provides full context.
Accessibility Checklist
- Use
alt=""for purely decorative images (swirls, backgrounds). - Add
aria-hidden="true"to icons that appear next to descriptive text. - Prefer CSS for decorative backgrounds over
<img>tags. - Never use placeholder alt like βimageβ or βiconβ for decorative content.
- Test with a screen reader to confirm the image is NOT announced.
<!-- Background Pattern -->
<img src="https://images.unsplash.com/photo-1618005182384-a83a8bd57fbe?auto=format&fit=crop&q=80&w=400" alt="" aria-hidden="true">
<!-- Redundant Icon -->
<button>
<svg aria-hidden="true">...</svg>
Submit
</button>
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