Expand/Collapse Widgets

This page showcases different approaches to building accessible expand/collapse interactions using semantic HTML, ARIA attributes, and progressive enhancement.

1. Native <details> Element

What is an expand/collapse widget?

An expand/collapse widget—also known as a disclosure widget—reveals additional information when requested by the user. The native <details> element automatically handles keyboard and mouse interaction, and browsers map it to the correct accessibility roles.

  • Keyboard toggle via Space or Enter
  • Accessible name taken from the <summary>
  • No extra JavaScript required

2. Custom Toggle Button

This example uses a regular button to control a region of content. A small script synchronizes the button’s aria-expanded attribute with the content’s visibility.

3. Accordion Pattern

This accordion allows only one section to be open at a time. It uses buttons, ARIA attributes, and JavaScript to coordinate the expanded state.

Maintain a clear visual hierarchy, provide sufficient interactive affordance, and ensure that content remains readable whether the section is collapsed or expanded.