CSS border-width Property

Description

The border-width CSS property is used to specify the width of an element's borders. It allows you to control the thickness of each border edge (top, right, bottom, and left) individually or set them all at once with a shorthand notation. You can assign values in various units such as pixels, ems, or percentages to determine the border thickness. For example, border-width: 2px sets all four borders to a thickness of 2 pixels, while border-width: 1px 2px 3px 4px assigns different thickness values clockwise starting from the top border. This property is often used in combination with other border-related properties like border-style and border-color to create custom border styles for elements in web design.

Initial value
See individual properties
Applies to
All elements
Inherited
No
Computed value
See individual properties
Animatable
Yes
JavaScript syntax
object.style.borderWidth

Syntax

border-width: <line-width>{1,4} 

Values

<line-width> = <length> | thin | medium | thick
  • thinLess than the default width.
  • mediumDefault value.
  • thickGreater than the default width.
  • <length>Floating-point number, followed by an absolute units designator (cm, mm, in, pt, or pc) or a relative units designator (em, ex, or px).
  • inherit

Example

<div class="border">This is an example of the border-width property using a purple solid border 2px in width.</div>
.border {
   border-style: solid;
   border-width: 2px;
   border-color: purple;
   margin: 20px;
   padding: 20px;
}

Give it a Try

Click the button below to experiment with this property.

Give it a Try!

Browser Support

The following table will show you the current browser support for the CSS border-width property.

Desktop
Edge Chrome Firefox Opera Safari
12113.51
Tablets / Mobile
Chrome Firefox Opera Safari Samsung Webview
18410.1312

Last updated by CSSPortal on: 23rd September 2023