Expand / Collapse Widget Examples

Each widget is wrapped with a container having class="example". The controlled content container uses class="details".

Native <details> element

This uses the built-in browser widget. The content container below has class="details".

Show basic details

The native <details> element provides expand/collapse functionality without custom scripting. Use it when you want a simple, accessible disclosure. Styling is limited by the browser, but it's robust.

  • Automatic keyboard support (Enter / Space).
  • State reflected via the "open" attribute on the details element.

Custom button-controlled panel

A simple accessible widget controlled by a button. The content container uses class="details".

Smooth animated expand/collapse

A slightly more advanced widget that animates the height for a smooth transition. The container has class="details".