W3docs

CSS border-image-width Property

The CSS border-image-width property defines the width of the border image. See examples and practice yourself.

The CSS border-image-width property defines the width of an element's border image — that is, how thick the image-based border is drawn around the box. It is one of the CSS3 properties.

When to use it

You only need border-image-width when an element already has a border image set with border-image-source (and usually border-image-slice). On its own it does nothing.

A key gotcha: border-image-width is not the same as the regular border-width. The plain border-width reserves space in the box model and affects layout, while border-image-width only controls how wide the image is painted in that border region. If you make the image wider than the actual border, it can overflow inward over the element's padding/content without pushing other content around. That is why most examples set a transparent border first and then size the image with border-image-width.

Accepted value types

The width of each side can be expressed in several ways:

  • <length> — a fixed size such as 20px.
  • <number> — a multiplier of the corresponding border-width. border-image-width: 2 means "twice the border width". This is the type used by the initial value 1.
  • <percentage> — relative to the size of the border-image area (horizontal percentages use its width, vertical ones its height).
  • auto — uses the intrinsic width/height of the matching border-image-slice, or the corresponding border-width if no intrinsic size exists.

How many values to use

border-image-width accepts one to four values, following the standard CSS clockwise shorthand:

  • One value — applies to all four sides.
  • Two values — first is top/bottom, second is left/right.
  • Three values — first is top, second is left/right, third is bottom.
  • Four values — top, right, bottom, left (clockwise from the top).

When a value is omitted, it mirrors the opposite side: an omitted fourth value copies the second (left = right), an omitted third copies the first (bottom = top), and an omitted second copies the first (so one value fills everything).

Initial Value1
Applies toAll elements, except internal table elements when border-collapse is collapse. It also applies to ::first-letter.
InheritedNo.
AnimatableNo.
VersionCSS3
DOM Syntaxobject.style.borderImageWidth = "20px";

Syntax

Syntax of CSS border-image-width Property

border-image-width: number | % | auto | initial | inherit;

Example of the border-image-width property:

Example of CSS border-image-width Property with px value

<!DOCTYPE html>
<html>
  <head>
    <style>
      .border {
        border: 10px solid transparent;
        padding: 20px;
        border-image: url("/uploads/media/default/0001/01/812bf6a749522b8185c1beee20dd99dd6c6c87da.jpeg") round;
        border-image-slice: 20;
        border-image-repeat: round;
        border-image-width: 20px;
      }
    </style>
  </head>
  <body>
    <h1>Border-image-width Example</h1>
    <p class="border">Here the border-image-width is set to 20px.</p>
  </body>
</html>

Result

CSS border-image-width Property

Here is another example where you can see what will be changed if one, two, three or four values are used.

Example of the border-image-width property with different values:

Example of CSS border-image-width Property with two, three and four values

<!DOCTYPE html>
<html>
  <head>
    <style>
      .border1 {
        border: 10px solid transparent;
        padding: 20px;
        border-image: url("/uploads/media/default/0001/01/812bf6a749522b8185c1beee20dd99dd6c6c87da.jpeg");
        border-image-slice: 10%;
        border-image-repeat: round;
        border-image-width: 20px;
      }
      .border2 {
        border: 10px solid transparent;
        padding: 20px;
        border-image: url("/uploads/media/default/0001/01/812bf6a749522b8185c1beee20dd99dd6c6c87da.jpeg");
        border-image-slice: 10%;
        border-image-repeat: round;
        border-image-width: 20px 10px;
      }
      .border3 {
        border: 10px solid transparent;
        padding: 40px;
        border-image: url("/uploads/media/default/0001/01/812bf6a749522b8185c1beee20dd99dd6c6c87da.jpeg");
        border-image-slice: 10%;
        border-image-repeat: round;
        border-image-width: 20px 10px 40px;
      }
      .border4 {
        border: 10px solid transparent;
        padding: 55px;
        border-image: url("/uploads/media/default/0001/01/812bf6a749522b8185c1beee20dd99dd6c6c87da.jpeg");
        border-image-slice: 10%;
        border-image-repeat: round;
        border-image-width: 20px 10px 40px 55px;
      }
    </style>
  </head>
  <body>
    <h1>The border-image-width Example</h1>
    <p class="border1">Here the border-image-width is set to 20px.</p>
    <p class="border2">Here the border-image-width is set to 20px and 10px.</p>
    <p class="border3">Here the border-image-width is set to 20px, 10px and 40px.</p>
    <p class="border4">Here the border-image-width is set to 20px, 10px, 40px and 55px.</p>
  </body>
</html>

In the example above, .border1 uses a single value for all sides, while .border4 gives each side a different width — notice how the thicker sides paint more of the image inward.

Values

ValueDescriptionPlay it
lengthA length unit (px) that defines the size of the border-width.Play it »
numberThe border width is defined as a multiple of the corresponding border-width. It must not be negative, and default value is 1.Play it »
percentageIs calculated in relation to the width of border image area for horizontal offsets and the height of the border image area for vertical offsets.Play it »
autoBorder width is made equal to the intrinsic width or height of the corresponding border-image-slice.Play it »
initialSets the property to its default value.Play it »
inheritInherits the property from its parent element.

Practice

Practice
What does the property 'border-image-width' in CSS do?
What does the property 'border-image-width' in CSS do?
Was this page helpful?