Accessibility Examples: Navigation Menus

Collapsible Menu with Toggle Button

Required HTML Markup

A menu toggle must indicate whether its associated menu is expanded or collapsed. This requires the following ARIA attributes:

Below is a code snippet showing simplified markup for implementing an accessible menu toggle button. The values of the aria-expanded and the aria-hidden attributes are shown for the collapsed state.

<button aria-expanded="false" aria-haspopup="true" aria-controls="menu-id">Toggle Menu</button>     
<ul id="menu-id" aria-hidden="true">
   . . .
</ul>
   

Here is the snippet with the menu in the expanded state:

<button aria-expanded="true" aria-haspopup="true" aria-controls="menu-id">Toggle Menu</button>     
<ul id="menu-id" aria-hidden="false">
   . . .
</ul>
   

JavaScript is needed to toggle the values of the aria-expanded and aria-hidden attributes. Note that the values of aria-controls and aria-haspopup do not change.

Note: The aria-hidden attribute is not needed in modern browsers. Using display: none or visability: hidden is sufficient. The attribute is included here for illustrative purposes.

Interaction Pattern