ARIA (Accessible Rich Internet Applications) roles are attributes added to HTML elements to improve accessibility, particularly for users relying on assistive technologies like screen readers. These roles help define the structure and function of web elements beyond what’s provided by standard HTML elements. For example, they can describe dynamic or interactive components, such as widgets or menus, that otherwise wouldn’t be recognized properly by assistive technologies.

Common ARIA Roles and Their Functions:

  1. Landmark Roles (used to define sections of a webpage):
    • role="banner": Identifies site-wide content, such as the header.
    • role="navigation": Identifies a navigation section of a page.
    • role="main": Identifies the main content of a document.
    • role="complementary": Marks complementary content that’s related to the main content but could stand alone.
    • role="contentinfo": Identifies the footer or other site information.
  2. Widget Roles (used for interactive elements):
    • role="button": Indicates an element that functions like a button.
    • role="checkbox": Identifies a checkbox element.
    • role="dialog": Defines a dialog box.
    • role="alert": Identifies a non-modal alert message.
    • role="slider": Identifies a slider control, such as a volume control.
  3. Document Structure Roles:
    • role="heading": Specifies the hierarchical structure for headings (similar to <h1>, <h2>, etc.).
    • role="list": Identifies a list of items.
    • role="listitem": Identifies an item within a list.
  4. Live Region Roles (for dynamic content):
    • role="alert": Used for important messages that need immediate attention.
    • role="status": Used for status messages that inform users of changes to the interface (e.g., saving progress).

How Many ARIA Roles Should Be Used?

There is no specific number of ARIA roles that a page must have. The use of ARIA roles depends on the complexity and structure of the webpage:

Best Practices for ARIA Usage:

  1. Only use ARIA when necessary: If native HTML elements provide the necessary semantics (e.g., <button>, <header>, <nav>), prefer them over adding ARIA roles like role="button" or role="navigation". Native elements have built-in accessibility features.
  2. Use ARIA roles to enhance non-semantic elements: If you’re using non-semantic elements (e.g., <div> or <span>), ARIA roles can be used to provide context to assistive technologies (e.g., role="navigation" for a <div> used as a navigation bar).
  3. Avoid overusing ARIA roles: Don’t add ARIA roles unless necessary. Incorrect or redundant use can confuse assistive technology.
  4. Ensure ARIA roles are supported: Test your website with different screen readers (such as NVDA, JAWS) and browsers to ensure that ARIA roles are interpreted correctly.

Common Example of ARIA Usage:

html code<nav role="navigation">
  <ul>
    <li><a href="#home">Home</a></li>
    <li><a href="#services">Services</a></li>
    <li><a href="#contact">Contact</a></li>
  </ul>
</nav>

<button role="button" aria-pressed="false">Toggle Menu</button>


In this example:

Conclusion: