Skip to content
Tutorials Center
My learning

Topics

Lesson 13 of 38 ยท Semantic HTML and ARIA

ARIA Basics

Learn what WAI-ARIA is, when to use it, the five rules of ARIA, and how roles, properties and states such as aria-label, aria-expanded and aria-hidden change what assistive tech hears.

ARIA stands for Accessible Rich Internet Applications. It is a W3C specification (WAI-ARIA) that adds attributes to HTML so that custom interfaces can describe themselves to assistive technology: "this is a tab", "this menu is collapsed", "this field is invalid". ARIA only changes what is announced. It does not add behavior, keyboard support or visual styling.

That last sentence is the most important one in this lesson. Many accessibility bugs come from ARIA added where it was not needed, or added without the behavior that goes with it. Remember the slogan: no ARIA is better than bad ARIA.

The five rules of ARIA

  1. Use native HTML first. If an element with the semantics you need exists, use it instead of repurposing another with ARIA. <button> beats <div role="button">.
  2. Do not change native semantics unless you really must. Do not write <h2 role="tab">; put the heading inside a tab.
  3. All interactive ARIA controls must be keyboard usable. A role="button" needs focus and Enter and Space handlers.
  4. Do not use role="presentation" or aria-hidden="true" on a focusable element. The user could tab to something that is invisible to them.
  5. All interactive elements must have an accessible name.

The ARIA rules in short

Native first Use button, not div role button
Keep semantics Do not override native roles
Keyboard ARIA adds no behavior
No hiding focus Never aria-hidden on focusable items

Rule 5, always provide a name.

1 / 2

Roles, properties and states

ARIA attributes fall into three groups:

  • Roles say what something is: role="dialog", role="tablist", role="alert", role="img".
  • Properties describe stable relationships and facts: aria-label, aria-labelledby, aria-describedby, aria-controls, aria-required.
  • States describe values that change: aria-expanded, aria-checked, aria-selected, aria-pressed, aria-invalid, aria-hidden, aria-busy.

Your JavaScript must update states as the interface changes. A disclosure button whose aria-expanded stays false while the panel is open is lying to the user.

Naming things

The accessible name is what a screen reader calls a control. The browser computes it in order of priority:

  1. aria-labelledby (points to other elements by id)
  2. aria-label
  3. Native label sources: a <label>, the content of a button or link, alt, <legend>, <caption>
  4. title or placeholder (last resort, unreliable)

An aria-labelledby reference may include text that is not visible, and it can join several elements into one name.

Naming with aria-label and aria-labelledby

This script imitates a simplified version of the real name algorithm. The third button's visible text is "Delete", but its accessible name is "Delete invoice 1042", which gives context that visible text lacks.

A disclosure, the right way

A disclosure (show/hide) widget needs a button, aria-expanded and aria-controls, and JavaScript that keeps them in sync:

Accessible disclosure

It uses a real <button>, so keyboard support is free. ARIA adds only the state. The hidden attribute removes the closed panel from the accessibility tree.

aria-hidden and visibility

aria-hidden="true" removes an element from the accessibility tree while leaving it visible. Use it for decorative icons or for the background content while a modal dialog is open. Never use it on something focusable. Elements hidden with display: none, visibility: hidden or the hidden attribute are already hidden from AT, so they need no extra attribute.

Where ARIA is really needed

  • Names for controls that have no text (aria-label).
  • States for custom widgets and toggles (aria-expanded, aria-pressed).
  • Live announcements (aria-live, role="status", role="alert").
  • Relationships (aria-describedby for help text, aria-controls).
  • Complex patterns with no native element: tabs, tree views, menus, comboboxes. For those, follow the ARIA Authoring Practices Guide patterns exactly.

Common mistakes

  • aria-label on a div or span with no role: it is often ignored.
  • role="button" without keyboard handlers.
  • Redundant roles like <button role="button">.
  • Invalid values: aria-expanded="yes" should be "true" or "false".
  • Forgetting to update states on interaction.

Run an automated checker as a safety net, and test with a screen reader, because invalid ARIA is silent in the browser.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does ARIA add to an element?

    ARIA changes only what is exposed to AT. Behavior and looks still come from HTML, CSS and JS.
  2. 2. What is the first rule of ARIA?

    Native elements have built-in semantics and behavior, so they are preferred over ARIA.
  3. 3. Which attribute tells AT whether a disclosure is open?

    aria-expanded true or false on the controlling button communicates the open state.
  4. 4. Why should aria-hidden not be put on a focusable element?

    The element stays in the tab order while hidden from AT, so keyboard users land on a silent control.

Summary

  • ARIA exposes roles, properties and states to assistive technology; it adds no behavior.
  • Follow the five rules: native first, keep semantics, keyboard support, no hiding focusable items, always name.
  • Names come from aria-labelledby, aria-label and native sources, in that order.
  • Keep states such as aria-expanded in sync with the interface.

Next: Keyboard Basics