Expand/Collapse Widget Examples

Three approaches: native details/summary, a button-controlled disclosure, and an accordion with a single open section. Each controlled content area uses the "details" class.

Example 1: Native details/summary

Uses the built-in HTML details element. Click the summary row to expand/collapse.

What is an expand/collapse widget?

An expand/collapse widget lets you reveal additional content on demand without navigating away from the page. It helps keep interfaces clean and focused.

  • Expandable content stays hidden until requested
  • Reduces visual clutter
  • Improves scannability of long pages

Tip: The <details> element is keyboard and screen-reader friendly by default.

Example 2: Button-controlled disclosure

A button toggles a content region. The button updates aria-expanded and controls a container with the details class.

Example 3: Accordion (single open)

Only one section stays open at a time. Each panel’s content container uses the details class.