Expand/Collapse Widgets

Examples of both native and custom expand/collapse interactions. Each widget is wrapped in a container with the class “example”, and the controlled content container uses the class “details”.

Native HTML Details

Uses the built-in <details> and <summary> elements.

What is an expand/collapse widget?

An expand/collapse widget toggles the visibility of additional content. The native <details> element is an accessible, semantic solution provided by HTML.

  • Keyboard-accessible by default
  • Works without JavaScript
  • Can be nested or grouped

Try clicking the summary line above or pressing the Enter or Space keys when it’s focused.

Custom Button Toggle

A button controls a separate region. ARIA properties convey state.

FAQ Group (Multiple Expanders)

Multiple independent sections using native details elements.

Can I open more than one section at a time?

Yes. Each <details> element is independent, so you may open multiple sections simultaneously.

Should I use native details or a custom button?

Prefer native <details> for simple disclosure patterns. Use a custom button when you need bespoke behavior or styling beyond what <details> offers.

How do I make custom toggles accessible?
  • Use an actual <button> element
  • Update aria-expanded correctly
  • Relate the button and region via aria-controls and aria-labelledby
  • Manage focus appropriately