Skip to content
Tutorials Center
My learning

Topics

Lesson 106 of 122 ยท Accessibility and Best Practices

ARIA Roles, States and Properties

Learn when ARIA helps and when it hurts. Use roles, accessible names, descriptions, aria-expanded and live regions correctly, following the first rule of ARIA.

In the previous lesson you saw that assistive technology reads a page through the accessibility tree, where every element has a role, a name and a state. Native HTML fills in that information for you. But sometimes you build something HTML has no element for, such as a panel that expands, a tab set or a message that appears after an action. For those gaps there is WAI-ARIA, usually just called ARIA (Accessible Rich Internet Applications).

ARIA is a set of attributes that let you describe an element's role, name and state directly. It is powerful, and it is also one of the easiest ways to make a page less accessible. This lesson shows you how to use it with care.

What ARIA does, and what it does not

ARIA attributes change only the accessibility tree. They do not change how an element looks or behaves. Adding role="button" to a <div> makes a screen reader announce "button", but the div still:

  • cannot be reached with Tab;
  • does not react to Enter or Space;
  • has no disabled state, no form behavior and no default focus style.

In other words, ARIA is a promise to assistive technology. If you write role="button", you are now responsible for making the element behave exactly like a button. That is why the most important rule comes first.

The first rule of ARIA

The W3C's guidance on using ARIA in HTML starts with this rule, paraphrased: if a native HTML element or attribute already gives you the meaning and behavior you need, use it instead of adding ARIA.

HTML
<!-- Avoid: rebuilding a button by hand -->
<div role="button" tabindex="0">Delete</div>

<!-- Prefer: it already is a button -->
<button type="button">Delete</button>

A few related rules are worth memorizing:

  • Do not change native semantics unless you really must. <h2 role="tab"> turns a heading into something that is no longer a heading.
  • Every interactive ARIA control must be usable with a keyboard.
  • Never hide focusable elements with aria-hidden="true" or role="presentation". A keyboard user would land on something that, for a screen reader, does not exist.
  • Interactive elements need an accessible name.

The ARIA Authoring Practices Guide puts it bluntly: a page with no ARIA is often better than a page with incorrect ARIA.

Roles

A role tells assistive technology what kind of thing an element is. Most HTML elements already have an implicit role:

HTML Implicit role
<button> button
<a href="..."> link
<nav> navigation
<main> main
<ul>, <ol> list
<input type="checkbox"> checkbox
<h1>โ€“<h6> heading (with a level)

Writing <nav role="navigation"> is therefore redundant. It does no harm, but it adds noise; validators flag it as unnecessary.

You add an explicit role when no element matches. Common examples are composite widgets such as tablist/tab/tabpanel, or role="status" and role="alert" for messages, which you will meet below. Roles fall into a few families:

  • Landmark roles such as banner, navigation, main, complementary, contentinfo, search and region. Prefer their HTML elements.
  • Widget roles such as button, checkbox, tab, slider, switch and menuitem.
  • Document structure roles such as list, heading, img and table.
  • Live region roles such as status, alert and log.

