[role]

Term side of the Card.
Topic: Global Attributes
Unit title: [role]
Categories: Attribute
Explanation side of the Card

Explanation: The attribute that defines the role of an element within web accessibility APIs. It helps assistive technologies, like screen readers, understand how the element should be interpreted or interacted with.

Browser compatibility:
  • The chrome browser supports this feature starting from version 103.
  • The edge browser supports this feature starting from version 103.
  • The firefox browser supports this feature starting from version 119.
  • The safari browser supports this feature starting from version 16.4.
Availability: 

Example

Wronghtml
<div role="button" onclick="send()">
  Send
</div>
Righthtml
<button type="button" onclick="send()">
  Send
</button>

A role only changes what assistive tech hears. The native button also brings focus and keyboard support.

Common mistakes

  • Adding role='button' to a <div> without tabindex and key handling.
  • Writing redundant roles like <nav role='navigation'>.

Key points

  • A native element is used when one exists, like <button> instead of role='button'.
  • Elements with interactive roles are focusable and handle the keys that role requires.
  • The role value is a real ARIA role and does not repeat the element's own role.

Interview questions

Does role add behavior to an element?

No. It changes only the semantics for assistive tech. Focus, keys and states must be added by you.

Can I use more than one role?

Yes. You can list roles separated by spaces, and the first supported one is used as a fallback chain.

Is role='presentation' the same as aria-hidden?

No. 'presentation' removes the element's semantics but keeps its content. aria-hidden hides the whole subtree.

Analytics cookiesWe'd like to use analytics cookies to see which pages are useful. They're set only if you accept. Privacy Policy