W3docs

CSS border-width Property

CSS border-width is a shorthand property which allows you to set widths of four sides of the element’s border. See examples and try it for yourself.

The CSS border-width property sets the width of an element's border. It applies to all four sides simultaneously. You can also set the width for each side individually using the following longhand properties:

Info

The border-style property defaults to none. If you do not specify a border style, the border width will not be visible.

This property accepts one to four values. A single value applies to all four sides. Two values apply to the top/bottom and left/right sides, respectively. Three values apply to the top, left/right, and bottom sides. Four values apply to the top, right, bottom, and left sides in order.

Initial Valuemedium
InheritedNo
AnimatableYes. The width of the border is animatable.
VersionCSS1
JavaScript Syntaxobject.style.borderWidth = "1px 5px";

Syntax

Syntax of CSS border-width Property

border-width: <line-width>{1,4} | initial | inherit;

Example of the border-width property:

Example of CSS border-width Property

<!DOCTYPE html>
<html>
  <head>
    <style>
      p {
        border-style: solid;
        border-width: 1px;
        padding: 5px;
      }
    </style>
  </head>
  <body>
    <p>This paragraph's border width is set to 1px.</p>
  </body>
</html>

Example of the border-width property with three values:

Example of CSS border-width Property with px and medium values

<!DOCTYPE html>
<html>
  <head>
    <style>
      p {
        color: #666;
        padding: 5px;
        border-style: solid;
      }
      .thin {
        border-width: 1px;
      }
      .medium {
        border-width: medium;
      }
      .thick {
        border-width: 10px;
      }
    </style>
  </head>
  <body>
    <p class="thin">This paragraph's border width is set to 1px.</p>
    <p class="medium">This paragraph's border width is set to medium.</p>
    <p class="thick">This paragraph's border width is set to 10px.</p>
  </body>
</html>

Result

CSS border-width Property

Values

ValueDescriptionPlay it
mediumDefines a medium border. This is the default value. (Relative keyword with browser-defined pixel values.)Play it »
thinDefines a thin border.Play it »
thickDefines a thick border.Play it »
lengthDefines the thickness of border.Play it »
initialSets the property to its default value.Play it »
inheritInherits the property from its parent element.

Practice

Practice

Which of the following values can be used to specify the width of CSS borders?