Border doesn't support percentage... but it's still possible...

As others have pointed to CSS specification, percentages aren't supported on borders:

'border-top-width',
'border-right-width',
'border-bottom-width',
'border-left-width'
  Value:          <border-width> | inherit
  Initial:        medium
  Applies to:     all elements
  Inherited:      no
  Percentages:    N/A
  Media:          visual
  Computed value: absolute length; '0' if the border style is 'none' or 'hidden'

As you can see it says Percentages: N/A.

Non-scripted solution

You can simulate your percentage borders with a wrapper element where you would:

  1. set wrapper element's background-color to your desired border colour
  2. set wrapper element's padding in percentages (because they're supported)
  3. set your elements background-color to white (or whatever it needs to be)

This would somehow simulate your percentage borders. Here's an example of an element with 25% width side borders that uses this technique.

HTML used in the example

.faux-borders {
    background-color: #f00;
    padding: 1px 25%; /* set padding to simulate border */
}
.content {
    background-color: #fff;
}
<div class="faux-borders">
    <div class="content">
        This is the element to have percentage borders.
    </div>
</div>

Issue: You have to be aware that this will be much more complicated when your element has some complex background applied to it... Especially if that background is inherited from ancestor DOM hierarchy. But if your UI is simple enough, you can do it this way.

Scripted solution

@BoltClock mentioned scripted solution where you can programmaticaly calculate border width according to element size.

This is such an example with extremely simple script using jQuery.

var el = $(".content");
var w = el.width() / 4 | 0; // calculate & trim decimals
el.css("border-width", "1px " + w + "px");
.content { border: 1px solid #f00; }
<div class="content">
    This is the element to have percentage borders.
</div>

But you have to be aware that you will have to adjust border width every time your container size changes (i.e. browser window resize). My first workaround with wrapper element seems much simpler because it will automatically adjust width in these situations.

The positive side of scripted solution is that it doesn't suffer from background problems mentioned in my previous non-scripted solution.

Answer from Robert Koritnik on Stack Overflow
🌐
W3Schools
w3schools.com › cssref › pr_border-width.php
CSS border-width property
border-width: medium|thin|thick|length|initial|inherit; ... Set the width of the top and bottom borders to 10px, and the width of the left and right borders to 1px: ... If you want to use W3Schools services as an educational institution, team ...
🌐
W3Schools
w3schools.com › css › css_border_width.asp
CSS Border Width
p.one { border-style: solid; border-width: 5px; } p.two { border-style: solid; border-width: medium; } p.three { border-style: dotted; border-width: 2px; } p.four { border-style: dotted; border-width: thick; }
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › CSS › Reference › Properties › border-width
border-width - CSS | MDN
/* Keyword values */ border-width: thin; border-width: medium; border-width: thick; /* <length> values */ border-width: 4px; border-width: 1.2rem; /* top and bottom | left and right */ border-width: 2px 1.5em; /* top | left and right | bottom */ border-width: 1px 2em 1.5cm; /* top | right | bottom | left */ border-width: 1px 2em 0 4rem; /* Global values */ border-width: inherit; border-width: initial; border-width: revert; border-width: revert-layer; border-width: unset;
🌐
W3Schools
w3schools.com › jsref › prop_style_borderwidth.asp
HTML DOM Style borderWidth Property
Four values, like: p {border-width: thick thin medium 10px} - the top border will be thick, right border will be thin, bottom border will be medium, left border will be 10px
Top answer
1 of 10
91

Border doesn't support percentage... but it's still possible...

As others have pointed to CSS specification, percentages aren't supported on borders:

'border-top-width',
'border-right-width',
'border-bottom-width',
'border-left-width'
  Value:          <border-width> | inherit
  Initial:        medium
  Applies to:     all elements
  Inherited:      no
  Percentages:    N/A
  Media:          visual
  Computed value: absolute length; '0' if the border style is 'none' or 'hidden'

As you can see it says Percentages: N/A.

Non-scripted solution

You can simulate your percentage borders with a wrapper element where you would:

  1. set wrapper element's background-color to your desired border colour
  2. set wrapper element's padding in percentages (because they're supported)
  3. set your elements background-color to white (or whatever it needs to be)

This would somehow simulate your percentage borders. Here's an example of an element with 25% width side borders that uses this technique.

HTML used in the example

.faux-borders {
    background-color: #f00;
    padding: 1px 25%; /* set padding to simulate border */
}
.content {
    background-color: #fff;
}
<div class="faux-borders">
    <div class="content">
        This is the element to have percentage borders.
    </div>
</div>

Issue: You have to be aware that this will be much more complicated when your element has some complex background applied to it... Especially if that background is inherited from ancestor DOM hierarchy. But if your UI is simple enough, you can do it this way.

Scripted solution

@BoltClock mentioned scripted solution where you can programmaticaly calculate border width according to element size.

This is such an example with extremely simple script using jQuery.

var el = $(".content");
var w = el.width() / 4 | 0; // calculate & trim decimals
el.css("border-width", "1px " + w + "px");
.content { border: 1px solid #f00; }
<div class="content">
    This is the element to have percentage borders.
</div>

But you have to be aware that you will have to adjust border width every time your container size changes (i.e. browser window resize). My first workaround with wrapper element seems much simpler because it will automatically adjust width in these situations.

The positive side of scripted solution is that it doesn't suffer from background problems mentioned in my previous non-scripted solution.

2 of 10
45

You can also use

border-left: 9vw solid #F5E5D6;
border-right: 9vw solid #F5E5D6;     

OR

border: 9vw solid #F5E5D6;
🌐
GeeksforGeeks
geeksforgeeks.org › css › css-border-width-property
CSS Border Width Property %%page%% %%sep%% %%sitename%% - GeeksforGeeks
July 11, 2025 - <!DOCTYPE html> <html> <head> <title> ... } </style> </head> <body> <h1 style="color: green"> GeeksforGeeks </h1> <p>border-width: 5px 10px 15px</p> <!-- This div has 5px for the top, 10px for the right/left, and 15px for the ...
🌐
Programiz
programiz.com › css › border-width
CSS border-width Property (With Examples)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" href="style.css" /> <title>CSS border-width</title> </head> <body> <p class="thin">border-width: thin;</p> <p class="medium">border-width: ...
🌐
Mimo
mimo.org › glossary › css › border-width
CSS border-width: Customize element borders effortlessly
Learn CSS border-width to define border thickness precisely. Create dynamic designs, highlight elements, and improve layouts with this essential property.
Find elsewhere
🌐
Tailwind CSS
tailwindcss.com › docs › border-width
border-width - Borders - Tailwind CSS
Use utilities like border-r and border-t-4 to set the border width for one side of an element:
🌐
Quora
quora.com › What-is-border-thickness-in-HTML
What is border thickness in HTML? - Quora
Answer (1 of 2): (Photo Credit: HTML Tables ) W3Schools has great explanations in learning some more about CSS and HTML. And even Bootstrap…. (1) If you're using CSS directly than here's one of the ways in adding the border. ————————————————- (2) Also if your ...
Top answer
1 of 4
248

A pixel is the smallest unit value to render something with, but you can trick thickness with optical illusions by modifying colors (the eye can only see up to a certain resolution too).

Here is a test to prove this point:

div { border-color: blue; border-style: solid; margin: 2px; }

div.b1 { border-width: 1px; }
div.b2 { border-width: 0.1em; }
div.b3 { border-width: 0.01em; }
div.b4 { border-width: 1px; border-color: rgb(160,160,255); }
<div class="b1">Some text</div>
<div class="b2">Some text</div>
<div class="b3">Some text</div>
<div class="b4">Some text</div>

Output

Which gives the illusion that the last DIV has a smaller border width, because the blue border blends more with the white background.


Edit: Alternate solution

Alpha values may also be used to simulate the same effect, without the need to calculate and manipulate RGB values.

.container {
  border-style: solid;
  border-width: 1px;
  
  margin-bottom: 10px;
}

