Height auto animation

Also called animate height auto or expand and collapse animation

An animation that opens or closes a panel to the exact height of its content, even though that height is unknown ahead of time.

What is Height auto animation?

Accordions, “Show more” sections, and expandable rows all need to grow from zero to however tall their content happens to be. For years CSS could not transition between height: 0 and height: auto, because auto is not a number, so the panel snapped open even with a transition set.

There are a few reliable fixes. Animate a grid row from grid-template-rows: 0fr to 1fr, with an inner wrapper set to overflow: hidden and min-height: 0; this works in all modern browsers. Motion can animate to height: "auto" directly by measuring the content for you. Chromium-based browsers also support interpolate-size: allow-keywords, which lets plain CSS transitions reach auto.

Keep it between about 200 and 300ms with an ease-out curve, and fade the content in slightly as the panel opens. Avoid the old trick of animating max-height to a large number: the timing feels off because the animation runs toward the large value instead of the real height.

Often confused with

Layout animation
Layout animation moves and resizes any element after a layout change. Height auto animation grows one container to fit content of unknown height.
All terms

Accordion

A vertical stack of headings that each expand to reveal their content when clicked, so long pages stay short and easy to scan.

Layout animation

An animation that smoothly moves and resizes elements when the layout changes, such as list items gliding to new spots after a sort or filter.

Ease-out

An easing curve that starts fast and slows down at the end, so motion feels quick and lands softly.

Reduced motion

An operating system setting that asks apps to minimize movement, which websites detect with the prefers-reduced-motion media query.