Accessibility Library

Accordion

An accordion is a vertically stacked set of interactive headings that each contain a title, content snippet, or thumbnail representing a section of content. The headings function as controls that enable users to reveal or hide their associated sections of content. Accordions are commonly used to reduce the need to scroll when presenting multiple sections of content on a single page.

Aria attributes

Accordions Description
aria-expanded Set to true when the Accordion panel is expanded, otherwise set to false.
aria-controls Points to the ID of the panel which the header controls.
aria-disabled If the accordion panel is expanded and is not allowed to be collapsed, then set to true.
aria-labelledby
  • Defines the accessible name for the region element.
  • References the accordion header button that expands and collapses the region.
  • region elements are required to have an accessible name to be identified as a landmark.

Live Example

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Code sample


<div id="accordion" class="Accordion">
  <h3>
    <button class="Accordion-trigger" aria-expanded="true" aria-controls="section1" aria-disabled="true" id="accordion1">
      <span class="Accordion-title">First</span>
      <span class="Accordion-icon"></span>
    </button>
  </h3>

  <div id="section1" class="Accordion-panel" aria-labelledby="accordion1" role="region">
    <span>
      Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
    </span>
  </div>

  <h3>
    <button class="Accordion-trigger" aria-expanded="false" aria-controls="section2" id="accordion2">
      <span class="Accordion-title">Second</span>
      <span class="Accordion-icon"></span>
    </button>
  </h3>

  <div id="section2" class="Accordion-panel" aria-labelledby="accordion2" role="region" hidden>
    <span>
      Dui nunc mattis enim ut. Sodales ut etiam sit amet nisl. Bibendum ut tristique et egestas quis ipsum suspendisse ultrices gravida. Volutpat sed cras ornare arcu dui. Egestas integer eget aliquet nibh praesent tristique magna. Neque gravida in fermentum et sollicitudin ac. Maecenas ultricies mi eget mauris pharetra et ultrices neque. Vulputate eu scelerisque felis imperdiet proin. Id donec ultrices tincidunt arcu non sodales neque sodales ut. Tempor nec feugiat nisl pretium fusce id velit.
    </span>
  </div>
</div>