CSS interpolate-size Property

The CSS interpolate-size property controls whether animations and transitions can interpolate between a length or percentage and an intrinsic sizing keyword such as auto.

By default, transitions between a numeric size and an intrinsic size are discrete rather than smooth. Setting interpolate-size: allow-keywords enables supported intrinsic size interpolation, making it possible to animate expanding panels, navigation menus, and other elements whose dimensions depend on their content.

interpolate-size Syntax

The interpolate-size property accepts one of two keyword values.

Basic Syntax

selector {
  interpolate-size: allow-keywords;
}

Default Behavior

.box {
  interpolate-size: numeric-only;
}

Enable Intrinsic Size Interpolation

.box {
  interpolate-size: allow-keywords;
}

CSS-Wide Keywords

.box {
  interpolate-size: initial;
}
.box {
  interpolate-size: inherit;
}
.box {
  interpolate-size: unset;
}
.box {
  interpolate-size: revert;
}
.box {
  interpolate-size: revert-layer;
}

The initial value is numeric-only. The property is inherited, so it can be applied to a parent element to control interpolation behavior throughout a section of the document.

Property Values

The interpolate-size property has two defined values.

Value Description
numeric-only Does not enable interpolation between intrinsic sizing keywords and numeric sizes. This is the initial value.
allow-keywords Allows supported intrinsic sizing keywords to interpolate with lengths or percentages.
initial Resets the property to numeric-only.
inherit Uses the computed value from the parent element.
unset Behaves like inherit because the property is inherited.
revert Reverts the property according to cascade origin rules.
revert-layer Reverts the property according to cascade layer rules.

Property Characteristics

Characteristic Value
Initial value numeric-only
Inherited Yes
Applies to All elements
Computed value As specified
Animation type Discrete
Percentages Not applicable

The property controls how certain sizing values interpolate. It does not directly set an element's width, height, or other dimensions.

How It Works

CSS normally interpolates compatible numeric sizes, such as 100px and 300px. Intrinsic sizing keywords are different because their used dimensions depend on content and layout calculations.

Numeric Size Transition

.box {
  width: 100px;
  transition: width 0.4s ease;
}
.box:hover {
  width: 300px;
}

This transition works without interpolate-size because both values are numeric lengths.

Intrinsic Size Transition

.box {
  interpolate-size: allow-keywords;
  width: 100px;
  transition: width 0.4s ease;
}
.box:hover {
  width: max-content;
}

In a supporting browser, the width can transition smoothly between the specified length and the content-based size.

Important Consideration

Setting interpolate-size: allow-keywords does not automatically animate an element. A transition or animation must also be defined, and the changing sizing values must be eligible for interpolation.

numeric-only Value

The numeric-only value preserves the default interpolation behavior. It does not opt an element into transitions between numeric dimensions and intrinsic sizing keywords.

Default Interpolation

.panel {
  interpolate-size: numeric-only;
  height: 0;
  overflow: hidden;
  transition: height 0.4s ease;
}
.panel.expanded {
  height: auto;
}

The transition from 0 to auto does not interpolate smoothly under the default behavior. The height changes discretely.

Explicitly Disable Intrinsic Interpolation

.component {
  interpolate-size: numeric-only;
}

This can override an inherited allow-keywords value for a component and its descendants, unless a descendant specifies another value.

Important Consideration

The value does not disable ordinary numeric size transitions. Transitions between compatible lengths and percentages remain available.

allow-keywords Value

The allow-keywords value opts an element into interpolation between supported intrinsic sizing keywords and numeric sizing values.

Enable on an Element

.panel {
  interpolate-size: allow-keywords;
}

Enable for the Document

:root {
  interpolate-size: allow-keywords;
}

Because the property is inherited, applying it to the root element enables the behavior for descendants unless they override it.

Enable for a Specific Section

.animated-content {
  interpolate-size: allow-keywords;
}

Scoping the declaration to a component or section can help avoid changing transition behavior elsewhere on the page.

Important Consideration

Interpolation is supported between an intrinsic sizing keyword and a compatible length or percentage. It does not generally enable smooth interpolation directly between two different intrinsic sizing keywords.

Intrinsic Sizing Keywords

Intrinsic sizing keywords describe dimensions determined by content or layout constraints rather than a fixed length.

Keyword Description
auto Uses automatic sizing rules appropriate to the property and layout context.
min-content Uses the minimum intrinsic size of the content.
max-content Uses the maximum intrinsic size of the content.
fit-content Uses a content-based size constrained by the available space.
content A content-based sizing keyword available in certain sizing contexts.

Transition to max-content

.label {
  interpolate-size: allow-keywords;
  width: 80px;
  transition: width 0.4s ease;
}
.label:hover {
  width: max-content;
}

Transition to min-content

.item {
  interpolate-size: allow-keywords;
  width: 200px;
  transition: width 0.4s ease;
}
.item:hover {
  width: min-content;
}

Important Consideration

Support for individual intrinsic sizing keywords can vary by browser and sizing context. Not every keyword or property combination is necessarily interpolable.

Animating height to auto

One of the most useful applications of interpolate-size is transitioning between a fixed height and auto.

Expandable Panel

.panel {
  interpolate-size: allow-keywords;
  height: 0;
  overflow: hidden;
  transition: height 0.4s ease;
}
.panel.expanded {
  height: auto;
}

When the expanded class is added, supporting browsers can animate the panel from zero height to its content-based height.

Hover Expansion

.details {
  interpolate-size: allow-keywords;
  height: 40px;
  overflow: hidden;
  transition: height 0.4s ease;
}
.details:hover {
  height: auto;
}

Important Consideration

The content-based height may change with text wrapping, fonts, or viewport dimensions. Intrinsic interpolation allows the browser to calculate the target size without requiring a fixed pixel height in the stylesheet.

Animating Width

The property can also enable transitions between numeric widths and intrinsic widths.

Expand to max-content

.menu-label {
  interpolate-size: allow-keywords;
  width: 100px;
  overflow: hidden;
  transition: width 0.4s ease;
}
.menu-label:hover {
  width: max-content;
}

Expand to auto

.panel {
  interpolate-size: allow-keywords;
  width: 120px;
  transition: width 0.4s ease;
}
.panel.expanded {
  width: auto;
}

The actual size produced by auto depends on the element's display type and layout context.

Important Consideration

Use an appropriate layout context when animating width. For example, width: auto on a block element may fill the available space rather than closely fit its content.

Logical Sizing Properties

Intrinsic size interpolation can also apply to logical sizing properties such as inline-size and block-size.

Animate block-size

.panel {
  interpolate-size: allow-keywords;
  block-size: 0;
  overflow: hidden;
  transition: block-size 0.4s ease;
}
.panel.expanded {
  block-size: auto;
}

Animate inline-size

.label {
  interpolate-size: allow-keywords;
  inline-size: 100px;
  transition: inline-size 0.4s ease;
}
.label:hover {
  inline-size: max-content;
}

Important Consideration

Logical sizing properties adapt to writing modes. In horizontal writing, inline-size usually corresponds to width and block-size to height.

Transitions and Animations

The interpolate-size property controls eligibility for intrinsic size interpolation. The timing and duration are controlled by CSS transitions or animations.

Transition Example

.panel {
  interpolate-size: allow-keywords;
  height: 0;
  overflow: hidden;
  transition: height 0.5s ease-in-out;
}
.panel.open {
  height: auto;
}

Keyframe Animation

@keyframes expand-panel {
  from {
    height: 0;
  }
  to {
    height: auto;
  }
}
.panel {
  interpolate-size: allow-keywords;
  overflow: hidden;
  animation: expand-panel 0.5s ease forwards;
}

Transition Multiple Properties

.panel {
  interpolate-size: allow-keywords;
  height: 0;
  opacity: 0;
  overflow: hidden;
  transition: height 0.4s ease, opacity 0.4s ease;
}
.panel.open {
  height: auto;
  opacity: 1;
}

Important Consideration

Animating layout dimensions can cause surrounding content to reflow. For complex pages, consider the performance impact of frequently changing intrinsic sizes.

calc-size() Function

The CSS calc-size() function provides another way to work with intrinsic sizes in calculations and animations.

Using calc-size()

.panel {
  height: calc-size(auto, size);
}

This expression represents the intrinsic auto size through the calc-size() function.

Add Space to an Intrinsic Size

.panel {
  height: calc-size(auto, size + 20px);
}

The calculation adds 20 pixels to the intrinsic size where the function and property combination are supported.

Difference from interpolate-size

Feature Purpose
interpolate-size Controls whether supported intrinsic sizing keywords can interpolate with numeric sizes.
calc-size() Represents an intrinsic size in a calculation and enables eligible interpolation involving that calculated size.

Important Consideration

The calc-size() function has its own browser compatibility requirements. It is not necessary for ordinary transitions between a length and auto when interpolate-size: allow-keywords is supported.

Inheritance

The interpolate-size property is inherited. This allows a parent element to enable intrinsic size interpolation for its descendants.

Enable on a Parent

.content-area {
  interpolate-size: allow-keywords;
}

Descendants inherit allow-keywords unless another declaration overrides it.

Override on a Child

.content-area {
  interpolate-size: allow-keywords;
}
.content-area .static-panel {
  interpolate-size: numeric-only;
}

Explicit Inheritance

.child {
  interpolate-size: inherit;
}

Reset to Initial Value

.child {
  interpolate-size: initial;
}

This resets the property to numeric-only.

Using unset

.child {
  interpolate-size: unset;
}

Because the property is inherited, unset uses the parent's computed value rather than automatically restoring numeric-only.

interpolate-size Example

This example uses interpolate-size: allow-keywords to animate a panel between a collapsed height and its natural content height. Select the button to expand or collapse the panel.

HTML Example

<div class="interpolate-size-demo">
  <button type="button" aria-expanded="false" aria-controls="size-panel">Expand Panel</button>
  <div class="demo-panel" id="size-panel">
    <div class="demo-content">
      <p>This panel expands to fit its content.</p>
      <p>Its height is determined automatically.</p>
    </div>
  </div>
</div>

CSS Example

.interpolate-size-demo {
  interpolate-size: allow-keywords;
  max-width: 480px;
}
.interpolate-size-demo button {
  padding: 10px 16px;
  border: 0;
  background-color: #2563eb;
  color: #fff;
  cursor: pointer;
}
.interpolate-size-demo .demo-panel {
  height: 0;
  overflow: hidden;
  transition: height 0.5s ease;
}
.interpolate-size-demo .demo-panel.open {
  height: auto;
}
.interpolate-size-demo .demo-content {
  padding: 16px;
  border: 2px solid #2563eb;
  background-color: #eff6ff;
}
.interpolate-size-demo .demo-content p {
  margin: 0 0 10px;
}
.interpolate-size-demo .demo-content p:last-child {
  margin-bottom: 0;
}
@media (prefers-reduced-motion: reduce) {
  .interpolate-size-demo .demo-panel {
    transition: none;
  }
}

JavaScript Example

const button = document.querySelector('.interpolate-size-demo button');
const panel = document.querySelector('.interpolate-size-demo .demo-panel');
button.addEventListener('click', () => {
  const expanded = button.getAttribute('aria-expanded') === 'true';
  button.setAttribute('aria-expanded', String(!expanded));
  button.textContent = expanded ? 'Expand Panel' : 'Collapse Panel';
  panel.classList.toggle('open', !expanded);
});
Browser Result

This panel expands to fit its content.

Its height is determined automatically.

In browsers that support intrinsic size interpolation, the panel transitions smoothly between height: 0 and height: auto. In browsers without support, the panel still opens and closes, but the height change may occur immediately.

Try a Faster Transition

.interpolate-size-demo .demo-panel {
  transition: height 0.2s ease;
}

Try a Slower Transition

.interpolate-size-demo .demo-panel {
  transition: height 0.8s ease-in-out;
}

