Expand/Collapse Widgets

Examples using native HTML details and custom JavaScript-driven toggles. Each widget is wrapped with an element that has class "example", and the container for controlled content uses class "details".

Native HTML details

Uses <details> and <summary>
What is an expand/collapse widget?

An expand/collapse widget is a UI control that reveals additional content on demand. The native HTML <details> element provides built-in accessibility and keyboard interaction.

  • Click or press Enter/Space on the summary to toggle.
  • The widget maintains its open/closed state per instance.
  • No JavaScript required for basic interaction.

Custom toggle button

ARIA attributes control a content region

Accordion (single-open)

Only one section open at a time

Native details (default open)

Starts expanded
Default open example

You can start a native <details> element in the open state using the open attribute. Click the summary to collapse it.

Tip: Try keyboard interaction. For custom widgets, the button toggles the hidden attribute on the associated .details container and updates aria-expanded.