Accordion
An accordion list uses an HTML description list to group togglable elements together.
Description terms can be toggled independently by using the individual toggle buttons or all together by using the open/close all button.
Each <dt> contains a <button> element that is used to toggle the contents of the corresponding <dd> element. In order to link these two elements:
- Each button must have an
idattribute with a unique value. - Each
<dd>must have anaria-labelledbyattribute whose value matches the corresponding buttonid.
- This is the content of the accordion.
- This is the content of the accordion.
- This is the content of the accordion.
<button class="cmp-button cmp-accordion-toggle-all js-toggle-all" aria-controls="sample-list" aria-hidden="true"> Open All</button><dl id="sample-list" class="cmp-accordion"> <dt> <button id="item1" class="cmp-accordion__button js-toggler" aria-expanded="true" > Accordion One </button> </dt> <dd class="cmp-accordion__content" aria-labelledby="item1" aria-hidden="false" > This is the content of the accordion. </dd> <dt> <button id="item2" class="cmp-accordion__button js-toggler" aria-expanded="true" > Accordion Two </button> </dt> <dd class="cmp-accordion__content" aria-labelledby="item2" aria-hidden="false" > This is the content of the accordion. </dd> <dt> <button id="item3" class="cmp-accordion__button js-toggler" aria-expanded="true" > Accordion Three </button> </dt> <dd class="cmp-accordion__content" aria-labelledby="item3" aria-hidden="false" > This is the content of the accordion. </dd></dl>Accessibility
Section titled “Accessibility”- Each toggle button uses
aria-expandedto communicate whether its panel is open or closed. - Each
<dd>panel usesaria-labelledbyto associate it with its corresponding<dt>button. - The Open All / Close All button toggles every panel and updates all
aria-expandedstates accordingly. - Keyboard: Users can tab to each accordion button and activate it with Enter or Space. When a panel is open, tabbable content inside it is reachable in the natural tab order.
- Toggle buttons are native
<button>elements, so they receive focus styles and are announced as buttons by screen readers.