Changing the transition duration affects the animation speed without changing the panel's natural expanded height.

Accessibility

Expanding and collapsing interfaces should remain usable with a keyboard and assistive technologies, regardless of whether intrinsic size interpolation is supported.

Respect Reduced Motion Preferences

@media (prefers-reduced-motion: reduce) {
  .panel {
    transition: none;
  }
}

Use an Accessible Control

<button type="button" aria-expanded="false" aria-controls="panel-content">
  Show Details
</button>

Update aria-expanded when the panel opens or closes so assistive technologies can identify the control's current state.

Manage Hidden Content

Collapsing an element to zero height does not automatically remove its descendants from keyboard navigation or the accessibility tree. For interactive content, manage focus and visibility appropriately, using mechanisms such as inert when suitable.

Important Consideration

Animation should enhance the interface rather than be required for understanding or operating it. Always provide a usable state change when interpolation is unsupported.

Common Mistakes

Using an Invalid Value

.box {
  interpolate-size: auto;
}

This is invalid. The property accepts numeric-only or allow-keywords, along with CSS-wide keywords.

Expecting Animation Without a Transition

.box {
  interpolate-size: allow-keywords;
  height: 0;
}
.box.open {
  height: auto;
}

Intrinsic interpolation is enabled, but no transition or animation has been defined. The size changes without an animated duration.

Trying to Interpolate Between Two Intrinsic Keywords

.box {
  interpolate-size: allow-keywords;
  width: min-content;
  transition: width 0.4s ease;
}
.box:hover {
  width: max-content;
}

The allow-keywords value does not generally enable interpolation directly between two different intrinsic sizing keywords.

Assuming All Browsers Support the Feature

Browsers without support ignore the interpolate-size declaration. The layout still uses its specified sizes, but intrinsic size transitions may be discrete.

Confusing interpolate-size with a Sizing Property

The property does not assign width or height. It changes how eligible sizing values interpolate during transitions and animations.

Ignoring Content Overflow

Collapsed panels may need overflow: hidden or another suitable clipping method to prevent content from remaining visible outside their animated dimensions.

Forgetting Reduced Motion Preferences

Provide a reduced-motion alternative when animating expanding panels or other content that changes the page layout.

Important Considerations

Keep the following points in mind when using interpolate-size:

  • The property controls interpolation involving supported intrinsic sizing keywords.
  • It accepts numeric-only and allow-keywords.
  • The initial value is numeric-only.
  • The property is inherited.
  • It does not directly change an element's dimensions.
  • A transition or animation is required for an animated size change.
  • Ordinary numeric size transitions do not require allow-keywords.
  • Intrinsic size interpolation generally requires one endpoint to be a length or percentage.
  • Interpolation between two different intrinsic sizing keywords is not generally enabled.
  • Supported intrinsic keywords can include auto, min-content, max-content, and fit-content.
  • Individual keyword and property combinations may have different browser support.
  • The property can be applied to :root to enable inheritance throughout the document.
  • Use component-level declarations when global interpolation behavior is not desired.
  • Transitions involving intrinsic sizes can affect surrounding layout.
  • Use appropriate overflow handling for collapsing content.
  • Respect prefers-reduced-motion for motion-sensitive users.
  • Provide usable behavior in browsers that do not support the feature.
  • The calc-size() function provides related intrinsic sizing capabilities.

Browser Support

The CSS interpolate-size property has limited availability compared with established CSS sizing and transition properties. Support is available in some modern browsers, but it is not universal across all major browser engines.

Browsers that do not recognize the property ignore its declaration and retain their normal intrinsic sizing behavior. Transitions between numeric dimensions continue to work, while transitions involving intrinsic sizing keywords may remain discrete.

For current compatibility information, visit Can I Use? and search for interpolate-size.

Specifications

The interpolate-size property is defined in the CSS Values and Units Module Level 5 specification.

CSS Values and Units Module Level 5: interpolate-size

The specification defines how intrinsic sizing keywords can participate in interpolation with compatible numeric values.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: interpolate-size