CSS Reference ยท Box Model and Sizing
The interpolate-size property
Reference for the CSS interpolate-size property: opt in to animating and transitioning between a length and keywords like auto. Values, example and limited support.
CSS cannot normally transition height from 0 to auto, because auto is a keyword with no number to calculate with. The interpolate-size property is an opt-in switch: with allow-keywords, the browser can interpolate between lengths and intrinsic-size keywords such as auto, min-content, max-content and fit-content.
:root { interpolate-size: allow-keywords; }
Try it
In a supporting browser the panel slides open smoothly. Without support it jumps open at once, because a transition between 0 and auto does not run.
Syntax
interpolate-size: numeric-only | allow-keywords
- Initial value:
numeric-only - Applies to: all elements
- Inherited: yes
- Animatable: no
- Computed value: as specified
Values
| Value | Description |
|---|---|
numeric-only |
Only numeric values can be interpolated. A change to or from auto is instant. |
allow-keywords |
Intrinsic-size keywords (auto, min-content, max-content, fit-content) can be interpolated with lengths and percentages in size properties such as width, height and max-height. |
Usage notes
- It is inherited, so setting it once on
:rootenables the behavior for the whole page, and individual elements can opt out withnumeric-only. - Only sizing properties. It covers properties like
width,height,min-*,max-*andflex-basis. It does not make other keywords animatable. - Pair with
overflow: hidden(orclip) on the animating box so content does not spill out while the box is smaller. calc-size()is a related function that gives finer control, for examplecalc-size(auto, size + 20px).- Respect motion preferences. Wrap long transitions in a
prefers-reduced-motion: no-preferencequery. - Old alternatives. Before this property, developers animated
max-heightto a guessed value, or used agrid-template-rows: 0frto1frtrick.
Browser support
Limited: supported in Chromium-based browsers, but not yet in all major browsers. Treat it as progressive enhancement; the panel simply opens without animation elsewhere.
Related
transitionheightcalc()- Lesson: Transitions