border-image-width CSS property

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

The border-image-width CSS property sets the width of an element's border image.

If this property's value is greater than the element's border-width, the border image will extend beyond the padding (and/or content) edge.

Try it

border-image-width: 30px;
border-image-width: 15px 40px;
border-image-width: 2.6rem;
border-image-width: 20% 8%;
<section id="default-example">
  <div id="example-element">This is a box with a border around it.</div>
</section>
#example-element {
  width: 80%;
  height: 80%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 50px;
  background: #fff3d4;
  color: black;
  border: 30px solid;
  border-image: url("../../../../../../shared-assets/images/examples/border-diamonds.png") 30
    round;
  font-size: 1.2em;
}

Syntax

css
/* Keyword value */
border-image-width: auto;

/* <length> value */
border-image-width: 1rem;

/* <percentage> value */
border-image-width: 25%;

/* <number> value */
border-image-width: 3;

/* top and bottom | left and right */
border-image-width: 2em 3em;

/* top | left and right | bottom */
border-image-width: 5% 15% 10%;

/* top | right | bottom | left */
border-image-width: 5% 2em 10% auto;

/* Global values */
border-image-width: inherit;
border-image-width: initial;
border-image-width: revert;
border-image-width: revert-layer;
border-image-width: unset;

The border-image-width property may be specified using one, two, three, or four values chosen from the list of values below.

  • When one value is specified, it applies the same width to all four sides.
  • When two values are specified, the first width applies to the top and bottom, the second to the left and right.
  • When three values are specified, the first width applies to the top, the second to the left and right, the third to the bottom.
  • When four values are specified, the widths apply to the top, right, bottom, and left in that order (clockwise).

Values

<length-percentage>

The width of the border, specified as a <length> or a <percentage>. Percentages are relative to the width of the border image area for horizontal offsets and the height of the border image area for vertical offsets. Must not be negative.

<number>

The width of the border, specified as a multiple of the corresponding border-width. Must not be negative.

auto

The width of the border is made equal to the intrinsic width or height (whichever is applicable) of the corresponding border-image-slice. If the image does not have the required intrinsic dimension, the corresponding border-width is used instead.

Formal definition

Initial value1
Applies toall elements, except internal table elements when border-collapse is collapse. It also applies to ::first-letter.
Inheritedno
Percentagesrefer to the width or height of the border image area
Computed valueas specified, but with relative lengths converted into absolute lengths
Animation typeby computed value type

Formal syntax

border-image-width = 
[ <length-percentage [0,∞]> | <number [0,∞]> | auto ]{1,4}

<length-percentage> =
<length> |
<percentage>

Examples

Tiling a border image

This example creates a border image using the following ".png" file, which is 90 by 90 pixels:

Square image containing eight circles. The circles in each corner are light purple. The four side circles are blue. The area in the middle, where a ninth circle could fit, is blank.

Thus, each circle in the source image is 30 by 30 pixels.

HTML

html
<p>
  Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
  eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam
  voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita
  kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
</p>

CSS

css
p {
  border: 20px solid;
  border-image: url("border.png") 30 round;
  border-image-width: 16px;
  padding: 40px;
}

Result

Specifications

Specification
CSS Backgrounds and Borders Module Level 3
# border-image-width

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
border-image-width
Chrome – Full support
Chrome 16 (Release date: 2011-12-13)
footnote
footnote Before Chrome 112, a border image's absolute or percentage length width may not take precedence over a narrower border-width (bug 40541033).
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote
footnote Before Edge 112, a border image's absolute or percentage length width may not take precedence over a narrower border-width (bug 40541033).
Firefox – Full support
Firefox 13 (Release date: 2012-06-05)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote
footnote Before Opera 98, a border image's absolute or percentage length width may not take precedence over a narrower border-width (bug 40541033).
Safari – Full support
Safari 6 (Release date: 2012-07-25)
footnote Full support
Chrome Android – Full support
Chrome Android 18 (Release date: 2012-06-27)
footnote
footnote Before Chrome Android 112, a border image's absolute or percentage length width may not take precedence over a narrower border-width (bug 40541033).
Firefox for Android – Full support
Firefox for Android 14 (Release date: 2012-06-26)
footnote Full support
Opera Android – Full support
Opera Android 14 (Release date: 2013-05-21)
footnote
footnote Before Opera Android 75, a border image's absolute or percentage length width may not take precedence over a narrower border-width (bug 40541033).
Safari on iOS – Full support
Safari on iOS 6 (Release date: 2012-09-10)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1 (Release date: 2013-04-27)
footnote
footnote Before Samsung Internet 23.0, a border image's absolute or percentage length width may not take precedence over a narrower border-width (bug 40541033).
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote
footnote Before WebView Android 112, a border image's absolute or percentage length width may not take precedence over a narrower border-width (bug 40541033).
WebView on iOS – Full support
WebView on iOS 6 (Release date: 2012-09-10)
footnote Full support
auto
Chrome – Full support
Chrome 16 (Release date: 2011-12-13)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 15 (Release date: 2012-08-28)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 6 (Release date: 2012-07-25)
footnote Full support
Chrome Android – Full support
Chrome Android 18 (Release date: 2012-06-27)
footnote Full support
Firefox for Android – Full support
Firefox for Android 15 (Release date: 2012-08-28)
footnote Full support
Opera Android – Full support
Opera Android 14 (Release date: 2013-05-21)
footnote Full support
Safari on iOS – Full support
Safari on iOS 6 (Release date: 2012-09-10)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1 (Release date: 2013-04-27)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 6 (Release date: 2012-09-10)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
See implementation notes.

See also