The aria-expanded attribute: which element gets it, and why NVDA still says “collapsed”


The aria-expanded attribute tells a screen reader whether the content a control opens is shown: "true" if so, "false" if hidden, no attribute if the control opens nothing. On a hamburger menu, a real button carries it: on a clickable div, with no role, Chrome ignores it and the screen reader gets no state. The script flips the value, and the CSS can read it to show the menu.
Setting, toggling and checking a menu's state
#Which element gets aria-expanded, and with what value?
The aria-expanded attribute goes on the control that shows and hides content: "true" means shown, "false" hidden; no attribute means the control opens nothing. On a hamburger menu, that's the button: a blind person doesn't see the menu appear, so this ARIA state tells them. NVDA, a free screen reader for Windows, adds it to the button's name and role: “collapsed” or “expanded”.
An accessible menu button follows four rules, and each version of our example is judged by them:
- it's a real
<button>: Tab reaches it, and Enter and Space activate it with no script; - it carries
aria-expanded,"false"on load and"true"with the menu open, since a missing attribute isn't “closed”; - its name stays “Menu”, open or closed, as our aria-label guide explains;
- the menu itself carries no
aria-expanded.
At Larkmere Cheese Cellar, our demo cheesemonger, a round button with three lines opens the navigation in the mobile header. We coded it four ways, all identical on screen.

