Sub topic 12
How Browsers Expose Semantics to Assistive Technology
This chapter assumes you know basic HTML syntax (tags, attributes, nesting) and can open your browser's developer tools. You should also know the landmark elements and heading levels from earlier chapters. Here you will learn what the browser does with your markup after parsing it, and why that step is the real reason semantic elements matter.
From markup to the accessibility tree
A browser turns your HTML into the DOM, the tree of elements it uses to render the page. Browsers also build a second tree from the DOM, called the accessibility tree. The accessibility tree is a simplified model of the page made for assistive technology (AT), such as screen readers, voice control and switch devices.
AT does not read your HTML or look at pixels. It asks the browser for the accessibility tree through a platform accessibility API. Examples are UI Automation on Windows, NSAccessibility on macOS and AT-SPI on Linux. The browser translates the tree into whatever that API expects.
Each node in the accessibility tree is an accessible object. It carries four kinds of information:
- Role: what kind of thing it is, such as button, link, heading or navigation.
- Name: a short label that identifies it, such as "Subscribe".
- State: its current condition, such as checked, expanded, disabled or required.
- Value and relationships: the text in a field, a heading level, or the link between a label and its control.
Semantic HTML works because each native element comes with a default role, and often a name and states, computed by the browser. You write <button> and get all of that without extra code.
Native elements and their default roles
The table lists common elements and the role the browser exposes for each. Some mappings depend on context.
| Element | Exposed role | Notes |
|---|---|---|
| `<button>` | button | Focusable, activated by Enter and Space |
| `<a href>` | link | Without `href`, it has no link role and is not focusable |
| `<h1>` to `<h6>` | heading | The level is exposed as a property |
| `<nav>` | navigation | A landmark |
| `<main>` | main | A landmark, one visible per page |
| `<header>` | banner or generic | Banner only when it is not inside `article`, `section`, `main`, `nav` or `aside` |
| `<footer>` | contentinfo or generic | Same scoping rule as `header` |
| `<aside>` | complementary | A landmark |
| `<section>` | region or generic | Region only when it has an accessible name |
| `<ul>`, `<ol>` | list | Items are exposed as listitem |
| `<input type="checkbox">` | checkbox | The checked state is exposed |
| `<table>` | table | With rowheader and columnheader for `th` cells |
| `<div>`, `<span>` | generic | No meaning exposed |
The header, footer and section rows show why scope matters. A page-level <header> becomes the banner landmark. A <header> inside an <article> is only a generic container, so a screen reader user will not find it in a list of landmarks.
Accessible names
A role says what an object is. A name says which one it is. A page may have three buttons, and "button, button, button" is useless without names.
The browser computes the name from several sources, in a fixed priority order. This is the accessible name computation. In simplified form, it works like this:
aria-labelledby, which points to other elements byid.aria-label, a string on the element itself.- Native sources, which depend on the element. These include the
<label>for a form control, thealtattribute for an image, the<caption>for a table, the<legend>for a fieldset, and the text content for buttons and links. - The
titleattribute, used as a last resort.
This is why the form chapter stressed <label for>. Take this markup.
<label for="email">Email address</label>
<input id="email" name="email" type="email" required>The accessibility tree contains a textbox with the name "Email address". It also has the state required. A screen reader announces something like "Email address, edit text, required". If you replaced the label with a placeholder only, the name might still come from the placeholder in some browsers, but the placeholder disappears when the user types, and it is not a dependable name source.
The same logic applies to landmarks. Two <nav> elements both have the role navigation. Naming them lets users tell them apart.
<nav aria-label="Primary">
<ul>
<li><a href="/articles">Articles</a></li>
</ul>
</nav>
<nav aria-label="Footer">
<ul>
<li><a href="/privacy">Privacy</a></li>
</ul>
</nav>A screen reader lists these as "Primary navigation" and "Footer navigation".
Comparing a div button and a native button
Here are two ways to build a Save control.
<div class="btn" onclick="save()">Save</div>
<button type="button" onclick="save()">Save</button>In the accessibility tree, the first becomes a generic object with the text "Save". It has no button role, so a screen reader reads it as plain text. It is not in the tab order. Pressing Enter or Space does nothing, because only mouse clicks reach onclick. Voice control users who say "click Save" may or may not reach it.
The second becomes a button named "Save". It joins the tab order and responds to Enter and Space. Browsers also expose its disabled state if you add the disabled attribute. The visual style can be identical in both cases. Only the second exposes its meaning.
What gets left out of the tree
The accessibility tree is not a copy of the DOM. The browser prunes it.
- Generic containers such as
divandspanwith no semantics are usually collapsed, so they add no noise. - Hidden content is removed. This includes
display: none,visibility: hiddenand thehiddenattribute. Hiding something visually with CSS also hides it from AT. - Decorative images with
alt=""are removed. An image with noaltattribute at all is often announced by its file name, which is worse. - Elements with
aria-hidden="true"are removed, along with their descendants.
Sometimes you want content available to AT but not visible. The usual technique is a "visually hidden" CSS class that clips the element to a one-pixel box instead of using display: none.
<style>
.visually-hidden {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
padding: 0;
overflow: hidden;
clip-path: inset(50%);
white-space: nowrap;
border: 0;
}
</style>
<button type="button">
<span aria-hidden="true">×</span>
<span class="visually-hidden">Close dialog</span>
</button>The button's name is computed from its text content. The visible "×" is hidden from AT, and the hidden text supplies "Close dialog".
Inspecting the tree in devtools
You can see the accessibility tree yourself.
- In Chrome or Edge, open DevTools and select an element in the Elements panel. Open the Accessibility pane. It shows the computed role, name and states, and how the name was derived. You can also enable the full-page accessibility tree view.
- In Firefox, open the Accessibility panel. It shows the whole tree and flags some problems, such as missing names.
- In Safari, the Elements tab has an Accessibility section in the details sidebar.
Try this on the <div class="btn"> above. The role will be generic or none, and there will be no focusable state. Then try the <button>. The difference is visible in a few seconds.
Where ARIA fits
ARIA (Accessible Rich Internet Applications) is a set of attributes that change what the browser writes into the accessibility tree. role="button" changes the role. aria-label changes the name. aria-expanded sets a state.
ARIA only changes the tree. It adds no behavior. A <div role="button"> is announced as a button, but it still has no focus, no Enter or Space handling and no default styling. You would need to add tabindex="0" and key handlers yourself. That is why the first rule of ARIA is to use a native element when one exists. The next chapter covers ARIA in detail.
Wrong ARIA is also worse than none. role="button" on a link tells AT it is a button, so users expect Space to activate it, and that does not work on a link.
Common failure modes
- Unnamed controls. An icon-only button with no text,
altoraria-labelhas the role button and an empty name. A screen reader says only "button". - Duplicate landmarks without names. Two
<nav>elements both announce as "navigation". - Heading levels chosen for size. Screen reader users often navigate by heading level, so skipped levels make the page structure look broken.
- Hiding content with
display: noneand expecting AT to read it. It will not. aria-hidden="true"on a focusable element. The element is removed from the tree but still receives keyboard focus, so a screen reader user lands on something with no announcement.
Exercise
A page has two <nav> elements, one in the header and one in the footer, and a <div onclick="open()">Menu</div>. Describe what each exposes in the accessibility tree and give one fix for each problem.
Show answer
Both <nav> elements expose the navigation role, but with no names a screen reader lists two identical landmarks. Fix this with aria-label="Primary" and aria-label="Footer". The <div> exposes a generic object with the text "Menu", has no button role, is not focusable and does not respond to the keyboard. Replace it with <button type="button">Menu</button>, which gets the button role, the name "Menu", focus, and Enter and Space activation.
Exercise
You add <span aria-hidden="true">×</span> inside a button and nothing else. What is the button's accessible name, and how do you fix it?
Show answer
The name is empty, because the only content is hidden from the tree, so a screen reader announces just "button". Add visually hidden text such as <span class="visually-hidden">Close dialog</span>, or put aria-label="Close dialog" on the button.