interpolate-size
Animating an element from a fixed height to auto has been impossible in CSS for decades. The browser cannot interpolate between a concrete value and a keyword it has not yet computed. interpolate-size: allow-keywords changes that, enabling smooth height transitions on accordions, disclosures, and any element that needs to expand to fit its content.
Why auto Has Never Been Animatable
CSS transitions and animations work by interpolating between a start value and an end value. To do that, the browser needs both values to be concrete numbers at the moment the transition begins. height: auto is not a number. It is an instruction to compute the height from the element's content, which the browser cannot do until layout runs. A transition from height: 0 to height: auto gives the browser no midpoint to calculate, so the property jumps instantly instead of animating.
The common workarounds have been clunky. Animating max-height to a large arbitrary value works visually but causes the element to reach its final size before the transition ends, making the easing feel wrong. A JavaScript approach measuring scrollHeight and setting an explicit pixel height works correctly but adds complexity and requires script for what should be a pure CSS concern.
interpolate-size: allow-keywords
Setting interpolate-size: allow-keywords on :root opts the entire page into keyword interpolation. The browser now treats size keywords like auto, min-content, and max-content as animatable endpoints, resolving them to concrete values before interpolating.
:root {
interpolate-size: allow-keywords;
}
Applying it to :root is the recommended pattern. Because it is an inherited property, every element on the page inherits the behavior. You can also apply it to a specific component if you want to scope the opt-in.
Chrome 129 and Edge 129 added support in late 2024. Firefox and Safari do not yet support this property. Check Can I Use and plan a fallback for unsupported browsers.
The Height-to-Auto Pattern
With interpolate-size: allow-keywords set on :root, a height transition to auto works exactly as you would expect. The typical pattern for an accordion or disclosure uses <details> and <summary>, with the panel content inside a wrapper element.
:root {
interpolate-size: allow-keywords;
}
.panel {
height: 0;
overflow: hidden;
transition: height 0.35s ease;
}
details[open] .panel {
height: auto;
}
@media (prefers-reduced-motion: reduce) {
.panel {
transition: none;
}
}
The details[open] selector is driven entirely by the browser's native toggle behavior. No JavaScript is required to open or close the element. The browser handles the state, and CSS handles the visual transition.
The overflow: hidden on .panel is required to clip the content during the transition. Without it, the content would be visible at full height while the element animates.
Progressive Enhancement
Because <details> and <summary> are native HTML elements, the accordion works in every browser with no JavaScript and no CSS animation support required. In unsupported browsers, the panel still opens and closes instantly. The animation is an enhancement, not a requirement.
If you need the animation in older browsers, a JavaScript fallback can measure the panel's scrollHeight and set an explicit pixel height before the transition fires. Use CSS.supports() to apply the fallback only where needed.
if (!CSS.supports('interpolate-size', 'allow-keywords')) {
document.querySelectorAll('details').forEach((details) => {
const panel = details.querySelector('.panel');
details.addEventListener('toggle', () => {
panel.style.height = details.open
? panel.scrollHeight + 'px'
: '0';
});
});
}
This fallback runs only when interpolate-size is not supported. Browsers with native support use the pure CSS approach and never execute the JavaScript block.
The JavaScript fallback sets an explicit pixel height, which will conflict with the CSS height: auto value in supporting browsers. Wrapping the fallback in CSS.supports() keeps the two approaches from interfering with each other.
Demo: Animated Accordion
This accordion uses native <details> and <summary> with no JavaScript. The smooth height animation depends on interpolate-size: allow-keywords. In an unsupported browser, the panels still open and close instantly.
The interpolate-size Property
interpolate-size: allow-keywords opts the page into keyword interpolation, allowing the browser to animate CSS size keywords like auto, min-content, and max-content as transition endpoints. Set it on :root to apply it everywhere.
Why max-height Is a Poor Fit
Animating max-height to a large value like 1000px works visually, but the element reaches its real height before the transition ends. The easing curve feels wrong because the element stops moving while the transition continues running. The animation appears to stall.
JavaScript and Progressive Enhancement
The <details> element handles open and close state natively, and CSS handles the animation. A JavaScript fallback is only needed if you want smooth animation in browsers that do not support interpolate-size. Without the fallback, those browsers still open and close the panels instantly.
Respecting prefers-reduced-motion
Always pair animated transitions with a @media (prefers-reduced-motion: reduce) block that sets transition: none. Users who have enabled reduced motion in their operating system settings will experience instant open and close behavior rather than the animated version.
Build Your Demo
Add an animated accordion to your portfolio at unit-5/interpolate-size/. Build the markup with native <details> and <summary> elements, a .panel wrapper around the expandable content, and at least three disclosure sections with real copy. Set interpolate-size: allow-keywords on :root, then add the height transition, overflow: hidden, and details[open] .panel { height: auto; } rules from this page. Include a prefers-reduced-motion block that disables the transition. Record your video in a browser that supports the property so teammates see the smooth animation; mention or demonstrate instant open in an unsupported browser. A CSS.supports() JavaScript fallback is optional unless you want to cover older browsers in the video.
Teaching Video Checklist
When you record your teaching video, make sure your teammates come away understanding these concepts:
-
Why
height: autohas no interpolatable midpoint unless the browser can resolve size keywords to concrete values -
What
interpolate-size: allow-keywordsopts into and why setting it on:rootis the usual pattern -
Why animating
max-heightstalls visually compared to a true height-to-autotransition -
The progressive enhancement stack: native
<details>for state, CSS for animation, and an optionalCSS.supports()fallback only where needed -
Why
overflow: hidden, thedetails[open]selector, andprefers-reduced-motionbelong in every animated disclosure pattern - Your portfolio demo: an accordion with at least three panels that animate open and closed in a supporting browser
Start by toggling a panel in a supporting browser before interpolate-size is set, then add allow-keywords on :root so teammates can see the jump become a smooth height transition.
Resources
- MDN: interpolate-size - Property reference, browser support, and interaction with other size keywords
- MDN: <details> - Native disclosure element, the toggle event, and accessibility considerations
- Can I Use: interpolate-size - Current browser support data