Accessible Expand/Collapse Widgets

These examples showcase two different approaches to building an expand/collapse interaction using semantic markup, WAI-ARIA attributes, and a touch of JavaScript to synchronize state. Each widget is wrapped in an example container and the controlled regions share the details class for styling.

Basic Expand/Collapse Panel

A single button reveals and hides additional content. The button updates its label dynamically and keeps the controlled region in sync with aria-expanded.

Accordion with Single-Open Behavior

This accordion demonstrates how to coordinate multiple toggles. Opening one panel closes the rest, ensuring only a single section is visible at any time.

Each accordion header is a button. A shared data-group attribute enforces single-open behavior by closing siblings on interaction.

  1. Click any header to expand its content.
  2. Focus indicators make navigation clear for keyboard users.
  3. State changes update aria-expanded and the toggle label.