Element.role gets or sets the element’s explicit WAI-ARIA role — the value of the HTML role attribute (MDN). It does not return the element’s implicit role.
Read the notes below before you get or set this property. Prefer feature detection when support is limited.
Syntax
Use el.role. Start with this line.
JavaScript
element.role / = value
Call
What it does
element.role / = value
Primary signature.
Built into the browser. Read or assign el.role — no import required.
Library declarations
JavaScript
element.role / = value
Parameters
Parameter
Description
Clear
Optional. el.role = null / remove attribute
Return Value
Return Value
Description
*
String or null
JavaScript Examples
Example 1 — Read Explicit role
Unset elements return null; an attribute returns its string.
Assign the property. The role attribute appears on the element.
Read via getAttribute. Same string.
Change the attribute. The property updates too.
Keep them in sync — either API is fine for simple cases.
Compatibility
Browser Support
Element.role is Baseline Widely available (MDN: across browsers since October 2023). Safe in modern evergreen browsers.
✓ Baseline · Widely available
Element.role
Get or set the explicit WAI-ARIA role string — null when the role attribute is not set.
92%Widely available
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
roleExcellent
Bottom line: Safe for modern production. Prefer native HTML; use role when you must expose or override semantics.
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 yourself.
It returns null when the element does not have an explicit role attribute.
No. MDN marks Element.role as Baseline Widely available (across browsers since October 2023). It is not Deprecated, Experimental, or Non-standard.
Yes. Assign a string such as el.role = "button" or el.role = "presentation" to update the role attribute.
No. Prefer native HTML semantics. Use an explicit role only when you have a clear accessibility reason.