.border-100 { border-color: rgba(0,0,255,1); }
.border-75 { border-color: rgba(0,0,255,0.75); }
.border-50 { border-color: rgba(0,0,255,0.5); }
.border-25 { border-color: rgba(0,0,255,0.25); }
<div class="container border-100">Container 1 (alpha = 1)</div>
<div class="container border-75">Container 2 (alpha = 0.75)</div>
<div class="container border-50">Container 3 (alpha = 0.5)</div>
<div class="container border-25">Container 4 (alpha = 0.25)</div>
2 of 4
6

It's impossible to draw a line on screen that's thinner than one pixel. Try using a more subtle color for the border instead.

🌐
Codecademy
codecademy.com › docs › css › borders › border-width
CSS | Borders | border-width | Codecademy
October 21, 2023 - Set the width of the border top to 10px, right and left to medium and bottom to thick: h1 { border-color: green; border-style: dashed; border-width: 10px medium thick; } Copy to clipboard · Copy to clipboard ·
🌐
Screenstepslive
utah.screenstepslive.com › a › 1865460-basic-borders-and-line-properties
Basic Borders and Line Properties | Advanced HTML Elements | University of Utah
You can control the thickness of your borders either by setting absolute values (cm, px, pt, etc.), standardized values (thin, medium, thick), or relative values (rem, vh, %, etc.). While relative values are often considered to be the most accessible as they are responsive to the display, they ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › CSS › border
border - CSS | MDN
border = <line-width> || <line-style> || <color> <line-width> = <length [0,∞]> | thin | medium | thick <line-style> = none | hidden | dotted | dashed | solid | double | groove | ridge | inset | outset · html · <div>I have a border, an outline, and a box shadow!
🌐
W3docs
w3docs.com › learn-css › css-border.html
CSS Border | Border Width | Border Color
<!DOCTYPE html> <html> <head> <style> p.border-width-1 { border-style: solid; border-width: 6px; } p.border-width-2 { border-style: dotted; border-width: 1px; } p.border-width-3 { border-style: dotted; border-width: medium; } p.border-width-4 { border-style: double; border-width: 8px; } p.border-width-5 { border-style: double; border-width: thick; } p.border-width-6 { border-style: solid; border-width: 3px 12px 6px 18px; } </style> </head> <body> <h2>The border-width Property</h2> <p class="border-width-1">Example with border-width.</p> <p class="border-width-2">Example with border-width.</p> <p class="border-width-3">Example with border-width.</p> <p class="border-width-4">Example with border-width.</p> <p class="border-width-5">Example with border-width.</p> <p class="border-width-6">Example with border-width.</p> </body> </html>
🌐
DoFactory
dofactory.com › css › border-width
CSS border-width
<style> .border-example-multiple { padding: 15px; border-style: solid; border-color: tomato; border-width: thin thick; } </style> <div class="border-example-multiple"> border-width: thin thick </div> Try it live
🌐
TechOnTheNet
techonthenet.com › css › properties › border_width.php
CSS: border-width property
In this CSS border-width example, we have provided four values. The first value of thick would apply to the top of the element. The second value of 10px would apply to the right side of the box. The third value of 12px would apply to the bottom of the box.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › CSS › border-right-width
border-right-width - CSS | MDN
border-right-width = <line-width> <line-width> = <length [0,∞]> | thin | medium | thick · html · <div>Element 1</div> <div>Element 2</div> css · div { border: 1px solid red; margin: 1em 0; } div:nth-child(1) { border-right-width: thick; } div:nth-child(2) { border-right-width: 2em; } Loading…
🌐
SitePoint
sitepoint.com › html & css
Border Vs. Border-Width - HTML & CSS - SitePoint Forums | Web Development & Design Community
September 2, 2023 - In the following code, if there is both border and border-width, than border-width controls the width. Border controls the width when there is no border-width. Is this normal, maybe it is set so if the border-width doe…
🌐
TutorialsPoint
tutorialspoint.com › css › css_border-width.htm
CSS - border-width Property
<!DOCTYPE html> <html> <head> <style> .container { display: block; align-items: center; justify-content: center; } .properties { padding: 10px; text-align: center; } .heading { background-color:lightgray; border-style:solid; border-width: thick; } .border { border: 1px solid #e74c0c; border-width: ...