Taking Control of Intrinsic Sizes with calc-size()
Intrinsic sizes you can calculate (and animate)
You’ve probably heard this before: “you can’t animate height: auto.”
And for a long time… that was basically true.
calc-size() changes that. It lets you do math with intrinsic sizes like
auto and fit-content—which opens the door to smoother layouts,
better sizing, and yes… actually animating things that used to feel impossible.
Why this has always been a pain
Intrinsic sizes—like auto, max-content, and
fit-content—are incredibly useful. They let elements size themselves
based on content.
The problem is… they’ve always been a dead end when you wanted control.
- You can’t do math with them
- You can’t tweak them
- You can’t animate to or from them cleanly
So we’ve all done the same dance: hard-coded heights, weird max-height hacks, or just giving up on the animation entirely.
So what does calc-size() actually do?
calc-size() is basically calc()—but for intrinsic sizes.
It lets you take something like auto or fit-content and say:
- “Give me that… plus a little more”
- “Give me 70% of that”
- “Round that to something cleaner”
And importantly: the result becomes something the browser can interpolate—meaning it can animate.
That’s the real unlock here. :contentReference[oaicite:0]{index=0}
The mental model (this is the part that matters)
calc-size(<basis>, <math>)Think of it like this:
-
The first value is your starting point
→ usually
auto,fit-content, etc. -
The second value is what you want to do to it
→ using
sizeas a reference
/* Just make auto animatable */
width: calc-size(auto, size);
/* Add breathing room */
inline-size: calc-size(fit-content, size + 2rem);
/* Scale it */
block-size: calc-size(max-content, size * 0.5);
If you remember one thing: size just means “whatever the intrinsic size would have been.”
The “this is actually useful” part
1) Auto… but not cramped
Sometimes auto is technically correct—but visually tight.
.card {
block-size: calc-size(auto, size + 1.5rem);
overflow: clip;
}Same natural height, just with a little breathing room baked in.
2) Fit-content without fighting padding
You want something to “hug” content… but not too tightly.
button.badge {
inline-size: calc-size(fit-content, size + 12ch);
}This avoids weird padding + layout interactions and keeps sizing intentional.
3) Let content decide—but not too much
.column {
inline-size: clamp(18rem, calc-size(max-content, size), 36rem);
}Content drives the size—but you stay in control.
4) Cleaner, more consistent layouts
.tile {
inline-size: calc-size(fit-content, round(nearest, size, 8ch));
}This is one of those subtle polish moves that makes layouts feel “designed” instead of accidental.
The thing everyone actually wants: animating to auto
This is where calc-size() stops being “nice” and becomes “finally.”
Because the value is now interpolatable, you can transition between fixed values and intrinsic ones.
Accordion without hacks
.accordion {
block-size: 0;
overflow: hidden;
transition: block-size 350ms ease;
}
.accordion[open] {
block-size: calc-size(auto, size + 2rem);
}No magic numbers. No guessing heights. Just… works.
Scaling intrinsic sizes
@keyframes narrower {
from { inline-size: fit-content; }
to { inline-size: calc-size(fit-content, size * 0.7); }
}You still can’t animate between different intrinsic keywords—but you can transform one into a calculated version of itself.
Where this can trip you up
-
One intrinsic basis at a time.
You can’t mixmin-contentandmax-contentin the same calculation. -
This isn’t always the right tool.
If you just want animation,interpolate-sizeis simpler. -
Layout animations still cost.
This affects layout. Don’t expect transform-level performance.
Use
calc-size() when you need both:
• intrinsic sizing
• and control over it
.panel { inline-size: 100%; }
@supports (width: calc-size(auto, size)) {
.panel {
inline-size: calc-size(fit-content, size + 4rem);
}
}Reality check: can you use this yet?
Not fully. This is still considered experimental.
That doesn’t mean “ignore it”—it means:
- Use it where it enhances things
- Don’t rely on it for core layout yet
- Always provide a fallback
Quick answers
Is this just calc()?
Not quite. calc() can’t touch intrinsic sizes. This can.
Can I animate between intrinsic values?
No—but you can animate between an intrinsic value and a calculated version of it.
When should I reach for this?
When you catch yourself thinking:
“I wish auto was just a little more controllable.”
Want to go deeper?
- MDN docs for syntax and updates
- Spec drafts (this is still evolving)
- Community demos—this space is moving fast