Home  Automation-testing-blog   Accessibili ...

Accessibility (ARIA) attributes examples in html

Accessibility (ARIA) attributes are crucial for making dynamic web content and custom UI components accessible to people who use assistive technologies like screen readers. They provide extra semantic meaning where native HTML falls short.

Here are essential ARIA attribute categories and examples of their practical use in HTML:


1. Roles (The "What Is It?")

ARIA roles define what a custom element is or does.

ARIA RoleHTML Equivalent (If any)Example Use Case
role="button"<button>Used on a <div> or <span> that you've styled to look and act like a button.
role="alert"NoneUsed on a message area that appears dynamically and must immediately interrupt the user (e.g., a form error).
role="dialog"NoneUsed on the container for a modal window.
role="navigation"<nav>Used on a <div> containing primary navigation links.

Role Example: Custom Button

<div role="button" tabindex="0" aria-pressed="false">
    Toggle Settings
</div>

2. Properties (The "How Is It?")

ARIA properties describe the characteristics or state of an element that is unlikely to change often.

ARIA PropertyDescriptionExample Use
aria-labelProvides a visible label for an element when no visible text is present (e.g., for an icon button).For a search icon button.
aria-describedbyPoints to another element that contains a description or error message for the current element.For associating a form input with its hint text.
aria-labelledbyPoints to another element that acts as the label for the current element (used when a label is complex).For associating a custom radio group with a title.
aria-hidden="true"Hides the element from assistive technology entirely.For decorative icons or duplicated text.

Property Example: Icon Button

<button aria-label="Delete Item">
    <img src="delete-icon.svg" alt="" />
</button>

3. States (The "What's Happening Now?")

ARIA states describe the current, dynamic conditions of an element, and they change via JavaScript.

ARIA StateValuesExample Use
aria-expandedtrue / falseUsed on a button that controls the visibility of a collapsible region (e.g., an accordion header).
aria-disabledtrue / falseUsed when an element is visually disabled but not necessarily a native HTML disabled element.
aria-currentpage, step, trueUsed on a link to indicate the user's current location in a set of pages or steps.
aria-livepolite / assertiveUsed on a region that updates dynamically without a page refresh (see below).

State Example: Accordion

<button aria-controls="panel1" aria-expanded="false" onclick="toggleAccordion()">
    Section Title
</button>
<div id="panel1" role="region" aria-hidden="true">
    </div>

4. Live Regions (Dynamic Updates) 💬

The aria-live attribute is vital for parts of the page that update asynchronously (e.g., search results, status messages, validation errors).

Live Region Example: Status Message

<div aria-live="polite" role="status">
    </div>
Published on: Oct 06, 2025, 11:18 PM  
 

Comments

Add your comment