Frontend System Design3 min readPremium

Empowering Web Accessibility with ARIA: Roles and Attributes Explained

ARIA roles are used to provide additional information to assistive technologies (such as screen readers) about the purpose and behavior of elements on a web page. This helps users with disabilities, particularly those who may not be able to interact with a page using a traditional mouse or visual interface. MDN keeps a full list of WAI-ARIA roles.

role=”button”

  • Purpose: Indicates that an element functions as a button.
  • Accessibility Benefit: Screen readers will announce the element as a button, allowing users to understand that it’s interactive and can be activated.
  • Purpose: Indicates that an element functions as a hyperlink.
  • Accessibility Benefit: Screen readers will announce the element as a link, letting users know that it leads to another page or resource.

role=”heading”:

  • Purpose: Specifies the heading level of an element.
  • Accessibility Benefit: Screen readers use headings to create a hierarchical structure for the content, aiding users in understanding the organization and flow of the page.

role=”navigation”:

  • Purpose: Denotes a navigation region within a page.
  • Accessibility Benefit: Screen readers can identify navigation sections, helping users quickly locate menus or links to different parts of the website.

role=”checkbox”:

  • Purpose: Represents a checkbox input.
  • Accessibility Benefit: Screen readers will recognize the element as a checkbox, allowing users to interact with it and understand its state (checked or unchecked).

role=”menu” and role=”menuitem”:

  • Purpose: Defines a menu and its individual items.
  • Accessibility Benefit: Screen readers will identify menus and their items, making it easier for users to navigate and select options.

role=”alert”:

  • Purpose: Indicates that an element contains important and time-sensitive information.
  • Accessibility Benefit: Screen readers will announce alerts, ensuring that users are immediately aware of critical messages or notifications.

How ARIA Attributes Enhance Accessibility:

  • aria-label and aria-labelledby: Provide an accessible name for an element, ensuring that assistive technologies can convey the purpose or label of the element to the user.
  • aria-describedby: Points to additional information that describes the element, giving users more context or instructions.
  • aria-hidden: Determines whether an element should be hidden from assistive technologies, allowing developers to manage what is presented to users with disabilities.
  • aria-disabled: Indicates that an element is not interactive and cannot be activated, ensuring that users understand when an element is not usable.
  • aria-haspopup and aria-expanded: Indicate the presence of a popup menu and its current state (open or closed), providing users with information about interactive elements.
  • aria-live: Specifies that an element will be automatically updated with live information, making dynamic content accessible to users.
  • aria-pressed: Indicates the current state of a toggle button (e.g., pressed or not pressed), helping users understand the current setting.

ARIA Roles:

  1. role="button":
    • Indicates that an element functions as a button.
    <div role="button" tabindex="0">Click me</div>
  2. role="link":
    • Indicates that an element functions as a hyperlink.
    <div role="link" tabindex="0">Visit our homepage</div>
  3. role="heading":
    • Specifies the heading level of an element.
    <div role="heading" aria-level="2">Subheading</div>
  4. role="navigation":
    • Denotes a navigation region within a page.
    <nav role="navigation"> <ul> <li><a href="#">Home</a></li> <li><a href="#">About</a></li> <li><a href="#">Contact</a></li> </ul> </nav>
  5. role="checkbox":
    • Represents a checkbox input.
    <div role="checkbox" aria-checked="true" tabindex="0">Checked</div>
  6. role="menu" and role="menuitem":
    • Defines a menu and its individual items.
    <div role="menu"> <div role="menuitem" tabindex="0">Option 1</div> <div role="menuitem" tabindex="0">Option 2</div> </div>
  7. role="alert":
    • Indicates that an element contains important and time-sensitive information.
    <div role="alert">Error: Please enter a valid email address</div>

ARIA Attributes:

  1. aria-label and aria-labelledby:
    • Provides an accessible name for an element.
    <button aria-label="Close">X</button>
    <div id="section-heading">Section Title</div>
    <section aria-labelledby="section-heading">
      <!-- Section content -->
    </section>
  2. aria-describedby:
    • Points to additional information that describes the element.
    <input type="text" aria-describedby="help-text">
    <div id="help-text">Please enter your username</div>
  3. aria-hidden:
    • Indicates whether an element should be hidden from assistive technologies.
    <div aria-hidden="true">Hidden content</div>
  4. aria-disabled:
    • Indicates that an element is not interactive and cannot be activated.
    <button aria-disabled="true">Disabled Button</button>
  5. aria-haspopup and aria-expanded:
    • Indicates that an element has a popup menu and whether it is expanded.
    <button aria-haspopup="true" aria-expanded="false">Show Menu</button>
  6. aria-live:
    • Specifies that an element will be automatically updated
      with live information.
    <div aria-live="polite">New message received</div>
  7. aria-pressed:
    • Indicates the current state of a toggle button (e.g., pressed or not pressed).
    <button aria-pressed="false">Toggle</button>

These are just a few examples of how ARIA roles and attributes can be used to enhance the accessibility of web content. It’s important to choose the appropriate roles and attributes based on the functionality and purpose of your elements. Always refer to the ARIA specification and consider testing with assistive technologies to ensure your content is properly accessible.