The Accessibility Tree and Native Semantics
How the browser turns your markup into the accessibility tree that screen readers read, and why native elements give you roles, names and keyboard support.
The Accessibility Tree and Native Semantics
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- Assistive technology never reads your HTML or your pixels. It reads the accessibility tree, a second tree the browser builds from the DOM, where each node has a role, a name, and states.
- Native elements map to roles for free: `button` becomes a button, `nav` a navigation landmark, `h2` a level-2 heading. A `div` with a click handler is just a generic node with text in it.
- Some markup removes nodes from the tree: `hidden`, `display: none`, `visibility: hidden`, `inert` and `aria-hidden="true"` all dropped their content in a test. `opacity: 0` and visually clipped text stayed in.
- Context changes roles. A `section` has no landmark role until it has an accessible name, and a `header` inside an `article` is not a page banner.
- To see the tree, use the Accessibility pane in browser DevTools. It is the real thing, where a source-code read is only a guess.
The page a screen reader sees
Your page has a visual form (pixels) and a structural form (the DOM). A screen reader uses neither. A blind user listening to a page needs to know “there is a navigation with four links, then a heading, then a button called Save”, and nothing in the pixels says that, while the DOM is full of noise: wrapper divs, class names, script tags.
So browsers build a third structure. It is called the accessibility tree, and it is a pruned copy of the DOM with the interesting parts labelled. Each node carries a role (what it is), a name (what it is called), and states (checked, expanded, disabled). Platform accessibility APIs hand that tree to screen readers, voice control and switch devices. Think of it as the page’s stage-manager script: the audience sees sets and costumes, the crew works from the script.
The rest of this section of the roadmap follows from that one fact. Whatever isn’t in the tree, assistive technology can’t use.
Native elements fill the tree for you
The browser decides roles from your tags. Writing <button> means writing “this has the role button, its name is its text, it takes focus, and Enter and Space activate it.” You get all of it with one word. The reverse is also true, and a quick test makes it concrete. This markup went through Chromium 159, and I read the tree through the DevTools protocol:
<div onclick="save()">Fake button</div>
<button>Real button</button>
The div came out as a generic node holding the text “Fake button”. The button came out as button "Real button". Nothing in the first one tells assistive technology it does anything. The accessible HTML and ARIA basics lesson in the frontend roadmap makes the same point from the screen-reader side.
Other results from that run:
<nav aria-label="Main">became anavigationnamed “Main”, and amainelement became themainlandmark.- An
<a>with nohrefbecame plain text. A link is anawith a destination. <img alt="">was dropped from the tree entirely, and<img alt="Logo">becameimage "Logo". An emptyaltis how you say “decoration”.- A
<table role="presentation">collapsed into generic nodes. A layout table without that role was kept by Chromium as aLayoutTable.
Context changes the role
Landmarks depend on where an element sits. In the same test a <header> placed directly in the body became banner, but a <header> inside an <article> did not. A <section> with no accessible name stayed generic, while <section aria-label="Pricing"> became a region named “Pricing”. That’s deliberate: if every section were a landmark, a landmark list would be useless. The landmarks lesson covers which elements to use, and accessible names covers how they get labelled.
What leaves the tree
Hiding is a tree question as well as a visual one. In the test, all of these removed their content from the tree: the hidden attribute, display: none, visibility: hidden, inert, aria-hidden="true", and the body of a closed <details>. Two things looked hidden but stayed in: opacity: 0, and a paragraph clipped to a 1px box. The second is on purpose; that is the visually-hidden technique. The hiding content lesson has the full table.
One more behaviour matters here. aria-hidden="true" removes a node from the tree, but not from the tab order. In a test the buttons inside an aria-hidden container were still reachable with Tab, which gives keyboard users a control that screen readers cannot see.
Looking at the tree yourself
Chrome DevTools has an Accessibility pane in the Elements panel, with a full-tree view. Firefox has an Accessibility Inspector tab. Use them to check a component, instead of reasoning from source. One caution from my tests: Playwright’s ariaSnapshot() is a handy text dump, but it computes its own approximation. It listed the buttons inside an inert container that the browser itself had removed, so use the browser’s tree for anything you plan to claim. Testing HTML accessibility returns to this.
What the video covers
This is Hidde de Vries’s JSConf Budapest talk “It’s the markup that matters” (June 2022, about 33 minutes). The description says it covers how the markup we write shapes the Document Object Model and the accessibility APIs, with specific examples and how to optimise them for end users, and it ends with a look at the Accessibility Object Model. I could not read a transcript, so I cannot list the examples. The checks on roles, landmarks and removal from the tree above are my own test results, and the video’s 2022 date means any browser behaviour it describes should be checked against current DevTools. Russ Weakley’s talk, linked in further viewing, goes deeper on names.
Where this fits
This lesson sets up everything else in the accessibility group. Next is keyboard, focus and tabindex, because focusable elements are the other half of what makes a native control work. details and summary is the first interactive element where native roles pay off.
Check yourself
Why does a screen reader announce a styled `div` with an `onclick` as plain text, and what is the fix?
The browser only assigns a role when the markup says so. A `div` is a generic node, so the tree holds text and nothing that says it can be pressed. Use a `button`, which brings the role, a name from its content, focus and Enter and Space activation.
Two elements look the same on screen, but one is `<section>` and the other is `<section aria-label="Pricing">`. How do they differ in the tree?
The unnamed one stayed a generic node in a test. The named one became a `region` landmark with the name "Pricing", so a landmark list can jump to it.
You hide a promo banner with `opacity: 0` and a screen reader user still hears it. Why?
`opacity: 0` changes how the box is painted, not whether it exists. The node stays in the tree and, if it contains links, they stay in the tab order. Use `hidden` or `display: none` to remove it for everyone.
Where do you check what the accessibility tree contains for a page you are building?
In the Accessibility pane of the browser's DevTools. Chrome's full-tree view and Firefox's Accessibility Inspector show the roles and names the browser computed. Checking the tree, not guessing from source, is the point.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.