border-image 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 CSS property draws an image around a given element. It replaces the element's regular border.

Note: You should specify a separate border-style in case the border image fails to load. Although the specification doesn't strictly require it, some browsers don't render the border image if border-style is none or border-width is 0.

Try it

border-image: url("../../../../../../shared-assets/images/examples/border-diamonds.png") 30;
border-image: url("../../../../../../shared-assets/images/examples/border-diamonds.png") 30 /
  19px round;
border-image: url("../../../../../../shared-assets/images/examples/border-diamonds.png") 30
  fill / 30px / 30px space;
border-image: linear-gradient(#f6b73c, #4d9f0c) 30;
border-image: repeating-linear-gradient(30deg, #4d9f0c, #9198e5, #4d9f0c 20px)
  60;
<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;
}

Constituent properties

This property is a shorthand for the following CSS properties:

Syntax

css
/* source | slice */
border-image: linear-gradient(red, blue) 27;

/* source | slice | repeat */
border-image: url("/images/border.png") 27 space;

/* source | slice | width */
border-image: linear-gradient(red, blue) 27 / 35px;

/* source | slice | width | outset | repeat */
border-image: url("/images/border.png") 27 23 / 50px 30px / 1rem round space;

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

The border-image property may be specified with anywhere from one to five of the values listed below.

Note: If the computed value of border-image-source is none, or if the image cannot be displayed, the border-style will be displayed instead.

Values

<'border-image-source'>

The source image. See border-image-source.

<'border-image-slice'>

The dimensions for slicing the source image into regions. Up to four values may be specified. See border-image-slice.

<'border-image-width'>

The width of the border image. Up to four values may be specified. See border-image-width.

<'border-image-outset'>

The distance of the border image from the element's outside edge. Up to four values may be specified. See border-image-outset.

<'border-image-repeat'>

Defines how the edge regions of the source image are adjusted to fit the dimensions of the border image. Up to two values may be specified. See border-image-repeat.

Accessibility

Assistive technology cannot parse border images. If the image contains information critical to understanding the page's overall purpose, it is better to describe it semantically in the document.

Formal definition

Initial valueas each of the properties of the shorthand:
Applies toall elements, except internal table elements when border-collapse is collapse. It also applies to ::first-letter.
Inheritedno
Percentagesas each of the properties of the shorthand:
Computed valueas each of the properties of the shorthand:
Animation typeas each of the properties of the shorthand:

Formal syntax

border-image = 
<'border-image-source'> ||
<'border-image-slice'> [ / <'border-image-width'> | / <'border-image-width'>? / <'border-image-outset'> ]? ||
<'border-image-repeat'>

<border-image-source> =
none |
<image>

<border-image-slice> =
[ <number [0,∞]> | <percentage [0,∞]> ]{1,4} &&
fill?

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

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

<border-image-repeat> =
[ stretch | repeat | round | space ]{1,2}

<image> =
<url> |
<image()> |
<image-set()> |
<cross-fade()> |
<element()> |
<gradient>

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

<image()> =
image( <image-tags>? [ <image-src>? , <color>? ]! )

<image-set()> =
image-set( <image-set-option># )

<cross-fade()> =
cross-fade( <cf-image># )

<element()> =
element( <id-selector> )

<image-tags> =
ltr |
rtl

<image-src> =
<url> |
<string>

<image-set-option> =
[ <image> | <string> ] [ <resolution> || type( <string> ) ]?

<cf-image> =
[ <image> | <color> ] &&
<percentage [0,100]>?

<id-selector> =
<hash-token>

Examples

Bitmap

In this example, we will apply a diamond pattern to an element's borders. The source for the border image is a ".png" file of 81 by 81 pixels, with three diamonds going vertically and horizontally:

Eight diamonds: four red diamonds, one in each corner, and four orange diamonds, one on each side. The middle is empty.

HTML

html
<div id="bitmap">
  This element is surrounded by a bitmap-based border image!
</div>

CSS

To match the size of a single diamond, we will use a value of 81 divided by 3, or 27, for slicing the image into corner and edge regions. To center the border image on the edge of the element's background, we will make the outset values equal to half of the width values. Finally, a repeat value of round will make the border slices fit evenly, i.e., without clipping or gaps.

css
#bitmap {
  width: 200px;
  background-color: #ffffaa;
  border: 36px solid orange;
  margin: 30px;
  padding: 10px;

  border-image: url("border.png") 27 / 36px 28px 18px 8px / 18px 14px 9px 4px
    round;
}

Result

Gradient

HTML

html
<div id="gradient">
  This element is surrounded by a gradient-based border image!
</div>

CSS

css
#gradient {
  width: 200px;
  border: 30px solid;
  border-image: repeating-linear-gradient(45deg, #ff3333, #33bbff, #ff3333 30px)
    60;
  padding: 20px;
}

Result

Rounded borders

border-radius has no effect on the border image. This is because border-image-outset is able to place the image outside the border box, so it doesn't make sense for the border image to be clipped by the border area. To create rounded borders when using a border image, you should create the image itself with rounded corners, or, in the case of a gradient, draw it as the background instead. Below, we show one approach to do this, which is to use two background-images: one that extends the border box, and another for the padding box.

HTML

html
<div id="rounded">
  This element is surrounded by a border image with rounded corners!
</div>

CSS

css
#rounded {
  width: 200px;
  /* Use transparent so the background image is visible */
  border: 10px solid transparent;
  padding: 20px;
  border-radius: 20px;
  background-image:
    linear-gradient(white, white), linear-gradient(to right, cyan, lime);
  background-origin: border-box;
  background-clip: padding-box, border-box;
}

Result

Note: There is a new background-clip: border-area value being proposed to address this use case.

Specifications

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

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
Chrome – Full support
Chrome 7 (Release date: 2010-10-19)
prefix
prefix Implemented with the vendor prefix: -webkit-
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)
prefix
prefix Implemented with the vendor prefix: -webkit-
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 3.5 (Release date: 2009-06-30)
prefix , footnote
prefix Implemented with the vendor prefix: -moz-
footnote Before Firefox 15, an earlier version of the specification was implemented, prefixed.
Firefox – Full support
Firefox 15 (Release date: 2012-08-28)
footnote
footnote Small SVGs are incorrectly stretched, because percentages in border-image-slice are computed to integers instead of floats (bug 1284797).
footnote Until Firefox 47, SVGs without viewport were not sliced correctly (bug 619500).
footnote From Firefox 48 until Firefox 49, SVGs without viewport are displayed the same as SVGs with viewport, but if the slices are not exactly 50%, they are incorrectly stretched (bug 1264809).
footnote Until Firefox 57, an issue persisted for SVGs without viewport when e10s was disabled (bug 1290782).
Opera – No support
Opera 10.5 – 12.1 (Release date: 2010-03-02)
prefix
footnote Removed in 15 and later
prefix Implemented with the vendor prefix: -o-
Opera – Full support
Opera 11 (Release date: 2010-12-16)
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 3 (Release date: 2007-10-26)
prefix
prefix Implemented with the vendor prefix: -webkit-
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)
prefix
prefix Implemented with the vendor prefix: -webkit-
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 4 (Release date: 2011-03-29)
prefix , footnote
prefix Implemented with the vendor prefix: -moz-
footnote Before Firefox for Android 15, an earlier version of the specification was implemented, prefixed.
Firefox for Android – Full support
Firefox for Android 15 (Release date: 2012-08-28)
footnote
footnote Small SVGs are incorrectly stretched, because percentages in border-image-slice are computed to integers instead of floats (bug 1284797).
footnote Until Firefox for Android 47, SVGs without viewport were not sliced correctly (bug 619500).
footnote From Firefox for Android 48 until Firefox for Android 49, SVGs without viewport are displayed the same as SVGs with viewport, but if the slices are not exactly 50%, they are incorrectly stretched (bug 1264809).
footnote Until Firefox for Android 57, an issue persisted for SVGs without viewport when e10s was disabled (bug 1290782).
Opera Android – No support
Opera Android 11 – 12.1 (Release date: 2011-03-22)
prefix
footnote Removed in 14 and later
prefix Implemented with the vendor prefix: -o-
Opera Android – Full support
Opera Android 11 (Release date: 2011-03-22)
footnote
footnote 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 2 (Release date: 2008-07-11)
prefix
prefix Implemented with the vendor prefix: -webkit-
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)
prefix
prefix Implemented with the vendor prefix: -webkit-
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 2 (Release date: 2009-10-26)
prefix
prefix Implemented with the vendor prefix: -webkit-
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote
footnote Before WebView 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 2 (Release date: 2008-07-11)
prefix
prefix Implemented with the vendor prefix: -webkit-
WebView on iOS – Full support
WebView on iOS 6 (Release date: 2012-09-10)
footnote Full support
fill
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
<gradient>
Chrome – Full support
Chrome 7 (Release date: 2010-10-19)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 29 (Release date: 2014-04-29)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 4 (Release date: 2009-06-08)
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 29 (Release date: 2014-04-29)
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 3.2 (Release date: 2010-04-03)
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 3.2 (Release date: 2010-04-03)
footnote Full support
none
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 3.5 (Release date: 2009-06-30)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 3 (Release date: 2007-10-26)
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 4 (Release date: 2011-03-29)
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 2 (Release date: 2008-07-11)
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 2 (Release date: 2008-07-11)
footnote Full support
optional <border-image-slice>
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
repeat
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 3.5 (Release date: 2009-06-30)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 3 (Release date: 2007-10-26)
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 4 (Release date: 2011-03-29)
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 2 (Release date: 2008-07-11)
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 2 (Release date: 2008-07-11)
footnote Full support
round
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 3.5 (Release date: 2009-06-30)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 3 (Release date: 2007-10-26)
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 4 (Release date: 2011-03-29)
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 2 (Release date: 2008-07-11)
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 2 (Release date: 2008-07-11)
footnote Full support
space
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 3.5 (Release date: 2009-06-30)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 3 (Release date: 2007-10-26)
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 4 (Release date: 2011-03-29)
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 2 (Release date: 2008-07-11)
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 2 (Release date: 2008-07-11)
footnote Full support
stretch
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 3.5 (Release date: 2009-06-30)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 3 (Release date: 2007-10-26)
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 4 (Release date: 2011-03-29)
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 2 (Release date: 2008-07-11)
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 2 (Release date: 2008-07-11)
footnote Full support

Legend

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

Full support
Full support
See implementation notes.
Requires a vendor prefix or different name for use.
Has more compatibility info.

See also