CSS Reference ยท Borders, Outlines and Shadows
The border-width property
Reference for the CSS border-width property: set border thickness with lengths or the thin, medium and thick keywords, with one to four values.
The border-width property sets the thickness of an element's borders. It is a shorthand for border-top-width, border-right-width, border-bottom-width and border-left-width, and accepts one to four values using the same pattern as margin.
A width only shows when the matching border-style is something other than none or hidden. When the style is none, the computed width is 0, whatever you wrote.
CSS
.box { border-style: solid; border-width: 1px 4px; }
Try it
Syntax
CSS
border-width: <line-width>{1,4} /* <line-width> = <length [0,โ]> | thin | medium | thick */
- Initial value:
medium - Applies to: all elements
- Inherited: no
- Animatable: yes, as a length
- Computed value: the absolute length for each side, or
0if that side's border style isnoneorhidden
Values
| Value | Description |
|---|---|
<length> |
Any non-negative length: 2px, 0.125rem, 0.1em. Negative values and percentages are invalid. |
thin |
A thin border. Browsers use 1px. |
medium |
The default. Browsers use 3px. |
thick |
A thick border. Browsers use 5px. |
| One value | Applies to all four sides. |
| Two values | Top and bottom, then left and right. |
| Three values | Top, then left and right, then bottom. |
| Four values | Top, right, bottom, left (clockwise). |
Usage notes
- The keywords are not fixed by the specification, only their order (
thin<=medium<=thick) is. In practice all browsers use1px,3pxand5px, but writing a length is clearer. - Browsers snap widths to device pixels. A width such as
1.5pxcan render as1pxon a standard display, because border widths are rounded down to whole device pixels (with a minimum of one for non-zero values). Do not expect fractional hairlines to behave consistently. - Setting the width alone shows nothing. The initial style is
none; addborder-style: solidor use thebordershorthand. - The shorthand resets it.
border: solidresetsborder-widthtomedium. - Width affects layout. Border width is added to the element's size under
content-box, and to its inner space underborder-box. - Use
emorremfor borders that scale with text, such as underline-style borders on headings. - Animations. You can transition the width, but doing so pushes surrounding content around. Prefer animating color or
box-shadow.
Browser support
Supported in every browser.
Related
borderโ the full shorthandborder-styleโ the style that makes a width visibleborder-colorโ the coloroutline-widthโ the outline equivalent- Lessons: Borders, The Box Model