Expand/Collapse Widgets

Three approaches: native details/summary, a basic button-controlled panel, and a panel with smooth open/close animation.

Example 1: Native details/summary

What is an expand/collapse widget?

An expand/collapse widget (also called a disclosure) shows or hides additional information on demand. The native HTML element <details> with a <summary> provides built-in accessibility and keyboard support.

  • Click or press Enter/Space to toggle.
  • Screen readers announce the expanded state.
  • No JavaScript required for basic behavior.

The container for the controlled content has a details class.

Example 2: Button-controlled panel

The content container uses the class details and starts hidden.

Example 3: Smooth animated panel

The animated wrapper manages the transition; the content itself remains a details-class container.