Expand/Collapse Widgets

Three approaches: native details/summary, a JS-powered toggle, and an accordion. Each widget is wrapped in an element with class "example", and the container for the controlled content has class "details".

Native details/summary

This uses the built-in HTML details and summary elements. It's accessible, keyboard-friendly, and doesn’t require JavaScript.

  • Click or press Space/Enter on the summary to toggle.
  • Works across modern browsers.
  • Supports nested content and styling.

Tip: Use this when you want the simplest solution.

This pattern is useful when you need to control multiple panels or coordinate with other UI states.

This accordion ensures only one panel is open at a time for a compact layout.