This guide covers Global Role Attribute: Semantics and Native HTML Equivalents. The role attribute helps assistive technologies understand what an element represents. Native HTML usually supplies the correct role automatically.
Not every new browser feature is ready for every site. It helps to understand the problem first, then check whether the feature is mature enough before you depend on it.
How it is intended to work
The role attribute helps assistive technologies understand what an element represents. Native HTML usually supplies the correct role automatically.
Code example
<nav aria-label="Main navigation">
<a href="lessons.html">Lessons</a>
</nav>
<main>
<h1>Getting started</h1>
<button type="button">Show a tip</button>
</main>
What you should notice
Avoid role="button" on a noninteractive div just to make it sound like a button: you would also need keyboard activation and focus behavior. ARIA changes semantics, not functionality.
Read the exact attribute and value shown in the code. That is the feature being demonstrated; the surrounding document merely provides the context required for valid HTML. Where JavaScript or CSS is involved, the complete working effect may need more than the markup shown.
How to test compatibility
- Create a plain HTML page with working essential content.
- Add the experimental feature as an enhancement, not as the only way to reach important information.
- Test in the latest browsers relevant to your audience, including keyboard and mobile use.
- Turn the feature off or use an older browser to confirm the fallback remains useful.
Common Beginner Mistakes
- Avoid role="button" on a noninteractive div just to make it sound like a button: you would also need keyboard activation and focus behavior. ARIA changes semantics, not functionality.
- Assuming a feature supported in a technical preview works for every visitor.
- Removing native accessible behavior before the replacement is proven.
Key Takeaways
- The role attribute helps assistive technologies understand what an element represents. Native HTML usually supplies the correct role automatically.
- Avoid role="button" on a noninteractive div just to make it sound like a button: you would also need keyboard activation and focus behavior. ARIA changes semantics, not functionality.
- Keep a safe baseline and make new browser capabilities optional whenever possible.