Icon-Only Button

When a button has no visible text, an aria-label is mandatory. Learn how to make icon-buttons accessible.

beginner
1.1.1 Non-text Content (Level A)4.1.2 Name, Role, Value (Level A)
❌

The Bad (Inaccessible)

<button class="icon-button-bad">
  <svg aria-hidden="true" viewBox="0 0 24 24" width="24" height="24"><path fill="currentColor" d="M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z" /></svg>
</button>
βœ…

Accessibility-Ready Code

<button aria-label="Close dialog" class="accessible-icon-button">
  <svg aria-hidden="true" focusable="false" viewBox="0 0 24 24" width="24" height="24">
    <path fill="currentColor" d="M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z" />
  </svg>
</button>

The Standard

An icon-only button (like a close β€œX” or a hamburger menu icon) has no visible text. This means screen readers have nothing to announceβ€”unless you provide an accessible name.

WCAG Criteria

  • 1.1.1 Non-text Content (Level A): All non-text content must have a text alternative.
  • 4.1.2 Name, Role, Value (Level A): The button’s name must be programmatically determinable.

❌ The Bad (Inaccessible)

What’s Wrong?

  1. No Accessible Name: The button has no text, so the screen reader can only say β€œbutton.”
  2. User Confusion: Users cannot distinguish this button from any other unnamed button.

βœ… The Good (Accessibility-Ready Code)

Why This Works

  1. Clear Name: Screen readers announce: β€œClose dialog, button.”
  2. Icon Hidden: aria-hidden="true" on the SVG prevents double-announcements.
  3. Focus Safe: focusable="false" on the SVG prevents a broken focus trap in old IE/Edge.

Accessibility Checklist

  • Add aria-label describing the action (e.g., β€œOpen menu”, β€œClose”).
  • Add aria-hidden="true" to the icon/SVG itself.
  • Ensure a visible :focus-visible ring is present.
  • Consider adding a title tooltip for sighted users (optional).
πŸ“ Perfect Implementation Reference
<button aria-label="Send message">
  <svg aria-hidden="true">...</svg>
</button>

Technical Deep Dive

The Accessibility Tree

Role: button
Name: "Close dialog"
State: focusable
πŸ§ͺ

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 Button 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