Mrs. Sri's storeroom is full of boxes, and every box has a sticker. A "Blankets" sticker on a box doesn't put blankets inside it. The sticker only tells someone who can't see inside. The right sticker helps a lot. The wrong one makes people take the wrong box.
On the web, the sticker is ARIA (Accessible Rich Internet Applications), a set of W3C attributes that change what the accessibility tree says: the role (what this element is), its state (how it is right now), and its properties (how it relates to other elements). The box is an HTML element, what is inside the box is the element's behaviour, and the person who can only read the stickers is a screen reader. Just as a sticker doesn't change what is in the box, ARIA changes no behaviour at all.
Four rules of ARIA
The W3C note "Using ARIA" lists four rules. The document is now a Discontinued Draft (a draft that was stopped, February 2026). The rules are kept for reference, and the active guidance is the ARIA Authoring Practices Guide (APG), W3C's guide to building accessible components.
- Use the native HTML element when there is one. Native means built into HTML.
<button>is better than<div role="button">, because<button>can already take focus and be pressed. - Don't change a native element's meaning, unless you really have to. Don't write
<h2 role="tab">. - Every ARIA control must work with the keyboard. A control is a part people can use, such as a button or a tab. A role is only a promise, and you have to write the behaviour yourself.
- Don't put
role="presentation"oraria-hidden="true"on a focusable element.role="presentation"removes an element's role, andaria-hidden="true"hides it from the tree. On a focusable element, focus would land on something that isn't in the tree.
The first rule explains why <nav role="navigation"> is redundant (says the same thing twice): <nav> already carries the navigation role on its own. Until 2023, a search area had no element of its own, so <div role="search"> filled the gap. Since 2023 HTML has <search>. The Chrome, Safari and Firefox versions we tested know it, and Chromium 147 gives it the search role in the tree. <div role="search"> is still right for older browsers.
Role, state and property
- Role: the kind of element.
tab,tablist,tabpanel,button,status. - State: a condition that changes as the element is used.
aria-selected,aria-expanded,aria-pressed. - Property: a relation or trait that rarely changes.
aria-controls(which element it controls),aria-labelledby(which element its name comes from).
The Mist Homestay page has four parts that need more than plain HTML. One of them is the photo tabs: a row of buttons (Room, Bathroom, Terrace), where each button shows one photo in the panel below.
| Part | Role | State and property |
|---|---|---|
| Photo tabs Room, Bathroom, Terrace | tablist, tab, tabpanel |
aria-selected, aria-controls, aria-labelledby |
| The "Room facilities" button that opens a list | button (native) |
aria-expanded, aria-controls |
| The "Add breakfast" button | button (native) |
aria-pressed |
| The total price | status |
read out when it changes |
Room photo tabs: tablist, tab, tabpanel
These are the Terrace Room photo tabs. The HTML part makes three tabs and three panels. The <script> part (JavaScript code) changes the active tab when a tab is clicked:
<div role="tablist" aria-label="Terrace Room photos">
<button role="tab" id="tab-room" aria-selected="true" aria-controls="panel-room">Room</button>
<button role="tab" id="tab-bath" aria-selected="false" aria-controls="panel-bath" tabindex="-1">Bathroom</button>
<button role="tab" id="tab-terrace" aria-selected="false" aria-controls="panel-terrace" tabindex="-1">Terrace</button>
</div>
<div role="tabpanel" id="panel-room" aria-labelledby="tab-room" tabindex="0">
<img src="room.svg" alt="A double bed in front of a large window">
</div>
<div role="tabpanel" id="panel-bath" aria-labelledby="tab-bath" tabindex="0" hidden>...</div>
<div role="tabpanel" id="panel-terrace" aria-labelledby="tab-terrace" tabindex="0" hidden>...</div>
<script>
const tabs = document.querySelectorAll('[role="tab"]');
for (const tab of tabs) {
tab.addEventListener('click', () => {
for (const t of tabs) {
const on = t === tab;
t.setAttribute('aria-selected', String(on)); // the state is updated too
t.tabIndex = on ? 0 : -1;
document.getElementById(t.getAttribute('aria-controls')).hidden = !on;
}
});
}
</script>
role="tablist"wraps the row of tabs, andaria-labelgives that row its name.aria-selected="true"marks the active tab. The code in<script>must update this value every time the tab changes, because ARIA doesn't update itself.aria-controlson a tab points at its panel'sid.aria-labelledbyon the panel points at its tab'sid, so the first panel is named "Room".- Inactive panels get
hidden, so they leave both the screen and the tree. tabindexand the arrow keys are covered in the next lesson.
We read the tree from Chromium 147 with Accessibility.getFullAXTree from the Chrome DevTools Protocol (a way to read what is inside Chrome from code):
| Version | What a screen reader receives |
|---|---|
Three plain <button>s, the active one only coloured |
button "Room", button "Bathroom", button "Terrace": nobody knows which photo is showing |
| The pattern above | tablist "Terrace Room photos" holding tab "Room" selected=true, tab "Bathroom" selected=false, tab "Terrace" selected=false, then tabpanel "Room" |
aria-expanded and aria-pressed
Two more buttons on Mrs. Sri's page: "Room facilities" opens a list of facilities, and "Add breakfast" adds or removes breakfast.
<button aria-expanded="false" aria-controls="facilities">Room facilities</button>
<ul id="facilities" hidden>
<li>Hot water</li>
<li>Thick blankets</li>
</ul>
<button class="breakfast" aria-pressed="false">Add breakfast</button>
aria-expandedsays whether the list the button controls is open. In Chromium's tree:button "Room facilities" expanded=false, thenexpanded=trueonce the script changes it when the button is clicked.- The first rule again:
<details><summary>Room facilities</summary>...</details>gives the same thing with no JavaScript. Chromium writes it asDisclosureTriangle "Room facilities" expanded=false, and the browser itself keeps the state up to date. aria-pressedturns a button into a toggle button: a button that stays pressed or not pressed, like a switch. In Chromium's tree:button "Add breakfast" pressed=false. The APG (Button pattern) says the label of a button like this must not change when its state changes. The label stays "Add breakfast", and only the state changes. If the label switches to "Remove breakfast", don't usearia-pressed.
aria-live: news without moving focus
When Mr. Hadi adds breakfast, the total changes elsewhere on the page. His focus stays on the button, so without a live region (a part of the page that screen readers watch) the change isn't read out. This total line becomes a live region with role="status":
<p class="total" role="status">Total for 2 nights: <b>$70</b></p>
There are three ways to write a live region. This is what Chromium 147's tree says, and what is read out when the content changes:
| Markup | In Chromium 147's tree | What's read when it changes |
|---|---|---|
role="status" |
status live=polite atomic=true |
the whole sentence, once the screen reader finishes speaking |
aria-live="polite" on a <p> |
live=polite atomic=false |
possibly only the part that changed |
role="alert" |
alert live=assertive atomic=true |
the whole sentence, cutting off whatever is being read |
polite means it waits until the screen reader finishes speaking, and assertive means it interrupts right away. aria-atomic="true" means the whole region is read, not just the piece that changed. The "Booking sent" toast that appears without moving focus also gets role="status". Keep role="alert" for errors that need attention right away. The region must already exist before its text changes.
The wrong role
Say Mrs. Sri's team builds the room photo tabs from <h2 role="tab">Room</h2>. Is the heading "Room" still in Chromium's accessibility tree? And can a keyboard user reach that tab with the Tab key? Guess before you look at the table.
A wrong role is worse than no role, because it erases the right meaning. We tried these four pieces of markup in Chromium 147 (focusable means it can take focus):
| Markup | In the tree | What happens |
|---|---|---|
<h2 role="tab">Room</h2> |
tab "Room", not focusable |
the heading leaves the headings list, and the Tab key skips the tab |
<button role="tabs"> (a typo) |
button "Room" |
an unknown role is ignored; it's a plain button |
<button role="heading" aria-level="2"> |
heading "Room" level 2, still focusable |
a screen reader calls it a heading, though it can be clicked |
<button role="presentation"> |
button "Terrace" |
the fourth rule: the browser refuses presentation on a focusable element |
So the answer to the guess: no, to both questions. The heading "Room" is replaced by tab "Room", so someone jumping through the headings list no longer finds it. Since <h2> can't take focus, the Tab key also skips it. That is why there is the second rule: tabs are made from <button role="tab">.
⚠️ Stickers on the wrong box
- ARIA before HTML. A
<div role="button">with notabindexand no keyboard code only pretends to be a button. Use<button>,<details>,<search>. - A state that isn't updated. An
aria-expanded="false"that stays false while the list is open makes the screen reader say "collapsed". Change the state in the same code that changes what is shown. aria-controlsoraria-labelledbypointing at anidthat doesn't exist. The link breaks with no error. Check that theidmatches exactly.- Changing the label and using
aria-pressed. Pick one: a fixed label witharia-pressed, or a changing label without it. role="alert"for every piece of news. An alert interrupts anything. Ordinary news only needsrole="status".
TL;DR: ARIA (a set of W3C attributes) changes the accessibility tree that screen readers read, not an element's behaviour. ARIA writes the role (what the element is), the state (how it is right now) and properties (how it relates to other elements). Four rules (W3C "Using ARIA"): native (built-in) HTML elements first; don't change a native element's meaning (<h2 role="tab"> erases its heading); ARIA controls must work with the keyboard; no presentation or aria-hidden on a focusable element. <nav> is already navigation, so role="navigation" is redundant. role="search" filled a gap until HTML got <search> (2023). Photo tabs (a row of buttons, each showing one photo): a tablist (the row of tabs) holding tabs with aria-selected (the active tab) and aria-controls (the panel it controls), and panels as tabpanel with aria-labelledby (the name comes from the tab). A button that opens and closes content: aria-expanded (or <details> with no JavaScript). A toggle button: aria-pressed with a label that doesn't change. News without moving focus: role="status" (it waits for the screen reader to finish speaking, then reads the whole sentence), and for urgent errors role="alert". Your code must update the states, and you can check the result in DevTools' accessibility tree.
⚡ ARIA is a sticker
Meaning: A sticker on a box tells you what is inside without changing what is inside. ARIA works the same way: these attributes change what the accessibility tree (what screen readers read) says, not the element's behaviour. There is the role (what the element is), the state (how it is now, such as aria-selected) and the property (how it relates, such as aria-controls). Its first rule: use the native (built-in) HTML element when there is one, so <button>, not <div role="button">.
⚡ Don't change a native element's meaning
Guess first: while checking someone else's code, you find <div role="search">, a menu button with aria-expanded (open or closed), <h2 role="tab"> inside a tablist (a row of tabs), and a toast (a small message) with role="status". Which one breaks the ARIA rules?
<h2 role="tab">. The heading leaves the headings list, and since an <h2> can't take focus, the Tab key skips that tab.
Meaning: Don't change a native HTML element's meaning. Build the tab from <button role="tab">, which can already take focus and be pressed.
⚡ Ordinary news gets role="status"
Write:
<p class="total" role="status">Total for 2 nights: <b>$70</b></p>
Meaning: This total price line has role="status". When the total changes and focus stays where it is, a screen reader reads the whole sentence once it finishes speaking. role="alert" cuts off whatever is being read, so keep it for errors. The "Booking sent" toast only needs role="status" too.