Definition
An Accordion is a group of interactive headings with corresponding sections of content that are stacked vertically. Typically, these are used to reduce the amount of vertical space that the content occupies, which limits the amount of scrolling needed to bypass that content.
Each group in an Accordion is composed of two parts: an Accordion Header and an Accordion Panel. The Accordion Header describes the content of its associated Accordion Panel as well as controls showing and hiding that content. The Accordion Panel contains content that relates to the Accordion Header. Commonly, only one Accordion Panel is open or “expanded” at any given time.
A common use case for Accordions would be a Frequently Asked Questions (FAQ) section where each question is an Accordion header and the answer to that question is in the Accordion panel.
Focus Expectations
Accordion Headers have visible focus states
Semantic Elements
headingelements (e.g.<h2>,<h3>)buttonelement (e.g.<button>)
ARIA Roles and Attributes
Accordion Header
- The title is contained in a
buttonelement - The
buttonis wrapped in aheadingelement - The
buttonelement is the only element inside theheadingand any other content in the Accordion Header must be outside theheadingelement - The
buttonelement must havearia-expandedset totruewhen the associated Accordion Panel is visible otherwisearia-expandedmust befalse - The
buttonelement must havearia-controlsset to theidof the element containing the Accordion Panel’s content
Accordion Panel
- The element containing the Accordion Panel’s content must have a unique
id - Optionally, use the “region” role with
aria-labelledbyset to theidof the associated Accordion Header’sbuttonelement as this helps provide structure to screen readers (but too many regions can defeat the purpose)
Keyboard Interactions
- When focused on an Accordion Header
- Enter or Space: collapses or expands the related Accordion Panel
- Down Arrow or Up Arrow (optional): cycles focus through Accordion Headers
- Home (optional): moves focus to the first Accordion Header
- End (optional): moves focus to the last Accordion Header
- Tab: moves focus to the next focusable element
- Shift + Tab: moves focus to the previous focusable element