StealThis .dev

Collapsible

A smooth expanding/collapsing content section with animated height transitions. Uses the CSS grid-template-rows trick for true 0-to-auto height animation.

Open in Lab
css javascript vue svelte
Targets: TS JS HTML React Vue Svelte

Code

Collapsible

A smooth expanding/collapsing content section that animates between zero and auto height. Uses the CSS grid-template-rows: 0fr / 1fr technique for a true height transition without JavaScript measurements or max-height hacks.

How it works

  1. The collapsible content is wrapped in a grid container.
  2. grid-template-rows: 0fr collapses the content to zero height.
  3. Toggling to 1fr smoothly expands to the content’s natural height.
  4. The inner wrapper uses overflow: hidden to clip during the transition.

Features

  • True 0-to-auto height animation via CSS grid
  • Animated chevron rotation
  • Multiple independent collapsibles
  • Keyboard accessible trigger button
  • Respects prefers-reduced-motion