Expand/Collapse Widgets

Three examples demonstrating native and custom expand/collapse patterns. Each widget is wrapped in an element with class "example", and the container for controlled content uses class "details".

Native details/summary

Uses the built-in HTML <details> element. The controlled container is the details element with class details.

What is an expand/collapse widget?

An expand/collapse widget reveals additional content on demand. This native widget is keyboard accessible and toggles with the Space or Enter keys on the summary.

  • Uses semantic HTML.
  • No JavaScript required for basic behavior.
  • State is reflected via the open attribute.

Custom toggle button

A button controls a separate region. The controlled container is a div with class details.

Pre-opened section

Starts expanded by default via the open attribute. The controlled container is the details element with class details.

Helpful resources