Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. Element
  4. role

Element: role property

Baseline 2023
Newly 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.

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:

js
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

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2026 Movatter.jp