Expand / Collapse Widget

Examples of an accessible expand/collapse pattern. Each widget is wrapped with a div.example and the controlled content container uses the class "details".

Keyboard: Enter or Space to toggle
Summary of the item

This is the content revealed by the expand/collapse widget. It can contain arbitrary HTML — paragraphs, lists, images, or other UI. The container has the class "details".

  • Point one about this item
  • Point two with more context
  • Final note
Updated: 2025-11-10
Animated reveal (prefers-reduced-motion respected)

Detailed Notes

This example demonstrates a longer block of content. The JavaScript sets the details container's max-height dynamically to allow a smooth transition that matches the content height.

Resize the window while the panel is open to see the script adjust the max-height to match the new content flow.

  1. Step one: preview the content
  2. Step two: interact with it
  3. Step three: close when done