This is an illustrative example of one way of using ARIA that conforms with the ARIA specification.
- There may be support gaps in some browser and assistive technology combinations, especially for mobile/touch devices. Testing code based on this example with assistive technologies is essential before considering use in production systems.
- The ARIA and Assistive Technologies Project is developing measurements of assistive technology support for APG examples.
- Robust accessibility can be further optimized by choosing implementation patterns that maximize use of semantic HTML and heeding the warning that No ARIA is better than Bad ARIA.
About This Example
Important
Although this example uses the word "menu" in the colloquial sense to refer to a set of navigation links, it does not use the WAI-ARIA menu role. This implementation of site navigation does not use the menu role because it does not provide the complex functionality that assistive technologies expect in a widget that has the menu role. Typical site navigation does not need all the keyboard interactions specified by the menu and menubar pattern.
The following example demonstrates using the Disclosure Pattern to show and hide dropdown lists of links in a navigation bar for a mythical university web site. Each disclosure button represents a section of the web site, and expanding it shows a list of links to pages within that section.
Similar examples include:
- Example Disclosure (Show/Hide) for Answers to Frequently Asked Questions
- Example Disclosure (Show/Hide) for an Image Description
- Example Disclosure Navigation Menu with Top-Level Links
- Disclosure (Show/Hide) Card
- Navigation Menubar Example
Example Usage Options
This example demonstrates two different ways of implementing keyboard support. Toggle between them with the following checkbox.
Include optional support for arrow keys, Home, and EndMythical University
Sample content section. Activating a link above will update and navigate to this region.
Accessibility Features
- Since this set of disclosure buttons controls visibility of navigation links for the mythical university web site, the list that contains them is wrapped in a navigation landmark named
Mythical University
. - The semantics of the list structure communicates the hierarchy of the navigation system to assistive technology users. The top-level set of three buttons is in a list of three items, and the set of links controlled by each button is contained within a list nested inside the item with the controlling button.
- If a dropdown is open and focus is inside the navigation region, pressing Esc will close the dropdown. Moving focus out of the navigation region also closes an open dropdown. Implementing this Esc behavior is necessary to meet the WCAG 2.1 1.4.13: Content on Hover or Focus criterion.
- The visual indicator of the show/hide state is created using CSS
::afterpseudo element border styles so the caret is reliably rendered in high contrast mode of operating systems and browsers. -
Optional navigation keys (Arrow keys, Home, and End):
- Implementing the optional arrow key support prevents the default page scroll behavior when focus is contained within the navigation region.
- Optional navigation key support is primarily for the benefit of keyboard users who are not running a screen reader. Screen readers that have both reading and interaction modes intercept these navigation keys and do not pass them to the page when the screen reader is in reading mode. When interacting with this example, such screen readers are typically in reading mode because this example does not use a widget role that triggers screen reader interaction mode.
-
If implemented, the optional navigation keys supplement, but do not replace, tabbing among buttons and links.
This is because the buttons and links are not contained by an element with a widget role, such as
grid, that is expected to occupy only one stop in the page Tab sequence and manage focus for all its descendants.
Keyboard Support
| Key | Function |
|---|---|
|
Tab Shift + Tab |
Move keyboard focus among top-level buttons, and if a dropdown is open, into and through links in the dropdown. |
|
Space or Enter |
|
| Escape | If a dropdown is open, closes it and sets focus on the button that controls that dropdown. |
|
Down Arrow or Right Arrow (Optional) |
|
|
Up Arrow or Left Arrow (Optional) |
|
| Home (Optional) |
|
| End (Optional) |
|
Role, Property, State, and Tabindex Attributes
| Role | Attribute | Element | Usage |
|---|---|---|---|
aria-controls="IDREF"
|
button
|
The disclosure button controls visibility of the container identified by the IDREF value. |
|
aria-expanded="false"
|
button
|
|
|
aria-expanded="true"
|
button
|
|
|
aria-current="page"
|
a
|
Indicates that the page referenced by the link is currently displayed. |
Assistive Technology Support
Learn how to interpret and use assistive technology support data
JavaScript and CSS Source Code
- CSS: disclosure-navigation.css
- JavaScript: disclosureMenu.js
HTML Source Code
To copy the following HTML code, please open it in CodePen.