Sub topic 12
How browsers expose semantics to assistive technology
This chapter assumes you know basic HTML syntax and can open your browser's developer tools. It builds on the landmark, heading and form chapters. Here you will see what the browser does with those elements after it parses them.
From markup to the accessibility tree
A browser builds the DOM from your HTML. It then builds a second structure called the accessibility tree. This tree is a simplified copy of the page that is meant for assistive technology (AT), such as screen readers and voice control software. AT does not read your HTML or look at your CSS. It reads the accessibility tree through a platform accessibility API.
Each node in the tree has four main properties:
- Role: what kind of thing it is, such as button, link, heading or navigation.
- Name: the label users hear, such as "Subscribe".
- State: conditions such as checked, expanded or disabled.
- Value or description: extra information, such as the text in a field.
What native elements give you for free
Native elements arrive with a role, a name source and keyboard behavior already defined. This table shows the mapping for elements covered earlier.
| Markup | Role in the tree | Name comes from |
|---|---|---|
| `<nav aria-label="Primary">` | navigation | the `aria-label` |
| `<main>` | main | none needed |
| `<h2>Key points</h2>` | heading, level 2 | its text |
| `<button>Save</button>` | button | its text |
| `<input id="email">` with a `<label for="email">` | textbox | the label |
| `<th scope="col">` | column header | its text |
A <div class="btn"> has the generic role. Screen reader users hear only the text "Save", with no hint that it is a control, and it cannot receive keyboard focus.
Landmarks and headings also let AT users skip around. A screen reader can list every landmark or every heading on the page and jump to one. This is why a single <main> and a logical heading order matter. Without them, users must move through the page one element at a time.
Names and what gets left out
An element with the right role but no name is still a problem. An <input> with no label is announced as "edit text" with nothing else. Two <nav> elements should each have an aria-label, so users can tell "Primary" from "Footer" in a landmark list.
The browser also leaves some content out of the tree:
- Elements with
display: noneorvisibility: hidden. - Elements with the
hiddenattribute. - Elements with
aria-hidden="true". - Purely decorative images that use
alt="".
Removing content from the tree removes it for AT users, so only hide what you want hidden from everyone, or what is truly decorative.
Inspecting the tree
Chrome, Edge and Firefox all show the accessibility tree in their developer tools.
- Open developer tools and select an element in the Elements or Inspector panel.
- Open the Accessibility pane or tab.
- Check the computed role, name and states.
- In Firefox, use the Accessibility panel to browse the whole tree.
Compare a <div onclick> with a <button>. The div shows a generic role and no name source beyond its text, while the button shows role "button" and is focusable.
Exercise
A developer writes <span class="link" onclick="go()">Pricing</span>. In the accessibility tree, what role does it get, and what two things does a real <a href="/pricing"> add?
Show answer
The span has a generic role, so AT does not announce it as a link. A real <a href> adds the link role, which AT announces and lists, and keyboard support, because it is focusable and activated with Enter.
Exercise
Why can a page with a visible, correctly styled search box still be unusable for a screen reader user if the input has no label?
Show answer
The accessibility tree gives the input a textbox role but no name. The user hears only "edit text" and cannot tell what to type. A <label for> supplies the name.