StealThis .dev

Spring Accordion

An accordion component with a spring-like open/close animation. Uses CSS grid-template-rows trick for smooth height transitions — no max-height hacks.

Open in Lab
css vanilla-js css-grid transition
Targets: JS HTML React Native

Expo Snack

Code

Spring Accordion

An accordion that uses the CSS grid-template-rows: 0fr / 1fr trick to animate from zero to auto height — no max-height hacks, no JavaScript height measurements. The spring feel comes from a custom cubic-bezier easing curve.

How it works

The panel content is wrapped in two elements:

<div class="panel" aria-hidden="true">   <!-- grid rows transition here -->
  <div class="panel-inner">…</div>       <!-- overflow: hidden here -->
</div>

Toggling an open class switches grid-template-rows between 0fr and 1fr. The cubic-bezier(0.34, 1.56, 0.64, 1) curve gives a slight overshoot — the spring feel.

Features

  • Smooth 0 → auto height animation with no JS measurements
  • Single open at a time (closes others on open)
  • Animated chevron rotation
  • aria-expanded + aria-hidden for accessibility

When to use it

  • FAQ sections
  • Settings panels
  • Mobile navigation menus