e01.org

Element: role property

DOM

DOM

The **`role`** property of the Element interface returns the explicitly set [WAI-ARIA role](/docs/Web/Accessibility/ARIA/Reference/Roles) for the element.

All HTML elements have an implicit ARIA role, even if that role is [`generic`](/docs/Web/Accessibility/ARIA/Reference/Roles/generic_role). 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. The `role` attribute is used to explicitly set the element's ARIA role, overriding the implicit role. For example, a ul, which has an implicit [`list`](/docs/Web/Accessibility/ARIA/Reference/Roles/list_role) role, might have [`role="treegrid"`](/docs/Web/Accessibility/ARIA/Reference/Roles/treegrid_role) explicitly set. The `role` property reflects the explicitly set value of the `role` attribute—in this case `treegrid`; it does not return the element's implicit `list` role unless explicitly set.

The full list of defined ARIA roles can be found on the [ARIA roles](/docs/Web/Accessibility/ARIA/Reference/Roles) reference page.

## Value

A string; the value of the `role` attribute or `null` if not explicitly set.

## Examples

In this example, images with empty or missing `alt` attributes are given a `role` of [`presentation`](/docs/Web/Accessibility/ARIA/Reference/Roles/presentation_role):

```js
const images = document.querySelectorAll("img");
images.forEach((image) => {
if (!image.alt) {
image.role = "presentation";
}
});
```

## Specifications

## Browser compatibility

## See also

- ElementInternals.role
- [ARIA attributes](/docs/Web/Accessibility/ARIA/Reference/Attributes)

source: MDN Web Docs mirror · page

Cite this

"Element: role property". MDN Web Docs. CC BY-SA 2.5 (MDN). https://developer.mozilla.org/en-US/docs/Web/API/Element/role

JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy

Save to pass ·