aria-expanded aria-controls for Toggles
Build accessible disclosure and accordion widgets with ARIA.
Toggle Pattern Overview
Toggle controls (accordions, dropdowns, menus) need ARIA to communicate their open/closed state:
aria-expanded— indicates open/closed state of a controlaria-controls— links the control to the element it controls
aria-expanded
aria-expanded communicates whether a controlled element is expanded or collapsed:
<button aria-expanded="false" aria-controls="menu">
Menu
</button>
<ul id="menu" hidden>
<li><a href="/">Home</a></li>
</ul>
<script>
btn.addEventListener('click', () => {
const expanded = btn.getAttribute('aria-expanded') === 'true';
btn.setAttribute('aria-expanded', !expanded);
menu.hidden = expanded;
});
</script>All lessons in this course
- aria-expanded aria-controls for Toggles
- aria-selected and Tab Patterns
- Live Regions aria-live aria-atomic aria-relevant
- Testing with Screen Readers