ARIA Label Role Conflict Fix
In this tutorial, you'll learn about ARIA Label Role Conflict Fix. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.
The Problem
ARIA attributes that conflict with each other or with native HTML semantics cause screen readers to present confusing or incorrect information. Common conflicts include aria-label on elements with existing visible labels, incorrect role assignments, and missing aria-labelledby references.
Quick Fix
Step 1: Do not override native semantics unnecessarily
<!-- Wrong — adding role to a native button -->
<button role="button">Submit</button>
<!-- Wrong — adding role to a native link -->
<a href="/page" role="link">Page</a>
<!-- Right — use native elements, no role needed -->
<button>Submit</button>
<a href="/page">Page</a>
Step 2: Use aria-label only when no visible label exists
<!-- Wrong — aria-label on element with visible text -->
<button aria-label="Submit the form">Submit</button>
<!-- Screen reader announces "Submit the form" instead of "Submit" -->
<!-- Right — use aria-label when there is no visible text -->
<button aria-label="Close dialog">
<span aria-hidden="true">×</span>
</button>
Step 3: Fix aria-labelledby references
<!-- Wrong — id does not exist -->
<div role="region" aria-labelledby="section-title">
<h2>Latest News</h2>
<p>Content here...</p>
</div>
<!-- Right — reference a real id -->
<h2 id="news-title">Latest News</h2>
<div role="region" aria-labelledby="news-title">
<p>Content here...</p>
</div>
Step 4: Do not use aria-label on divs and spans
<!-- Wrong — div with aria-label but no role -->
<div aria-label="Menu">
<a href="/home">Home</a>
<a href="/about">About</a>
</div>
<!-- Right — add a role for the label to be meaningful -->
<nav aria-label="Main navigation">
<a href="/home">Home</a>
<a href="/about">About</a>
</nav>
Step 5: Avoid aria-hidden conflicts
<!-- Wrong — focusable element with aria-hidden -->
<button aria-hidden="true">Close</button>
<!-- Screen reader ignores it, but keyboard users can still tab to it -->
<!-- Right — use display:none or visibility:hidden instead -->
<button style="display: none">Close</button>
<!-- Or add tabindex="-1" if it must be in DOM -->
<button aria-hidden="true" tabindex="-1">Close</button>
Prevention
- Use native HTML elements before ARIA roles
- Only add
aria-labelto elements without visible text - Ensure
aria-labelledbypoints to an existing element id - Add a valid
roleto elements that usearia-label - Never put
aria-hidden="true"on focusable elements
Common Mistakes with aria label
- Using
returnto exit a function early instead of wrapping a pure value in the monad - Mixing let bindings with <- bindings in do notation, producing type errors
- Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors
These mistakes appear frequently in real-world A11Y code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro