Animate height: auto with interpolate-size
Use interpolate-size to transition a disclosure from zero to its content height, with an instant fallback and reduced-motion support.
You collapse a delivery panel to zero height. On open, it needs enough room for text that wraps differently on a phone. Declare height: auto for the open state and the content fits, but a height transition can snap to that size unless you opt in to interpolating the keyword.
Keep the open state on the button
Save this as an HTML file, then add the CSS from the next section before opening it. The button owns the expanded state. The panel uses inert while closed so the browser skips its content during focus navigation and excludes it from the accessibility tree.
<button type="button" aria-expanded="false" aria-controls="delivery">
Delivery options
</button>
<div id="delivery" inert>
<p>Pickup is free. Delivery takes two business days.</p>
</div>
<script>
const button = document.querySelector('button')
const panel = document.querySelector('#delivery')
button.addEventListener('click', () => {
const open = button.getAttribute('aria-expanded') === 'false'
button.setAttribute('aria-expanded', String(open))
panel.inert = !open
})
</script>Pressing the button changes aria-expanded, and the panel's inert state follows it.
Let the browser find the open height
Add the CSS in a <style> element. The two height rules work on their own. The feature query adds keyword interpolation where the browser supports it and the user allows motion.
#delivery {
height: auto;
overflow: clip;
}
button[aria-expanded="false"] + #delivery {
height: 0;
}
@supports (interpolate-size: allow-keywords) {
@media (prefers-reduced-motion: no-preference) {
#delivery {
interpolate-size: allow-keywords;
transition: height 240ms ease;
}
}
}In Chromium 129 or later, focus the button and press Enter. With reduced motion off, the panel expands to the height of the wrapped text.
The closed value, 0, gives the transition a length to start from. The other endpoint, auto, lets layout work out the right height for the content. allow-keywords enables that pair. If both endpoints are intrinsic keywords, the browser has no length endpoint to interpolate from. The property inherits, so set it on the panel to keep the opt-in within this subtree.
Keep overflow: clip on the panel so the text stays inside the opening area. Put padding on an inner wrapper if you need it. Padding on the element with height: 0 can leave space visible when the panel is closed.
In a browser without the feature, the closed and open height rules still apply. You get the same instant change with reduced motion enabled. To check the fallback in Chromium, disable the block inside @supports and open the panel using the keyboard. Try it again at a narrow width with twice as much delivery text. The open panel should fit the text with or without interpolation.