CSS interpolate-size: Animate From 0 to auto

An expanding panel knows its natural height. CSS traditionally could not animate to it, which is why such a small interaction produced so many max-height tricks and JavaScript measurements. This looks like it should work:

.panel {
  height: 0;
  transition: height 300ms;
}

.panel.open {
  height: auto;
}

But browsers traditionally could not smoothly animate between 0 and auto. Developers worked around it with JavaScript, large max-height values, or transforms. The newer interpolate-size property is designed to solve this.

There is one important warning: browser support is still not complete everywhere in 2026, so I would use it as progressive enhancement rather than making an important interface depend on it.

Compare immediate and animated auto height
View code
HTML
<button id="toggle" type="button" aria-expanded="false" aria-controls="plain smooth">Expand panels</button>
<h2>Default interpolation</h2><div id="plain" class="panel"><p>The panel follows its content height. Add more text and the open height can grow naturally.</p></div>
<h2>interpolate-size: allow-keywords</h2><div id="smooth" class="panel smooth"><p>The panel follows its content height. Add more text and the open height can grow naturally.</p></div>
<p id="support" class="note">Both panels open. Animation depends on browser support and motion preferences.</p>
CSS
button, select { padding: .35rem .6rem; border: 1px solid var(--clg); background: var(--cw); color: var(--cb); }
input[type="range"] { width: min(100%, 18rem); vertical-align: middle; }
h2, h3 { font-size: 1rem; }
.note { color: var(--clg); }

.panel { height: 0; overflow: clip; transition: height 700ms ease; background: var(--cg); }
.panel p { padding: 1rem; margin: 0; }
.panel.open { height: auto; }
.smooth { interpolate-size: allow-keywords; }
JavaScript
const button = document.querySelector('#toggle');
button.addEventListener('click', () => {
  const open = button.getAttribute('aria-expanded') !== 'true';
  button.setAttribute('aria-expanded', String(open));
  button.textContent = open ? 'Collapse panels' : 'Expand panels';
  document.querySelectorAll('.panel').forEach(panel => panel.classList.toggle('open', open));
});
if (!CSS.supports('interpolate-size', 'allow-keywords')) document.querySelector('#support').textContent = 'This browser does not support interpolate-size. Both panels still open without the enhanced transition.';

Why height: auto did not animate

Imagine an expandable section:

<div class="panel">
  <p>
    This content can be short or long.
  </p>
</div>

You do not know the exact height because the content can change. That is why auto is useful. Historically:

0px → 200px

was easy to animate.

0px → auto

was not.

The new approach

You can allow intrinsic sizes to be interpolated:

:root {
  interpolate-size: allow-keywords;
}

Then:

.panel {
  height: 0;
  overflow: hidden;
  transition: height 300ms ease;
}

.panel.open {
  height: auto;
}

In supporting browsers, the browser can animate between the numeric height and the natural auto size.

Why set it on :root?

interpolate-size is inherited.

You can enable it once:

:root {
  interpolate-size: allow-keywords;
}

or only for one component:

.accordion {
  interpolate-size: allow-keywords;
}

The old max-height trick

A common workaround is:

.panel {
  max-height: 0;
  overflow: hidden;
  transition: max-height 300ms;
}

.panel.open {
  max-height: 1000px;
}

It works, but 1000px is just a guess. If the content is taller, it breaks. If the content is much shorter, the timing can feel strange.

The browser is technically animating toward 1000 pixels even when the real content is only 180 pixels tall.

The JavaScript workaround

Another method measures the element:

panel.style.height = `${panel.scrollHeight}px`;

This works, but JavaScript now needs to measure layout and keep track of size changes. If CSS can animate to the natural size directly, there is less code.

Use <details> when possible

Before building a custom accordion, ask whether HTML already has what you need:

<details>
  <summary>More information</summary>
  <p>Content goes here.</p>
</details>

For a normal FAQ or disclosure section, <details> is often the better starting point.

interpolate-size is more interesting for custom components and layout transitions.

A safe fallback

Because support is still limited, keep the base experience working.

.panel {
  height: auto;
}

@supports (interpolate-size: allow-keywords) {
  .panel {
    height: 0;
    overflow: clip;
    transition: height 250ms;
    interpolate-size: allow-keywords;
  }

  .panel.open {
    height: auto;
  }
}

In an older browser, the content simply remains visible. That is not the exact same design, but it remains usable.

Respect reduced motion

@media (prefers-reduced-motion: reduce) {
  .panel {
    transition: none;
  }
}

This is a good habit for any motion added only for visual polish.

Where it can help

Good uses include:

I would not use it only because it is new. The best use is when it lets you remove a brittle workaround.

Keep the content and open state working everywhere, then add the smoother size transition where supported. I would use interpolate-size when it replaces a brittle size-measuring workaround.

Last updated on and filed under and .