Skip to content
Tutorials Center
My learning

Topics

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

One to four values

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 0 if that side's border style is none or hidden

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 use 1px, 3px and 5px, but writing a length is clearer.
  • Browsers snap widths to device pixels. A width such as 1.5px can render as 1px on 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; add border-style: solid or use the border shorthand.
  • The shorthand resets it. border: solid resets border-width to medium.
  • Width affects layout. Border width is added to the element's size under content-box, and to its inner space under border-box.
  • Use em or rem for 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.