Element.role is an instance property that reflects the explicit ARIA role attribute on an element. Learn what it returns, how it differs from implicit roles, when it gives null, and how to update it safely with five examples and try-it labs.
01
Kind
Instance property
02
Access
Read and set
03
Type
string or null
04
Reflects
HTML role attribute
05
Status
Baseline widely
06
Focus
Accessibility semantics
Fundamentals
Introduction
HTML elements already come with built-in meaning. For example, a native <button> is announced like a button by assistive technologies. That built-in meaning is called an implicit role.
The role attribute lets you set an explicit ARIA role when needed, and Element.role is the JavaScript property that reflects that attribute.
element.role only tells you the explicitly set value. It does not calculate or return the element’s implicit role for you.
Concept
Understanding the Property
MDN: the role property of the Element interface returns the explicitly set WAI-ARIA role for the element.
Reflects the attribute — it matches the HTML role attribute.
String or null — returns a role name, or null if not explicitly set.
Explicit only — does not expose implicit semantics unless you assign them yourself.
Accessibility-focused — mainly used when inspecting or updating ARIA semantics.
Foundation
📝 Syntax
JavaScript
element.role
element.role = "button"
Value
A string containing the explicit role value, or null when no role attribute is present.
Item
Detail
Type
string or null
Access
Readable and writable
Reflects
HTML role attribute
Important note
Does not return implicit roles
⚠️
Use roles carefully
Adding the wrong ARIA role can confuse screen readers. Prefer native HTML elements first, and use explicit roles only when they truly improve semantics.
Pattern
📋 MDN Accessibility Example Shape
MDN demonstrates setting a presentational role on images that have no alternate text:
Element.role is Baseline Widely available (MDN: across browsers since October 2023). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline Widely available
Element.role
Reflects the explicit ARIA role attribute as a string or null.
BaselineWidely available
Google ChromeSupported
Yes
Microsoft EdgeSupported
Yes
Mozilla FirefoxSupported
Yes
Apple SafariSupported
Yes
OperaSupported
Yes
Internet ExplorerNot supported
No
roleBaseline
Bottom line: Use Element.role to inspect or update explicit ARIA semantics. Remember that implicit native roles are not returned unless you set the role attribute yourself.
Wrap Up
Conclusion
Element.role is a simple but important accessibility property. It reflects the explicit role attribute, returns a string or null, and helps you inspect or update ARIA semantics from JavaScript.
Use element.role to inspect explicit accessibility semantics
Check for null when no role attribute is present
Keep property and attribute reflection in mind while debugging
Use ARIA roles only when they improve the experience
❌ Don’t
Assume element.role returns the implicit native role
Add explicit roles to every element without a reason
Override strong native semantics carelessly
Use ARIA as a replacement for proper HTML structure
Forget to test accessibility changes with real assistive tooling
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about role
Reflects explicit ARIA semantics only, not the implicit native role.
5
Core concepts
📄01
Reflects
role attribute
Kind
📝02
string|null
explicit value
Type
🔍03
No implicit role
returned automatically
Rule
✅04
Baseline
widely available
Status
🎯05
Use carefully
for accessibility
Tip
❓ Frequently Asked Questions
It gets or sets the explicitly assigned WAI-ARIA role for an element by reflecting the HTML role attribute.
No. It returns only the explicitly set role attribute value. If an element has only an implicit role, element.role is null unless you set a role attribute yourself.
It returns null when the element does not have an explicit role attribute.
No. MDN marks Element.role as Baseline Widely available, available across browsers since October 2023.
Yes. You can assign a string such as element.role = "button" or element.role = "presentation" to update the role attribute.
No. Use explicit roles only when needed. Native HTML semantics are usually better, so avoid overriding them unless you have a clear accessibility reason.
Did you know?
A plain <button> already behaves like a button for assistive technologies, but button.role still returns null unless you explicitly set a role attribute.