Add ARIA Labels to Custom Components
Learn how to use ARIA attributes to label custom components, buttons, and interactive elements. Includes code examples and best practices.
What Is It?
ARIA attributes add accessibility information to HTML elements. Key attributes: aria-label (labels element when no visible text), aria-labelledby (links element to labeling text), aria-describedby (provides description).
Affected users: Screen reader users, voice control users, users with visual disabilities, users with cognitive disabilities
Why It Matters
Screen reader users need to understand what each element does. Without ARIA labels, buttons with only icons (like a X close button) are announced as "button" with no context. ARIA bridges this gap.
How to Detect This Issue
Test with screen reader. Navigate to elements and check if names/descriptions are announced. Inspect element and look for aria attributes. Use automated accessibility checker.
Code Examples & Fixes
HTML / CSS
<button>×</button><button aria-label="Close dialog">×</button>The × symbol is not meaningful to screen readers. aria-label provides context. Alternatively: <button><span aria-hidden="true">×</span> Close</button>
React / Next.js
<button onClick={handleSearch}><SearchIcon /></button><button onClick={handleSearch} aria-label="Search articles"><SearchIcon /></button>Icon buttons need aria-label. Alternatively, include text: <button onClick={handleSearch}><SearchIcon /> <span>Search</span></button>
WordPress
<button class="toggle-menu">☰</button><button class="toggle-menu" aria-label="Toggle navigation menu" aria-expanded="false">☰</button>Menu toggle buttons should have aria-label and aria-expanded to show menu state. Update aria-expanded="true" when menu opens.
Shopify Liquid
<button class="cart-icon"><i class="icon-cart"></i></button><button class="cart-icon" aria-label="Shopping cart, 3 items"><i class="icon-cart"></i></button>Icon buttons in Shopify need aria-labels. For cart buttons, include item count in the label.
Common Mistakes
Using aria-label on elements that already have visible text (redundant)
aria-label text doesn't match visible text (confuses screen reader users)
Forgetting to update aria-expanded when toggles change state
Using aria-label when semantic HTML would be better (use <button> instead of <div>)
aria-hidden="true" used incorrectly, hiding content from screen readers when shouldn't
Frequently Asked Questions
Should I use aria-label or aria-labelledby?
Can I use aria-label with visible text?
What's the difference between aria-label and title?
How do I know if I need ARIA?
Check your website for free
Get your ADA, WCAG, privacy & security score in 90 seconds.