Course contentsShow
← Web Development
Lesson 1164 of 2,98221. Accessible ComponentsFree lesson

Menu Button Semantics and ARIA

Implementing button role, aria-haspopup, aria-expanded, and aria-controls for accessible menu buttons.

Menu Button Semantics and ARIA

What You'll Learn

You'll learn how to properly mark up a button that opens a menu using the correct ARIA attributes so screen readers announce it correctly.

The Core Idea

A menu button is a button that, when clicked, reveals a menu of options (like a dropdown navigation or kebab menu). To make this accessible, you need to communicate three things to assistive technology:

  1. It's a button – Use <button> or add role="button"
  2. It opens a menu – Use aria-haspopup="true" (or "menu")
  3. Whether the menu is open or closed – Use aria-expanded="true" or "false"
  4. Which element it controls – Use aria-controls with the menu's ID

The Semantic Pattern

<button
  aria-haspopup="true"
  aria-expanded="false"
  aria-controls="menu-dropdown"
>
  Menu ▾
</button>

<ul id="menu-dropdown" role="menu" hidden>
  <li role="menuitem">Profile</li>
  <li role="menuitem">Settings</li>
  <li role="menuitem">Logout</li>
</ul>

What Each Attribute Does

  • aria-haspopup="true" announces "This button opens something" (use "menu" for specificity)
  • aria-expanded="false" announces "The thing is currently closed" (toggle to "true" when open)
  • aria-controls="menu-dropdown" links the button to the menu element by ID

When you click the button, JavaScript should toggle aria-expanded and the hidden attribute on the menu.

Think of it like a door sign: aria-haspopup says "door exists here," aria-expanded tells you if it's open or closed, and aria-controls points to which door.

Key Takeaway: Use <button> with aria-haspopup, aria-expanded, and aria-controls to create menu buttons that screen readers can properly understand and announce.