Inner border calculations

First, you'll need to remove -vendor-background-clip: padding-box or set them to border-box the default in order to achieve the inner border radius.

The inner border radius is calculated as the difference of the outer border radius (border-radius) and the border width (border-width) such that

inner border radius = outer border radius - border width

Whenever the border-width is greater than the border-radius, the inner border radius is negative and you get some awkward inverted corners. Currently, I don't believe there is a property for adjusting the inner-border-radius, so you'll need to calculate it manually.

In your case:

inner border radius = 6px - 5px = 1px

Your new CSS should be:

.radius-all { border-radius: 6px; -moz-border-radius: 6px; -webkit-border-radius: 6px; }
.template-bg { background: #FFF; }
.template-border { border: 5px solid rgba(255, 255, 255, 0.2); }

Simply subtract the border-radius (6px) values from the border-width value (5px) in order to achieve your desired inner-border-radius:


Code that works for me

Tested on Firefox 3.x, Google Chrome, and Safari 5.0

 .radius-all { border-radius: 10px; -moz-border-radius: 10px; -webkit-border-radius: 10px; }
.template-bg { background: #FFF; }
.template-border { border: 5px solid rgba(0, 0, 0, 0.2); } /* Note that white on white does not distinguish a border */

Adding color overlays in JavaScript

<script type="text/javascript">
    var bodyBgColor = document.getElementsByTagName('body')[0].style.backgroundColor;;

    // insert opacity decreasing code here for hexadecimal

    var header = document.getElementsByTagName('header')[0];
    header.style.backgroundColor = bodyBgColor;
</script>

I'm not entirely sure how to do hexadecimal arithmetic in JavaScript but I'm sure you can find an algorithm in Google.


Applying General Borders

Are you using a separate box <div> for your border through its background property? If so, you'll need to apply border-radius and its vendor specific properties on both the border box and the inner box:

<div id="border-box" style="border-radius: 5px;">
    <div id="inner-box" style="border-radius: 5px;">
    </div>
</div>

A much more efficient way would simply have the inner-box manage its own border:

<div id="inner-box" style="border: 4px solid blue; border-radius: 5px">
    <!-- Content -->
</div>

CSS-wise, you could just declare a .rounded-border class and apply it to every box that will have rounded borders:

.rounded-borders {
    border-radius: 5px;
    -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
    -khtml-border-radius: 5px;
}

And apply the class to any boxes that will have rounded borders:

<div id="border-box" class="rounded-borders">
    <div id="inner-box" class="rounded-borders">
    </div>
</div>

For a single box element, you'll still be required to declare the border size in order to be shown:

<style type="text/css">
    #inner-box { border: 4px solid blue; }
</style>

<div id="inner-box" class="rounded-borders">
</div>
Answer from Gio Borje on Stack Overflow
Top answer
1 of 13
67

Inner border calculations

First, you'll need to remove -vendor-background-clip: padding-box or set them to border-box the default in order to achieve the inner border radius.

The inner border radius is calculated as the difference of the outer border radius (border-radius) and the border width (border-width) such that

inner border radius = outer border radius - border width

Whenever the border-width is greater than the border-radius, the inner border radius is negative and you get some awkward inverted corners. Currently, I don't believe there is a property for adjusting the inner-border-radius, so you'll need to calculate it manually.

In your case:

inner border radius = 6px - 5px = 1px

Your new CSS should be:

.radius-all { border-radius: 6px; -moz-border-radius: 6px; -webkit-border-radius: 6px; }
.template-bg { background: #FFF; }
.template-border { border: 5px solid rgba(255, 255, 255, 0.2); }

Simply subtract the border-radius (6px) values from the border-width value (5px) in order to achieve your desired inner-border-radius:


Code that works for me

Tested on Firefox 3.x, Google Chrome, and Safari 5.0

 .radius-all { border-radius: 10px; -moz-border-radius: 10px; -webkit-border-radius: 10px; }
.template-bg { background: #FFF; }
.template-border { border: 5px solid rgba(0, 0, 0, 0.2); } /* Note that white on white does not distinguish a border */

Adding color overlays in JavaScript

<script type="text/javascript">
    var bodyBgColor = document.getElementsByTagName('body')[0].style.backgroundColor;;

    // insert opacity decreasing code here for hexadecimal

    var header = document.getElementsByTagName('header')[0];
    header.style.backgroundColor = bodyBgColor;
</script>

I'm not entirely sure how to do hexadecimal arithmetic in JavaScript but I'm sure you can find an algorithm in Google.


Applying General Borders

Are you using a separate box <div> for your border through its background property? If so, you'll need to apply border-radius and its vendor specific properties on both the border box and the inner box:

<div id="border-box" style="border-radius: 5px;">
    <div id="inner-box" style="border-radius: 5px;">
    </div>
</div>

A much more efficient way would simply have the inner-box manage its own border:

<div id="inner-box" style="border: 4px solid blue; border-radius: 5px">
    <!-- Content -->
</div>

CSS-wise, you could just declare a .rounded-border class and apply it to every box that will have rounded borders:

.rounded-borders {
    border-radius: 5px;
    -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
    -khtml-border-radius: 5px;
}

And apply the class to any boxes that will have rounded borders:

<div id="border-box" class="rounded-borders">
    <div id="inner-box" class="rounded-borders">
    </div>
</div>

For a single box element, you'll still be required to declare the border size in order to be shown:

<style type="text/css">
    #inner-box { border: 4px solid blue; }
</style>

<div id="inner-box" class="rounded-borders">
</div>
2 of 13
28

Another solution is to have matching inner and outer borders combined with border-radius is to "fake" the border using the <spread-radius> value of the box-shadow property. This produces a solid shadow which can easily pass for a regular border.

For instance, to achieve a 4px border and a 4px white border radius, try this:

/* rounded corners */
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;

/* drop shadow */
-webkit-box-shadow: 0px 0px 0px 4px #fff;
-moz-box-shadow: 0px 0px 0px 4px #fff;
box-shadow: 0px 0px 0px 4px #fff;

If you want to add a "real" drop shadow to the entire container, you can simply chain your shadow statements like so:

/* drop shadow */
-webkit-box-shadow: 0px 0px 0px 4px rgba(255,255,255,1.0),
        1px 1px 8px 0 rgba(0,0,0,0.4);
-moz-box-shadow: 0px 0px 0px 4px rgba(255,255,255,1.0),
        1px 1px 8px 0 rgba(0,0,0,0.4);
box-shadow: 0px 0px 0px 4px rgba(255,255,255,1.0),
        1px 1px 8px 0 rgba(0,0,0,0.4);

Note: Keep in mind here that the order of the statements is the order in which it will be rendered.

The only thing to beware of is that the initial "faux border" will overlap the first X pixels (where X is the width of the border) of any shadow you want beneath it (and combine, if you're using RGBa opacity on it below 100%.)

So it won't work in all situations, but it'll get the majority. I use this pretty frequently when regular borders are not ideal.

🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › CSS › border-radius
border-radius - CSS - MDN Web Docs - Mozilla
October 13, 2025 - Denotes the size of the circle radius, or the semi-major and semi-minor axes of the ellipse, using percentage values. Percentages for the horizontal axis refer to the width of the box; percentages for the vertical axis refer to the height of the box. Negative values are invalid.
Discussions

For inner border roundness, how can I say something like use `rounded-lg` but 1 px less
Since I have double borders, if I use rounded-lg on both of them it doesn't work and has some gap because of the border width In order to fix this based on this answer, I need to put a differen... More on github.com
🌐 github.com
1
2
October 21, 2022
Css Inner border radius - Stack Overflow
I need to apply an inner border radius to my component not an outer radius. I have a plain div and applied some styles to it : .border { width: 350px; height: 200px; border: 50px solid grey; More on stackoverflow.com
🌐 stackoverflow.com
Rounded border with only inside of border rounded.
Hello! https://playbook-nth.squarespace.com/ PW NTH2024# Very little code experience so hoping someone could help me. I have managed to achieve rounded border bot on the outside not inside. The below works well because it scales between mobile and desktop. From my searches looks like the solution... More on forum.squarespace.com
🌐 forum.squarespace.com
7
April 23, 2024
Is it possible to create an inner-rounded, outer-square container with a single element?
But the problem is: this doesn’t actually work as expected — the outline ends up being rounded along with the border-radius (at least in modern browsers). In the past, the border-radius property did not affect the outline. But for several years now, it has. Books often contain outdated information. The first thing that comes to mind is to use a pseudo-element: https://codepen.io/evilfeijoa/pen/bNGPqMX More on reddit.com
🌐 r/css
12
1
April 10, 2025
🌐
Reddit
reddit.com › r/css › is it possible to create an inner-rounded, outer-square container with a single element?
r/css on Reddit: Is it possible to create an inner-rounded, outer-square container with a single element?
April 10, 2025 -

I'm currently reading CSS Secrets and came across a trick for making a container with a rounded inner area but a square outer edge — basically, inner border-radius, but the outer shape remains square.

The solution uses something like this:
.solution {

background: tan;

border-radius: .8em;

padding: 1em;

box-shadow: 0 0 0 .6em #655;

outline: .6em solid #655;

}

But the problem is: this doesn’t actually work as expected — the outline ends up being rounded along with the border-radius (at least in modern browsers). That kind of defeats the point.

Any ideas for achieving this effect with a single element?
I know using a wrapper is an option, but I’m curious if it can be done purely with clever CSS.

🌐
30 Seconds of Code
30secondsofcode.org › home › css › visual › perfect nested border radius in css
Perfect nested border radius in CSS - 30 seconds of code
April 3, 2022 - .outer { border-radius: 24px; padding: 8px; } .inner { border-radius: 16px; } Using CSS variables, we can make this even easier. Depending on the use case, we can adapt the formula to calculate the outer radius from the inner one, or the other ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › CSS › Guides › Backgrounds_and_borders
CSS backgrounds and borders - CSS | MDN
3 weeks ago - You can add different types of ... to CSS gradients. Borders can be square or rounded, and a different radius can be set for each corner. Elements can be rounded whether or not they have a visible border. Box shadows include inset and outset shadow, single or multiple shadows, and solid or allowed to fade to transparent. An outer box-shadow casts a shadow as if the border-box of the element were opaque. An inner box-shadow ...
🌐
W3Schools
w3schools.com › cssref › css3_pr_border-radius.php
CSS border-radius property
The border-radius property defines the radius of the element's corners. Tip: This property allows you to add rounded corners to elements! This property can have from one to four values.
Find elsewhere
🌐
CSS-Tricks
css-tricks.com › body-border-rounded-inside
Body Border, Rounded Inside | CSS-Tricks
March 4, 2016 - body { background: #5bb0ff; } .page-wrap { position: fixed; top: 10px; right: 10px; left: 10px; bottom: 10px; background: white; border-radius: 10px; padding: 20px; overflow-y: scroll; } ::-webkit-scrollbar-track { background: none; } ::-webkit-scrollbar { width: 10px; height: 10px; } ::-webkit-scrollbar-thumb { background: #ccc; border-radius: 5px; } Check out this Pen!
🌐
YouTube
youtube.com › watch
Perfect Nested Border Radius 👌 - YouTube
How to calculate the perfect nested border radii for your website or app design.⭐ Get my full-stack Next.js with Express & TypeScript course: https://codingi...
Published   August 17, 2023
🌐
Nikita Hlopov
nikitahl.com › adjust-element-inner-border-radius
How to adjust the element's inner border radius
August 8, 2019 - Another more proper way to fix it is to add a wrapper for the content and set the border-radius property for it. The value should be equal to a CSS calc() function. The parameter for this function should be the expression based on the formula given above. To actually make the inner border-radius effect a background property with a value equal to the border color must be set to the .content element.
🌐
Cloudinary
cloudinary.com › home › creative uses for css inner border and 3 ways to set a border
Creative Uses for CSS Inner Border and 3 Ways to Set a Border | Cloudinary
November 16, 2025 - This technique can make elements ... soft inner borders When applying inner borders, remember that border-radius can be used to soften the edges of these borders....
🌐
Medium
medium.com › design-bootcamp › getting-your-border-radius-right-a-simple-trick-for-smooth-nested-containers-f6e0025e8c53
Getting Your Border Radius Right: A Simple Trick for Smooth Nested Containers | by Jitendra Kumar | Bootcamp | Medium
October 15, 2024 - Then, add padding to that radius to determine the outer corner’s radius. For example, if your inner container has a 16px radius and you want 8px of padding, set the outer container’s radius to 16px + 8px = 24px.
🌐
Imgix
docs.imgix.com › en-US › apis › rendering › border-and-padding › inner-border-radius
Inner Border Radius | Rendering API
October 28, 2025 - For evenly-rounded borders, we recommend setting border-radius-inner to 1/2 the value of border-radius if border has a value higher than both radius values; if not, then setting to 3/4 the value of border-radius will work better.
🌐
YouTube
youtube.com › dev tutorials
CSS - Make outer and inner Element border radius perfect - YouTube
How to make css border radius of outer and inner element perfectly round.How to make round corner of outer and inner element perfect round.Perfect nested bor...
Published   November 13, 2023
Views   301
🌐
YouTube
youtube.com › watch
Creating an inverted border-radius with CSS - YouTube
The other day on Twitter, @FlorinPop pulled me into a conversation, wondering how to create inverted, round corners. Mask-image was probably the easy answer...
Published   May 25, 2023
🌐
Squarespace Forum
forum.squarespace.com › home › customize with code › rounded border with only inside of border rounded.
Rounded border with only inside of border rounded. - Customize with code - Squarespace Forum
April 23, 2024 - Hello! https://playbook-nth.squarespace.com/ PW NTH2024# Very little code experience so hoping someone could help me. I have managed to achieve rounded border bot on the outside not inside. The below works well because it scales between mobile and desktop. From my searches looks like the solution...
🌐
JsCraft
js-craft.io › home › css inner and outer border-radius
CSS inner and outer border-radius
June 10, 2023 - After some research, I've realized we can only set an outer border radius with CSS border-radius property. No direct way to set the inner radius.
🌐
Piccalilli
piccalil.li › blog › relative-rounded-corners
Relative rounded corners - Piccalilli
March 1, 2023 - An extra bonus that it’s completely configurable too, so you can drop this CSS utility wherever you need it. Here’s the utility code in full, so you can copy and paste it easier: ... .matched-radius { --matched-radius-padding: 8px; --matched-radius-inner-size: 12px; padding: var(--matched-radius-padding); border-radius: calc( var(--matched-radius-inner-size) + var(--matched-radius-padding) ); } .matched-radius__inner { border-radius: var(--matched-radius-inner-size); }
🌐
Mark Heath
markheath.net › post › keep-inside-rounded-corners-css
Keeping inside the rounded corners with CSS
April 14, 2017 - The trouble is, the inner div ends up drawing outside its containing div: What’s the solution? Well it took me a long time to track down, and initially I was using a hack by rounding the corners of the heading div with a slightly smaller corner radius.