Give a card and the panel inside it the same border-radius and the gap looks wider around the corners than it does along the sides. I could nudge the inner radius down in DevTools. Then I’d have to do it again every time the padding changed.
This time I tried making the inner radius follow the padding. The experiment starts with calc() and ends with a CSS function I can call with two lengths.
Subtract the gap from the outer radius
Take a card with a 32px radius and 12px of padding on all sides. The curve on the inner panel starts 12px farther in, so a 20px radius gives the two curves the same centre. CSS uses the same subtraction to shape the inside edge of a border. CSS Backgrounds and Borders, corner shaping
.card__body {
border-radius: calc(32px - 12px);
}I can put the outer radius and the inset in custom properties so the padding and the calculation share a value. I also want the inner corner to go square once the inset reaches the outer radius. max() lets me put the floor at 0px and accepts the subtraction directly. CSS Values and Units, comparison functions
Both cards below have a 32px outer radius. Move the slider to request an inset of 4px. clamp() raises it to 8px. Move it to 40px and the inset stops at 32px, where the calculated inner corner goes square.
Your browser is using the max() fallback.
Your browser is running --inner-radius().
See the CSS calculations
.corner-radius-demo {
--outer-radius: 32px;
--requested-inset: 16px;
--inset: clamp(8px, var(--requested-inset), 32px);
}
.corner-radius-demo__panel--calculated {
border-radius: max(0px, var(--outer-radius) - var(--inset));
}
@function --inner-radius(--outer <length>, --inset <length>) returns <length> {
result: max(0px, var(--outer) - var(--inset));
}
.corner-radius-demo__custom {
display: none;
}
@supports (border-radius: --inner-radius(32px, 12px)) {
.corner-radius-demo__panel--calculated {
border-radius: --inner-radius(var(--outer-radius), var(--inset));
}
.corner-radius-demo__custom {
display: inline;
}
.corner-radius-demo__fallback {
display: none;
}
}Browser support. As of November 2026, the demo’s @function runs in Chrome and Edge 139+, Safari Technology Preview, and the Safari 27.3 beta. Firefox and Safari 27.2 use the built-in max() fallback and show the same corners. MDN browser compatibility data · Safari release notes
The slider uses JavaScript to pass the requested inset to CSS. With JavaScript disabled, the comparison shows the default 16px inset.
Let the padding follow the container
Here’s the markup I used to try it at a few sizes.
<div class="radius-demo">
<div class="card">
<div class="card__body">Resize the container to change the inset.</div>
</div>
</div>.radius-demo {
container-type: inline-size;
max-inline-size: 32rem;
}
.card {
--outer-radius: 32px;
--inset: clamp(10px, 6cqi, 20px);
padding: var(--inset);
border-radius: var(--outer-radius);
background: #cbd8f2;
}
.card__body {
padding: 1rem;
border-radius: max(0px, var(--outer-radius) - var(--inset));
background: #f5f7ff;
color: #202730;
}6cqi is 6% of the wrapper’s inline size. In ordinary horizontal writing, that’s its width. I put container-type on the wrapper because the units in .card look for an eligible ancestor. clamp() keeps the inset between 10px and 20px. CSS Conditional Rules, container query units
Try setting the wrapper’s inline-size to 160px, 300px, and 500px in DevTools. At 160px, 6% works out to 9.6px, so clamp() uses 10px. At 300px it uses 18px. At 500px it caps the inset at 20px. Watch border-top-left-radius on the inner panel as you go. It drops from 22px to 14px to 12px.
The example uses one length for all four corners and an even inset. If I add a border to .card, I need to subtract its thickness too. The distance from the outer edge to the panel now includes both border and padding.
Give the radius calculation a name with @function
The inline calculation is short. I wanted to see what it would look like if I could call it anywhere I had an outer radius and an inset, including on a component that uses different custom property names.
Add this after the previous CSS.
@function --inner-radius(--outer <length>, --inset <length>) returns <length> {
result: max(0px, var(--outer) - var(--inset));
}
@supports (border-radius: --inner-radius(32px, 12px)) {
.card__body {
border-radius: --inner-radius(var(--outer-radius), var(--inset));
}
}The names inside @function are parameters. var(--inset) in result reads the second argument, and var(--inset) at the call site supplies it from the card. The <length> types let me pass values like 32px and 1rem, and the returns clause describes the value that goes back into border-radius. CSS Custom Functions and Mixins, defining custom functions
I keep the original max() declaration and put the function call behind @supports. The query checks whether the browser accepts custom function syntax in a property value. Browsers that skip the block still get the same radius from the inline calculation. Chrome for Developers, detecting custom function support
For one last check, set --outer-radius to 8px. The padding will always be at least 10px, so the inner corner should go square at every width. That’s the case I’d include if I borrowed --inner-radius() for another component.