CSS Border Width
In this page:
selector {
border-width: thin | medium | thick | length;
}
Keyword Widths
border-width accepts the keywords thin, medium (the default), and thick. These map to browser-defined pixel values that aren't identical across browsers, so for pixel-precise designs an explicit length unit is generally preferred over the keywords.
- Accepted values:
- length — any non-negative size like 2px or 0.25rem
- thin — usually 1px
- medium — usually 3px (default)
- thick — usually 5px
- Needs a border-style other than none to appear
- inherit | initial | unset | revert — CSS-wide keywords accepted by every property
Example: Keyword Widths
<style>
.thin { border: thin solid black; }
.medium { border: medium solid black; }
.thick { border: thick solid black; }
</style>
<div class="thin">thin</div>
<div class="medium">medium</div>
<div class="thick">thick</div>
Length-Based Widths
Any CSS length unit works for border-width: px for exact pixel control, em/rem to scale with font size, or percentages are notably NOT allowed for border-width (unlike padding/margin).
- Accepted values:
- length — e.g. 1px, 4px or 0.1em
- thin | medium | thick — keywords
- 0 — removes the width
- one to four values — top, right, bottom, left order
- inherit | initial | unset | revert — CSS-wide keywords accepted by every property
Example: Length-Based Widths
<style>
.px { border: 3px solid black; }
.rem { border: 0.2rem solid black; }
</style>
<div class="px">3px</div>
<div class="rem">0.2rem</div>
Border Width Requires a Style
Just like color, a border-width value has no visible effect unless border-style is also set to something other than none — width alone doesn't make a border appear.
Example: Border Width Requires a Style
<style>
.no-style { border-width: 5px; }
.with-style { border-width: 5px; border-style: solid; }
</style>
<div class="no-style">Invisible: no border-style</div>
<div class="with-style">Visible</div>
Per-Side Widths
border-top-width, border-right-width, border-bottom-width, and border-left-width set each side's thickness independently, letting you build asymmetric borders like a thick left accent bar with thin borders elsewhere.
- Accepted values:
- length — e.g. 1px, 4px or 0.1em
- thin | medium | thick — keywords
- 0 — removes the width
- border-top-width etc. — take one width each
- inherit | initial | unset | revert — CSS-wide keywords accepted by every property
Example: Per-Side Widths
<style>
.box {
border-style: solid;
border-left-width: 8px;
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
}
</style>
<div class="box">Thick left accent bar</div>
Width in the Shorthand
Inside the border shorthand (border: width style color), width can be a keyword or length and must come first if all three values are present, though the shorthand also tolerates omitting values.
- Accepted values:
- width — length or thin, medium, thick
- style — solid, dashed, dotted, double and others
- color — any color value
- values may appear in any order
- style — required for the border to appear
- inherit | initial | unset | revert — CSS-wide keywords accepted by every property
Example: Width in the Shorthand
<style>
.box {
border: 4px solid navy;
}
</style>
<div class="box">Width comes first in the shorthand</div>
- Setting
border-width: 5pxwithout aborder-style, so nothing is shown. - Writing a width without a unit, as in
border-width: 5, which is invalid (only0is allowed). - Using a negative width, which is invalid.
Supported in all modern browsers: Chrome, Firefox, Safari, Edge and Opera.
Chapter Quiz — Complete all 21 topics to unlock
0/21 topics done
Complete these topics first:
- CSS Colors
- CSS RGB Colors
- CSS HEX Colors
- CSS HSL Colors
- CSS Color Keywords
- CSS Backgrounds
- CSS Background Color
- CSS Background Image
- CSS Background Repeat
- CSS Background Attachment
- CSS Background Shorthand
- CSS Multiple Backgrounds
- CSS Background Size
- CSS Background Origin
- CSS Background Clip
- CSS Borders
- CSS Border Style
- CSS Border Width
- CSS Border Color
- CSS Border Sides
- CSS Border Shorthand