This note has an interactive demo. Try it in the original
height: 0 to height: auto can finally be a real CSS transition, and it takes one line: interpolate-size: allow-keywords. Chrome and Edge have had it since version 129, and Safari Technology Preview 254 just added both interpolate-size and calc-size(). That makes this a good moment to learn it properly.
Flip the switch in the demo above and open the card. The CSS doesn't change, only that one property, and you can watch the live block-size meter go from one jump to a few dozen frames.
Why this was impossible
A transition needs two values the browser can blend. 0 and 300px work. 0 and auto don't, because auto isn't a number, it's an instruction ("work out the size from the content"). So the browser snapped straight to the end.
We all worked around it. One fix was max-height: 1000px, a guess that either cut off long content or made the animation start late. The other was measuring scrollHeight with JavaScript and animating to that number. interpolate-size moves that job into the browser.
How it works
interpolate-size has two values. The initial one is numeric-only, which keeps the old behaviour. allow-keywords lets the browser interpolate between a length or percentage and an intrinsic size keyword: auto, min-content, max-content, fit-content, or content for flex-basis. It's inherited, so you usually set it once:
:root {
interpolate-size: allow-keywords;
}
From there, a normal transition does the rest. This is the "Show more" panel from the demo:
.more {
overflow: clip;
block-size: 0;
visibility: hidden;
transition: block-size .6s cubic-bezier(.22, 1, .36, 1), visibility .6s;
}
.post.open .more {
block-size: auto;
visibility: visible;
}
The visibility part matters. Collapsing to zero height hides the text only visually: a screen reader still reads it and its links stay in the tab order. visibility: hidden takes it out of both, and because visibility is in the transition, the content stays visible until the panel has finished closing.
Why opt in instead of on by default? MDN and the Chrome team give the same reason: plenty of existing stylesheets assume that a change to auto doesn't animate, and turning it on everywhere would break them.
calc-size(): maths on intrinsic sizes
Sometimes you want "the natural height, but no more than X". calc() can't take auto, so there is a new function: calc-size(basis, calculation). The first argument is the intrinsic keyword, and inside the second one size means "that size, resolved".
The demo's "Cap" checkbox does exactly this:
.post.open.cap .more {
block-size: 7.5rem; /* fallback: browsers without calc-size() keep this */
block-size: calc-size(auto, min(size, 7.5rem));
overflow-y: auto;
}
The panel animates to its natural height or to 7.5rem, whichever is smaller. In Chrome I measured it landing at exactly 120px (7.5 × 16). A calc-size() value can be interpolated even without interpolate-size, but MDN recommends interpolate-size for plain animations and keeping calc-size() for when you actually need the maths.
Native accordions
<details> puts its content in the ::details-content pseudo-element, which has been Baseline since September 2025. Closed content is hidden with content-visibility, so to animate the collapse as well as the opening you also transition that property, discretely:
details::details-content {
overflow: clip;
contain: layout;
}
details:not([open])::details-content {
block-size: 0;
}
details::details-content {
transition: block-size .6s, content-visibility .6s;
transition-behavior: allow-discrete;
}
Without allow-discrete, the content would disappear as soon as the collapse starts. That's the third card in the demo.
Browser support and gotchas
-
Support:
interpolate-sizeandcalc-size()are in Chrome and Edge 129+. Safari has them in Technology Preview 254, not in a stable release yet. Firefox doesn't support either yet. MDN marks both as Limited availability. -
It degrades well: where it's unsupported, the panel just opens without animation and the layout still works. To detect support:
CSS.supports('interpolate-size', 'allow-keywords'). That's how the demo switches modes. -
The demo's plan B: in Firefox and stable Safari, the demo animates the panel with the old grid trick,
grid-template-rows: 0fr→1frwithmin-height: 0on the child. It works everywhere, but it needs an extra wrapper and only works for heights. -
Keyword to keyword doesn't work:
min-contenttomax-contentstill jumps. One end has to be a length or a percentage. -
No mixing keywords inside
calc-size(): one basis per call. -
Percentages inside
calc-size()resolve against the containing block, not againstsize. For "150% of its size", writesize * 1.5. -
It costs layout: animating
block-sizeorinline-sizerecalculates layout on every frame. Use it for small, deliberate reveals, not a whole page. -
Reduced motion: the demo turns off these transitions under
prefers-reduced-motion: reduce(with an opt-in to see them anyway). Do the same.
What to keep an eye on
- When Safari Technology Preview's
interpolate-sizeandcalc-size()reach a stable Safari release. That would make Firefox the only major engine without them. - Firefox's implementation bugs for both, linked from the MDN compatibility tables.
- Once support is wide enough, deleting
max-heighthacks andscrollHeightmeasuring scripts.
Sources
- interpolate-size — MDN
- calc-size() — MDN
- Animate to height: auto (and other intrinsic sizing keywords) in CSS — Chrome for Developers
- Safari Technology Preview 254 release notes — Apple
- ::details-content — MDN
Originally published at richi.codes.
Top comments (0)