What is ARIA?

ARIA (Accessible Rich Internet Applications) is a set of HTML attributes, role, aria-* states and properties, that tell assistive technologies what a custom widget is, what state it is in and how it relates to other elements. ARIA changes only the accessibility tree; it adds no behavior, focus or keyboard support.

Three kinds of attributes

  • Roles: what something is: role="dialog", "tablist", "tab", "alert", "switch".
  • States: values that change: aria-expanded, aria-checked, aria-selected, aria-disabled, aria-busy.
  • Properties: relationships and descriptions: aria-label, aria-labelledby, aria-describedby, aria-controls, aria-live.

The first rule of ARIA

Do not use ARIA if a native element does the job. <button> already has the role, focusability and Enter/Space handling; <div role="button"> needs all of that added manually. "No ARIA is better than bad ARIA": incorrect roles actively mislead screen reader users.

When ARIA is the right tool

  • Custom widgets with no native equivalent: tabs, comboboxes, tree views.
  • Communicating dynamic state: aria-expanded on a disclosure button.
  • Live regions: aria-live="polite" for toast messages and async results.
  • Hiding decorative content: aria-hidden="true".

Remember

If you add a role, you must implement the matching keyboard pattern. The WAI-ARIA Authoring Practices Guide (APG) documents the expected behavior for each widget.

Code example

html
1<style>
2 [role="tab"][aria-selected="true"] { background: #0b1020; color: white; }
3 [role="tab"] { font: 600 15px system-ui; padding: 6px 12px; }
4 [role="tabpanel"] { border: 2px solid #0b1020; padding: 12px; margin-top: 6px; font-family: system-ui; }
5</style>
6<div role="tablist" aria-label="Plan details">
7 <button role="tab" id="t1" aria-selected="true" aria-controls="p1">Features</button>
8 <button role="tab" id="t2" aria-selected="false" aria-controls="p2" tabindex="-1">Pricing</button>
9</div>
10<div role="tabpanel" id="p1" aria-labelledby="t1">Unlimited projects and 24/7 support.</div>
11<div role="tabpanel" id="p2" aria-labelledby="t2" hidden>$12 per user per month.</div>
12<script>
13 const tabs = [...document.querySelectorAll('[role="tab"]')];
14 function select(tab) {
15 tabs.forEach((t) => {
16 const on = t === tab;
17 t.setAttribute("aria-selected", on);
18 t.tabIndex = on ? 0 : -1; // roving tabindex
19 document.getElementById(t.getAttribute("aria-controls")).hidden = !on;
20 });
21 tab.focus();
22 }
23 tabs.forEach((t, i) => {
24 t.addEventListener("click", () => select(t));
25 t.addEventListener("keydown", (e) => { // arrow keys, per the APG tabs pattern
26 if (e.key === "ArrowRight") select(tabs[(i + 1) % tabs.length]);
27 if (e.key === "ArrowLeft") select(tabs[(i - 1 + tabs.length) % tabs.length]);
28 });
29 });
30</script>

Practice this question

Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the HTML & CSS set.

Open in study app