Icon-Only Button
When a button has no visible text, an aria-label is mandatory. Learn how to make icon-buttons accessible.
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>
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")
<button aria-label="Close dialog">
<svg aria-hidden="true" focusable="false">...</svg>
</button>
<button aria-label="Close dialog">
<svg aria-hidden="true" focusable="false">...</svg>
</button>
<button
aria-label="Close dialog"
class="p-2 bg-indigo-50 text-indigo-600 rounded-full hover:bg-indigo-100 transition-colors focus:ring-2 focus:ring-indigo-600 focus:outline-none"
>
<svg aria-hidden="true" focusable="false" class="w-6 h-6" fill="currentColor" viewBox="0 0 24 24">
<path 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?
- No Accessible Name: The button has no text, so the screen reader can only say βbutton.β
- User Confusion: Users cannot distinguish this button from any other unnamed button.
β The Good (Accessibility-Ready Code)
Why This Works
- Clear Name: Screen readers announce: βClose dialog, button.β
- Icon Hidden:
aria-hidden="true"on the SVG prevents double-announcements. - Focus Safe:
focusable="false"on the SVG prevents a broken focus trap in old IE/Edge.
Accessibility Checklist
- Add
aria-labeldescribing the action (e.g., βOpen menuβ, βCloseβ). - Add
aria-hidden="true"to the icon/SVG itself. - Ensure a visible
:focus-visiblering is present. - Consider adding a
titletooltip for sighted users (optional).
<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
π¬ 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
Button Pattern