Accordion
A series of expanding/collapsing panels of content.
Last updated
Was this helpful?
A series of expanding/collapsing panels of content.
Last updated
Was this helpful?
Allows vertical stacking of content panels. Each panel is separated by an interactive panel header. Zero or more panels can be open at any time.
Often used in sidebars and navigation menus for the progressive disclosure of links and filters.
The accordion pattern is a composite pattern; each item in the accordion is a disclosure widget.
You can take a look at the accordion pattern in action on our .
You can get an idea of the required markup structure by viewing our .
We use the following terminology when discussing this pattern.
accordion: the pattern as a whole, comprised of the following sub-parts
panel: each panel in the accordion is a disclosure widget
header: each panel displays an interactive summary of the panel contents
heading: each header contains a nested heading level element
auto-collapse: an accordion that automatically collapses other open panels when a new panel is opened
Each header will be in the natural tabindex, courtesy of the details pattern. This natural tabindex must not be removed or tampered with.
By default, all panels can be in an open, expanded state.
Optionally, the accordion may be restricted to only show one content panel at a time (i.e. opening a panel will close any other open panel). This is known as an auto-collapsing accordion. Note that auto-collapse on accordion should be used cautiously, as it prevents users from comparing content and may disrupt the user experience.
This section provides detailed instructions for how different input types should navigate and operate the pattern.
Pressing TAB key must move keyboard focus from one header to the next. It will also move focus through any interactive elements inside open panels.
Likewise, pressing SHIFT-TAB keys moves focus backwards through headers and interactive panel content.
Pressing SPACEBAR or ENTER key on a header with keyboard focus must open the panel. For auto-collapse accordions, any other open panel must close.
Virtual cursor must be able to move from one header to the next.
With virtual cursor on header, it must be able to open panel via click event simulation. For auto-collapse accordions, any other open panel must close, but this should not be announced.
Tapping or clicking a header must open the related content panel. For auto-collapse accordions, any other open panel must close.
The accordion pattern makes heavy use of the details.
The structure is a list of details widgets. Note that in some browsers the implicit list role is removed when CSS list-style-type: none
is applied. To hide the list item markers, use the ::marker
pseudo-element .
To address the issue in some browsers where the implicit list role is removed with list-style-type
, the following CSS can be applied to hide the list item markers. Beyond this, accordion headers and panels can be styled as desired.
For accordions that allow all panels to be open at once, no scripting is necessary; each nested details widget will handle the open and close mechanics.
For accordions limited to a single open panel, the name
attribute allows multiple <details>
elements to be linked, ensuring only one is open at a time. This approach effectively eliminates the need for JavaScript.
On older browsers that do not yet support the name
attribute, the JavaScript steps can be briefly summarized as the following:
Find each nested details element
Listen to toggle event of each details element
When receiving a toggle event, if the details state has moved from closed to open, close all other details elements
That's it. Pretty straightforward. You can reference our .
aria-roledescription: defines a human-readable, author-localized description for the of an . In this case, "accordion".