Expand/Collapse Widgets

This page demonstrates a native HTML details element and custom button-controlled sections. Each widget is wrapped with a container that has the "example" class, and the controlled content container has the "details" class.

Native details/summary widget

How does the native widget work?

The <details> element provides built-in expand/collapse behavior across modern browsers. Clicking the summary toggles the open state.

  • No JavaScript required.
  • Keyboard accessible out of the box.
  • Use CSS to style the summary and content.

Learn more in the MDN docs: MDN <details>.

Custom button-controlled widget

Another custom widget

Group controls

Use these controls to expand or collapse all custom widgets above. The native <details> widget remains independent.