
Animating to Auto: interpolate-size and calc-size()
Transitions interpolate numbers, and auto is not one. How the new opt-in property and function retire the measure-then-animate pattern in Chromium, and the grid technique that works everywhere today.
TL;DR: Transitions interpolate numbers, and auto is not a number — which is why expanding a panel meant reading scrollHeight in JavaScript, writing a pixel height, animating, and resetting. interpolate-size: allow-keywords makes intrinsic size keywords valid transition endpoints when the other endpoint is a length or percentage (in other cases, such as between two different keywords, a keyword still cannot be interpolated), and calc-size() allows arithmetic on them. Both are Chromium-only as of November 2026, so the practical shape is a grid-template-rows: 0fr to 1fr floor that works everywhere today with the new property and function layered on top behind a feature query.
The oldest workaround in CSS
A transition needs to compute intermediate values between two endpoints, which requires both endpoints to be quantities it can do arithmetic on. height: 0 to height: 240px is arithmetic. height: 0 to height: auto is not: auto is an instruction to the layout algorithm, and its resolved value is not known until layout runs. So the transition had nothing to interpolate and the element snapped.
The workaround has been around for a long time. Measure the content's natural height by reading scrollHeight, set that number as an explicit pixel height, let the transition run, then set the height back to auto when it finishes so the panel can respond to content changes afterward.
// the pattern this feature retires
const h = panel.scrollHeight
panel.style.height = '0px'
requestAnimationFrame(() => { panel.style.height = h + 'px' })
panel.addEventListener('transitionend', () => { panel.style.height = 'auto' }, { once: true })Every line there has a failure mode. The measurement is a forced synchronous layout, so it thrashes when several panels open at once. It goes stale the moment the content or the viewport changes — a late-loading font, an image that finally decodes, a rotation — leaving a panel clipped or padded. The reset to auto at the end causes a visible jump when the measured value and the resolved value disagree by a pixel or two. And transitionend does not fire for a transition that is canceled before it completes, which is what happens when it is interrupted (the CSS Transitions specification defines a separate transitioncancel event for that case), so an interrupted expand can leave the element at a fixed pixel height, or let the one-time listener run later when a different transition ends.
The fix took years because making keywords interpolable is not a small semantic change: it alters what a layout keyword means during animation, and stylesheets written across the entire history of the web assume it never happens. So the platform shipped it as something you turn on.
interpolate-size: allow-keywords
The switch is a single declaration, and it is inherited — so declaring it once at the root turns the behavior on for the document.
:root {
interpolate-size: allow-keywords;
}
.panel-content {
height: 0;
overflow: hidden;
transition: height 250ms ease;
}
.panel[open] .panel-content {
height: auto;
}That is the entire expanding panel. No measurement, no listener, no reset — and because the endpoint is genuinely auto rather than a number captured at one moment, content that changes size while the panel is open simply reflows, with no stale value to invalidate.
The keywords that become interpolable include the intrinsic-size family: auto, min-content, max-content, fit-content, and content for flex sizing (MDN, accessed November 2026). The reason it must be opted into is stated plainly in the same reference: enabling it by default would break sites whose stylesheets assume intrinsic sizes never animate, so the behavior is scoped to the subtree that asks for it. That framing is also the argument for declaring it at :root in a new codebase and scoping it to a component in an old one where you cannot audit every existing transition.
calc-size(): arithmetic on intrinsic sizes
The companion function does what plain calc() cannot: arithmetic where one operand is an intrinsic size.
.drawer {
height: calc-size(auto, size + 2rem);
transition: height 250ms ease;
}
.notice {
max-height: calc-size(max-content, min(size, 12rem));
}Inside calc-size(), the first argument names the intrinsic size being resolved and size stands for its resolved value, so you can pad it, clamp it, or scale it. Padding a disclosure panel by its own margin, or capping a notice at its natural height or twelve rem, whichever is smaller — both were previously measurement problems.
There is a scoping consequence worth knowing: using calc-size() in a declaration enables interpolation for that declaration on its own, without the global switch. So the two mechanisms are also two levels of opt-in. Reach for the root-level interpolate-size when you want the behavior broadly and can accept it applying to everything; reach for calc-size() when you want exactly one animation to gain the capability and nothing else in the codebase to change.
The cross-browser floor: 0fr to 1fr
Neither the property nor the function is interoperable yet, so production code that must work across browsers still needs a technique that works in every engine today. The grid track version is that technique: a single-row grid whose track animates from zero to content size.
.panel-content {
display: grid;
grid-template-rows: 0fr;
transition: grid-template-rows 250ms ease;
}
.panel[open] .panel-content {
grid-template-rows: 1fr;
}
.panel-content > * {
min-height: 0;
overflow: hidden;
}Grid items have an automatic minimum size: in this pattern, an item whose overflow is visible or clip refuses to shrink below its content, and the collapse never visually happens. Setting overflow: hidden on the item already removes that minimum, because the automatic minimum size of a grid item with a scrollable overflow value such as hidden is zero, and it also clips the content during the animation so it does not spill out of the shrinking track. min-height: 0 removes the minimum on its own, which keeps the collapse working if you later change the item's overflow to visible or clip. The technique also animates the track rather than the element's own height, which matters if something else in your layout is reading or depending on that element's height.
One authoring detail catches people in both versions: vertical padding on the collapsing element does not collapse with it. A panel with padding-block: 1rem still occupies two rem when closed, which reads as a mysterious gap under the header. The fix is the same in either approach — put the padding on an inner wrapper that lives inside the clipped region, so it disappears along with the content rather than surviving the collapse.
Layering the two paths is a feature query:
@supports (interpolate-size: allow-keywords) {
:root { interpolate-size: allow-keywords; }
.panel-content {
display: block;
height: 0;
overflow: hidden;
transition: height 250ms ease;
}
.panel[open] .panel-content { height: auto; }
}Ship the grid version as the floor, let the query upgrade browsers that support the cleaner path, and delete the floor when support justifies it. Feature-query authoring as a discipline — where to put the gate, how to avoid two mechanisms running at once — has its own coverage.
Where it composes and where JS stays
The natural applications are disclosure panels, expanding cards, and any accordion content region. When the accordion is built on the native disclosure element, the sizing technique here composes with it, though with interpolate-size alone the animation runs only as the element opens; combining it with the ::details-content pseudo-element can animate the close as well. The element's own behavior and styling belong to its own discussion.
When the collapsing element is also hidden afterward (display: none) rather than merely shrinking, size interpolation pairs with the CSS mechanisms for animating elements in and out — a panel that collapses and then leaves the layout is two animations describing one interaction, and both halves are now declarable.
Support has to be stated per mechanism, because the two paths are nowhere near each other. The grid technique works in every current engine and has for years (the web-features data records animating grid tracks as Baseline Widely available, as of November 2026). interpolate-size and calc-size() are Chromium-only — Chrome and Edge 129 and later — with caniuse putting global support near 72% and no shipping implementation in Firefox or Safari (caniuse, accessed November 2026; the web-features data records the property as limited availability, accessed November 2026). Verify both before you plan around them; this is the fastest-moving claim in the article.
The honest line: this retires measurement for the case where one element grows to its natural size. It does not replace animation tooling generally. Shared-layout transitions where an element appears to move between two positions in different parts of the tree are covered by the View Transitions API, which animates elements that share a view-transition-name between the old and new state (same-document view transitions have been Baseline Newly available since October 2025, as of November 2026). Coordinated size choreography across many elements with dependent timing may still call for a library that can compute and drive the whole sequence. What has changed is that the single expanding panel — the case this article set out to solve, and one that generated fragile code — no longer needs a single line of JavaScript.