Expand/Collapse Examples

This is the content for the first section. It is hidden by default. The implementation uses semantic HTML buttons and ARIA attributes to ensure screen readers understand the relationship between the trigger and the content.

The transition effect is achieved using CSS Grid to animate height from 0 to auto seamlessly.

  • Button element: Used for keyboard focus and native click handling.
  • aria-expanded: Indicates the state (open/closed) to assistive technology.
  • aria-controls: Connects the button to the content panel ID.
  • aria-labelledby: Connects the panel back to the button title.
  • role="region": Defines the content area as a landmark.

You can customize the styling of the trigger and the content panel easily. The JavaScript is generic and relies on data attributes or class names rather than specific IDs for logic.

Focusable link inside content