Element: role property
Baseline 2023Newly available
Since October 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
Therole property of theElement interface returns the explicitly setWAI-ARIA role for the element.
All HTML elements have an implicit ARIA role, even if that role isgeneric. This semantic association allows tools to present and support interaction with the object in a manner that is consistent with user expectations about other objects of that type. Therole attribute is used to explicitly set the element's ARIA role, overriding the implicit role. For example, a<ul>, which has an implicitlist role, might haverole="treegrid" explicitly set. Therole property reflects the explicitly set value of therole attribute—in this casetreegrid; it does not return the element's implicitlist role unless explicitly set.
The full list of defined ARIA roles can be found on theARIA roles reference page.
In this article
Value
A string; the value of therole attribute ornull if not explicitly set.
Examples
In this example, images with empty or missingalt attributes are given arole ofpresentation:
const images = document.querySelectorAll("img");images.forEach((image) => { if (!image.alt) { image.role = "presentation"; }});Specifications
| Specification |
|---|
| Accessible Rich Internet Applications (WAI-ARIA)> # dom-ariamixin-role> |