role="menu" is not for site navigation. It describes an application-style menu (like a desktop app's File menu) with arrow-key behavior. A list of links in <nav> is the right pattern for website menus.

Accessible names

Every interactive element needs a name, the text a screen reader announces for it. Usually it comes from HTML: a button's text, a link's text, an image's alt, a form field's <label>. When that is not enough, ARIA offers two attributes.

aria-label

aria-label sets a name directly as a string. It is handy for icon-only buttons:

HTML
<button type="button" aria-label="Close">
  <svg aria-hidden="true" width="16" height="16"><!-- an X icon --></svg>
</button>

The SVG is hidden from the tree with aria-hidden="true", and the button gets a clear name. Two cautions: aria-label is invisible to sighted users, and automatic translation tools often skip it. Visible text is usually better.

aria-labelledby

aria-labelledby points at the id of one or more other elements and uses their text as the name. It is ideal when the label is already visible on the page:

HTML
<section aria-labelledby="billing-heading">
  <h2 id="billing-heading">Billing address</h2>
  ...
</section>

Now the section is exposed as a region landmark called "Billing address". You can list several ids, separated by spaces, and the texts are joined in that order.

When several sources compete, aria-labelledby wins over aria-label, which wins over the native label (<label>, alt or the content itself). The title attribute is only a last resort.

Do not put aria-label on a plain <div> or <span>. Elements with no role are not allowed to have a name, and many screen readers ignore it. Name interactive elements, landmarks and other elements with a real role.

aria-describedby

A description is extra information read after the name and role, such as a hint or an error message. Like aria-labelledby, it points at ids:

HTML
<label for="pw">Password</label>
<input type="password" id="pw" aria-describedby="pw-hint">
<p id="pw-hint">At least 12 characters.</p>

A screen reader might say: "Password, secure edit text, At least 12 characters."

States and properties

States describe the current condition of an element and usually change with interaction. Properties describe characteristics that change less often. Some you will use often:

Attribute Meaning
aria-expanded="true|false" A control that shows or hides another element is open or closed.
aria-pressed="true|false" A toggle button is pressed or not.
aria-current="page" This link points to the current page (also step, date, true).
aria-invalid="true" A form field's value failed validation.
aria-hidden="true" Remove this element and its children from the accessibility tree.
aria-controls="id" This control affects the element with that id.

Here is a classic disclosure pattern: a button that shows and hides a panel. The script keeps aria-expanded in sync with what is on screen.

Disclosure button with aria-expanded

Notice that a real <button> is used, so keyboard support comes free. ARIA only adds the missing piece: the open or closed state. For this exact pattern, <details> and <summary> give you everything natively; see Collapsible Sections with Details.

Live regions: announcing changes

When content changes without a page load ("Item added to cart", "3 results found"), a sighted user sees it, but a screen reader user may hear nothing. A live region asks assistive technology to announce changes inside it.

  • aria-live="polite" waits until the user is idle, then announces. Use it for most updates.
  • aria-live="assertive" interrupts immediately. Save it for urgent, time-sensitive messages.
  • role="status" is a polite live region with a meaning ("this is status information").
  • role="alert" is an assertive live region for important errors or warnings.
A polite live region

The key detail is in the comment: the live region must exist before its content changes. If you insert a brand-new element that already contains the message, many screen readers will not announce it. Keep an empty region on the page and update its text.

Use live regions sparingly. A page that constantly announces things is exhausting to listen to.

Checking your ARIA

Every major browser shows the accessibility tree. In Chrome or Edge, open DevTools, select an element and look at the Accessibility pane; Firefox has a dedicated Accessibility tab. You can see the computed role, name, description and states exactly as assistive technology receives them. The DevTools lesson shows how to open these panels.

Common mistakes to look for:

  • Roles on elements that already have the right one, or roles that contradict them.
  • Interactive ARIA widgets that do not work with the keyboard.
  • aria-hidden="true" on something that contains a link or button.
  • Ids in aria-labelledby or aria-describedby that do not exist (a typo breaks the reference silently).
  • States such as aria-expanded that are never updated by the script.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What happens when you add role="button" to a <div>?

    ARIA only changes the accessibility tree. Behavior such as focus and key handling must be added by you, which is why a real button is better.
  2. 2. A section already has a visible heading. Which attribute names the section using that heading's text?

    aria-labelledby points at the heading's id and reuses its visible text, so the name and the visible label never drift apart.
  3. 3. Why should a live region be in the page before its text changes?

    Assistive technology watches existing live regions for changes. Keep an empty region in the DOM and update its text content.
  4. 4. Which use of aria-hidden="true" causes a serious problem?

    Keyboard users can still tab to the link, but screen readers treat it as if it did not exist. Never hide focusable content.

Summary

  • ARIA changes only the accessibility tree, never behavior or appearance.
  • The first rule of ARIA: if native HTML can do it, use native HTML.
  • Roles describe what an element is; most elements already have an implicit role.
  • Names come from content, <label> or alt first; use aria-labelledby or aria-label when needed, and aria-describedby for extra hints.
  • Keep states such as aria-expanded and aria-pressed in sync with what is on screen.
  • Live regions (aria-live, role="status", role="alert") announce dynamic updates; keep them in the DOM and use them sparingly.

Next up: Keyboard Access and Focus.