Expand/Collapse Widgets

Three examples below show different ways to create expand/collapse behavior. Each widget is wrapped with div.example, and the container for the controlled content uses the details class.

Example 1: Native HTML details/summary

Click to expand: About this demo

This uses the built-in HTML <details> element for accessible expand/collapse. No JavaScript is required.

  • The container for the controlled content is details.details.
  • The summary acts as the toggle control.
  • Keyboard and screen-reader behavior are handled by the browser.

Tip: You can nest content, include images, or any markup within a details element.

Example 2: Button-controlled content

Example 3: Accordion (only one section open)