Expand/Collapse Widgets

Examples of native and custom expand/collapse patterns. Each widget is wrapped in a div with class "example", and controlled content uses the "details" class.

Native
element

This uses the built-in HTML <details> element with a <summary> trigger.

What is an expand/collapse widget?

An expand/collapse widget lets users reveal or hide additional content on demand. The native <details> element provides this behavior without custom JavaScript.

  • Keyboard accessible out of the box
  • Semantic and easy to style
  • Works across modern browsers

Custom toggle with a button

This example uses a button with aria-expanded and aria-controls to manage a collapsible region.

Accordion (single section open)

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