Transition an element to its natural height in CSS

Several CSS techniques animating an element between its closed and natural height

Smooth height transitions are possible in CSS.

Animating from height: 0 to height: auto has traditionally been awkward because the browser could not interpolate an intrinsic size.

There are several ways to handle it:

  • A fixed max-height, which is simple but requires a guessed upper limit.
  • A transform, which looks smooth but does not move surrounding content.
  • CSS Grid with a row transitioning from 0fr to 1fr.
  • interpolate-size: allow-keywords, which allows transitions to intrinsic sizing keywords such as auto.
  • calc-size(), which lets calculations work with intrinsic sizes.

The Grid method is the most practical fallback when surrounding content needs to move. interpolate-size and calc-size() are cleaner, but they still need progressive enhancement because browser availability is limited.

I cover all five approaches with interactive examples in the full article:

https://theosoti.com/blog/height-transition/

You Don’t Need JavaScript ebook mockup

I wrote a guide about building modern UI with HTML and CSS first. It covers practical patterns you can use before reaching for JavaScript.

Learn more

    No strings attached, unsubscribe anytime!

    Other short articles you might like

    Explore more articles on front-end development, covering HTML, CSS and JavaScript for building high-performance websites.