CSS / Reference / border-width: Side Widths, Shorthand Order, and Box Size
CSS border-width sets the thickness of the four sides of a box. Four values apply clockwise from the top: top, right, bottom, and left. If you set a width and still cannot see the line, check whether the side has a visible style such as border-style: solid.
How one to four values map to the sides
One value applies to all sides. Two set the vertical pair, then the horizontal pair. Three set the top, the horizontal pair, and the bottom.
| Values | Top | Right | Bottom | Left |
|---|---|---|---|---|
2px |
2px | 2px | 2px | 2px |
2px 6px |
2px | 6px | 2px | 6px |
2px 6px 10px |
2px | 6px | 10px | 6px |
2px 6px 10px 14px |
2px | 6px | 10px | 14px |
Use nonnegative lengths such as 2px or 0.125rem, or the keywords thin, medium, and thick. Percentages and negative values are invalid. The current W3C specification defines the keywords as 1px, 3px, and 5px respectively.
W3C specification for border widths
Compare box sizes with the same border
Save the complete code as border-width-example.html in UTF-8 and open it in a browser. Each box declares width: 160px and the same border widths. The box model and border style vary.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Compare box sizes with the same border</title>
<style>
body { margin: 1rem; font-family: system-ui, sans-serif; }
.box {
width: 160px;
height: 48px;
border-style: solid;
border-color: #2455a3;
border-width: 2px 6px 10px 14px;
background: #eef5ff;
}
.content { box-sizing: content-box; }
.border { box-sizing: border-box; }
.missing { border-style: none; }
</style>
</head>
<body>
<p>content-box</p>
<div class="box content"></div>
<p>border-box</p>
<div class="box border"></div>
<p>border-style: none</p>
<div class="box content missing"></div>
</body>
</html>
The first two boxes have their thickest border on the left at 14px and their thinnest on top at 2px. The first box is 180px wide overall, and the second is 160px wide. The third has no visible border.
When a declared border does not appear
The third box declares the same widths, but border-style: none gives each side a computed width of zero. hidden also yields zero width. Remove the missing class from the third box to see the same border as the first.
In DevTools, inspect the style and width of the side together, such as border-left-style and border-left-width. A winning border shorthand or a declaration for an individual side can reset earlier settings.
Box sizing and layout changes
With content-box, the borders add to the declared width. With no padding in this example, the first box measures 160 + 14 + 6 = 180px. With border-box, the second box stays 160px wide overall and its content area is 140px wide.
A thicker hover border can change the box width or the room inside it. For a highlight that keeps the layout stable, reserve the thickness with a transparent border and change only its color, or use an outline. Keep keyboard focus visible.
Change the width of one side
Use border-top-width: 6px to change only the top side. The other widths stay the same. Check border-top-style if the top line is invisible.
Use border-inline-start-width for the side that follows the reading direction. In horizontal writing this is the left in left-to-right text and the right in right-to-left text. Four border-width values always refer to physical sides.
For more on the full dimensions of boxes, see CSS box-sizing.