#Why doesn't aria-expanded work on a clickable div?
In our first version, the icon is a div that responds to clicks. With no role attribute, it gets the role generic, which carries no meaning. ARIA 1.2 allows aria-expanded only on a closed list of roles, such as button, link or tab, and generic isn't on it. The phrase developers search for, “the aria expanded attribute is not allowed on the generic role”, says just that.
Chrome hands screen readers its accessibility tree. In it, we found the div reduced to a generic node with no name or state, which Tab never reaches. The axe-core 4.11.0 testing engine does flag it, under its aria-allowed-attr rule. Its message names no role, though: “ARIA attribute is not allowed: aria-expanded="false"”. The phrase developers search for therefore doesn't come from axe.
Marker 1. The round three-line button, menu closed.Avoid
<div class="burger" aria-expanded="false" onclick="toggleMenu(this)">
<svg width="24" height="24" viewBox="0 0 24 24">
<path class="line top" d="M3 6h18" />
<path class="line middle" d="M3 12h18" />
<path class="line bottom" d="M3 18h18" />
</svg>
</div>Correct
<button type="button" class="burger" aria-label="Menu" aria-expanded="false" aria-controls="menu">
<svg aria-hidden="true" focusable="false" width="24" height="24" viewBox="0 0 24 24">
<path class="line top" d="M3 6h18" />
<path class="line middle" d="M3 12h18" />
<path class="line bottom" d="M3 18h18" />
</svg>
</button>Screen reader: « Menu, button, collapsed »
Styled like the old div, the <button> looks the same. A div with role="button" and tabindex="0" is still tolerated, since Chrome then passes on a button and its state. You have to code Enter and Space yourself, though, and the <button> handles both on its own. An aria-label on a div with no role runs into the same generic role.
The Includdy scan flags this div too, since it runs axe's default rules. Its AI writes a fixed button next to the faulty code, to review against the four menu-button rules.
The “tabIndex should only be declared on interactive elements” error: what to use instead
#Should the menu itself get aria-expanded too?
No: on the panel, the attribute tells screen readers nothing. The navigation role of the nav element used to accept it, until ARIA 1.2 took it away in 2019. An older tutorial may still put it on the menu.
In our second version, the script toggles the attribute on the nav, and the button doesn't have it. Chrome ignores it: its accessibility tree shows a navigation node and a button, neither with a state. Axe-core, which flagged the div, reports nothing here. The Chrome and NVDA test at the end of this page catches it.
Marker 1. The yellow navigation panel, open.Avoid
<button type="button" class="burger" aria-label="Menu">…</button>
<nav id="menu" class="menu" aria-expanded="true">
<ul>…</ul>
</nav>Correct
<button type="button" class="burger" aria-label="Menu" aria-expanded="true" aria-controls="menu">…</button>
<nav id="menu" class="menu">
<ul>…</ul>
</nav>Screen reader: « Menu, button, expanded »
#Why is the menu open on screen while NVDA says “collapsed”?
When a script opens the menu with a CSS class and leaves aria-expanded alone, the attribute stays at false. The browser takes the state from that attribute alone, and NVDA announces it: “collapsed”, in front of a menu that's plainly open.
In our third version, the button does carry aria-expanded="false", but the script toggles an .is-open class on the nav. With the menu open, Chrome's Accessibility tab showed us the Expanded row still at false. Axe-core reports nothing: it can't know that this button opens a panel.
Marker 1. The yellow menu, open in the page. Marker 2. The Expanded row of the computed properties, set to false.In an audit, a state stuck at “collapsed” fails the WCAG success criterion Name, Role, Value, at level A. It requires that assistive technologies get notified when a scripted component changes state. In Europe, EN 301 549 requires every web page to meet that criterion. This standard was drafted as one voluntary way to comply with Directive (EU) 2019/882, the European Accessibility Act.
#How do you open the menu in CSS with aria-expanded="true"?
The fix drops the .is-open class. The script flips the attribute, writing the string "true" or "false", and the CSS reads its value. The selector [aria-expanded="true"] matches only that exact value, never a missing or empty attribute. Three rules draw the cross, and one more shows the menu, which the + selector finds only right after the button, inside the same parent.
Marker 1. The round menu button, now showing a cross.Avoid
<button type="button" class="burger" aria-label="Menu" aria-expanded="false" aria-controls="menu">…</button>
<nav id="menu" class="menu">…</nav>
<style>
.menu { display: none; }
.menu.is-open { display: flex; }
.burger.is-open .top { transform: translateY(6px) rotate(45deg); }
</style>
<script>
const button = document.querySelector(".burger");
const menu = document.querySelector(".menu");
button.addEventListener("click", () => {
button.classList.toggle("is-open");
menu.classList.toggle("is-open");
});
</script>Screen reader: « Menu, button, collapsed »
Correct
<button type="button" class="burger" aria-label="Menu" aria-expanded="false" aria-controls="menu">
<svg aria-hidden="true" focusable="false" width="24" height="24" viewBox="0 0 24 24">
<path class="line top" d="M3 6h18" />
<path class="line middle" d="M3 12h18" />
<path class="line bottom" d="M3 18h18" />
</svg>
</button>
<nav id="menu" class="menu">
<ul>
<li><a href="/cheeses">Cheeses</a></li>
<li><a href="/boards">Cheese boards</a></li>
</ul>
</nav>
<style>
.menu { display: none; }
.burger[aria-expanded="true"] + .menu { display: flex; }
.burger .line { stroke: currentColor; stroke-width: 2; transform-box: fill-box; transform-origin: center; }
.burger[aria-expanded="true"] .top { transform: translateY(6px) rotate(45deg); }
.burger[aria-expanded="true"] .middle { opacity: 0; }
.burger[aria-expanded="true"] .bottom { transform: translateY(-6px) rotate(-45deg); }
</style>
<script>
const button = document.querySelector(".burger");
button.addEventListener("click", () => {
const isOpen = button.getAttribute("aria-expanded") === "true";
button.setAttribute("aria-expanded", String(!isOpen));
});
</script>Screen reader: « Menu, button, expanded »
Opening the menu through the attribute goes further than the navigation example of the W3C, which publishes ARIA. That example reads the attribute in CSS only to style the button, and opens the links with JavaScript.
Leaving the hidden attribute on the menu as well sets a trap: a display rule overrides it, so a menu set to display: flex stays visible even closed. On the Larkmere demo, only the CSS hides the menu, with display: none by default. Closed, the menu drops out of the accessibility tree, and in our Chrome test, Tab skipped its five links.
Reading the attribute in CSS also changes who notices a bug. With the class version, only someone using a screen reader heard “collapsed”. On the fixed version, we commented out the setAttribute line, and a click left the menu closed, three lines still showing. The whole team now sees the mistake on the first click.
#How do you check what the button tells a screen reader?
The test takes two steps: Chrome's Accessibility tab shows the state the button passes on, then NVDA with Chrome lets you hear it. Together, they catch the attribute on the panel and the state frozen by a class, two mistakes axe-core lets through.
- In Chrome's developer tools, open the Elements panel and select the menu button.
- In the Accessibility tab, Computed Properties shows its name, role and Expanded row.
- Click the button in the page: the value should switch from
falsetotrue.
The person-shaped button at the top right of the DOM tree replaces that tree with the page's full accessibility tree. On the version with the attribute on the nav, we found a navigation row there with no state.
Marker 1. The Expanded row of the computed properties, set to true.#What should NVDA say when the menu opens?
When Tab lands on the button, NVDA says its name, role and state, “Menu, button, collapsed”, sometimes after naming the area it enters. Press Enter and it repeats neither the name nor the role: it only says “expanded”, then “collapsed” on the next press. We took these words from the W3C's screen reader tests, run with Chrome and not yet approved. The audio clips come from the eSpeak NG speech synthesizer. On a Mac, NVDA runs in a virtual machine.
From the “Cart (2)” link, focus moves to the button.
The menu opens, and focus stays on the button.
The menu closes.
Keep focus on the button when the menu opens, because NVDA doesn't report a state change on an element that has lost focus. If the script moves focus to the first link, “expanded” can get lost. NVDA's developer, NV Access, confirmed this in focus mode, where the screen reader passes almost every key to the component. Issue 12738 has been open since 2021. The W3C pattern leaves focus on the button.
Larkmere's fixed version looks the same on screen. A real button carries the state in a single attribute, which the script switches from false to true and the CSS reads to show the menu. Chrome's tree shows true, and NVDA turns it into “expanded”. The .is-open class is gone, along with the line that looked up the menu: the script now only knows about the button.
NVDA screen reader: how to install it, set it up and test a web page
To track down other elements like this div, with no role and an ARIA attribute they don't accept, the Includdy scan analyzes a page or a component. Every issue it flags comes with a test plan, steps and expected result included, that any teammate can run again.


