Related Tips and Techniques: Mobile Menus
Status: This is not ready for detailed review. It is an in-progress, unapproved editor’s draft.
In mobile navigation a single button is often used to expand and collapse a set of navigation links. When the button is activated, a menu appears visually adjacent to the button. It’s also important to ensure that the expanded content is easily discoverable by keyboard-only and screen reader users.
Step 1: Create a Button to Display and Hide the Menu
For the control to show and hide the menu, use a button with a valid name.
Step 2: Convey the State of the Menu
There are multiple ways to describe whether the menu is expanded or collapsed. The aria-expanded attribute conveys this information to assistive technology users.
Step 3: Make the Menu Contents Discoverable
When the menu is open, users should be able to easily discover the new content. Two techniques can be used to aid discovery.
-
The
aria-controls
attributeThis attribute semantically ties the button to the area it controls. Assistive technologies that support the attribute will allow users to jump straight to this area.
-
Menu placement
To make the new content easily discoverable for assistive technologies that don’t support aria-controls, place the menu contents immediately after the button. This allows screen reader users and keyboard-only users to find the new content when they navigate to the next item in the page.
Step 4: Define the Entire Menu as a Navigational Area
To describe the function of the entire menu system, wrap the entire structure with a navigation element that contains a label describing its function.
Make the expanded menu the next item in the DOM after the button that expands and collapses it. On the button that controls the menu’s visibility, use aria-expanded to indicate if the menu is expanded and use aria-controls to point to the expanded content.