Expand/Collapse Widget Examples

Three approaches to expand/collapse content. Each widget is wrapped in a div.example and the controlled content container uses the details class.

Basic Toggle Button

A button toggles a content region using the hidden attribute and ARIA semantics.

Accordion (Single-open)

An accordion where only one section opens at a time. Buttons share a common group identifier.

Native details/summary

Leverages the built-in HTML <details> element with a details class applied.

Native expandable content

This uses the browser's native expand/collapse behavior. It works without JavaScript and is fully keyboard accessible by default.

Tip: You can style the summary marker and open state as shown here.