Border-image-width - CSS Property

border-image-width

Summary of characteristics of the border-image-width property

Quick description
Sets the thickness of the border when the border is made with an image.
Status
Standard
Predefined values
auto
Percentages
Calculated relative to the dimensions of the border-image area.
Initial value
1
Inherited by default
No.
Computed value: during an animation, the border-image-width property gradually changes from one value to another.
Per grammar: serialization in the order of syntax.
W3C Module
CSS Backgrounds and Borders Module
Document status: CR (Candidate Recommendation)

Syntax diagram of border-image-width.

border-image-width - Syntax DiagramSyntax diagram of the border-image-width CSS property, which defines the thickness of the image border. auto auto length | % length | % number number {1,4} {1,4}border-image-width:;border-image-width:;
Syntax diagram of the border-image-width property.
The links in the diagram provide more details about the values.
Download the diagram in SVG.

In the diagram, the bold terms are the predefined words of CSS, the other terms are described below:

  • lengthis a numeric value followed by one of CSS dimension units.
  • % is a percentage calculated relative to the size of the border-image area (which is most often the size of the element, unless border-image-outset has a value other than 0.}.
  • number is a number without a unit.
  • This syntax can be repeated from one to four times.

Description of the border-image-width property.

border-image-width} sets the width of the border-image. Besides, it enlarges or shrinks the images to fit within this thickness.

For a general overview of images in borders, see the shorthand property border-image. And to set the thickness of a regular (non-image) border, see the border-width property.

Other properties related to image borders.

Shorthand of border properties made with image.
Sets the path and file name for the image used to build the border.
Defines how the border image is clipped.
Sets the overflow of the border image.
Defines how the border image is repeated or expanded to cover the desired area.

Values for border-image-width.

    In the examples below, the image used for the border measures 45 pixels on each side. border-image-slice is set to the value 15.

    Image pour dessiner les bordures
  • border-image-width: auto;

    Value automatically determined based on the value of border-image-slice. In our examples, this property is 15.

    border-image-width:auto;
    On an image
    border-image-width:auto;
    On a gradient without dimensions.
  • border-image-width: 15px;

    From one to four values expressed with a unit of measurement (see CSS dimension units), they define the thickness of the border image.

    border-image-width:5px;
  • border-image-width: 1;

    One to four without unit values indicate a multiple relative to the border-width. Don't confuse border-width, which is the thickness of the standard border, with border-image-width, which is the thickness of the border-image.

    The default value is 1, which gives an image border the same width as a normal border.

    border-image-width:2;
    border-width:5px;
  • border-image-width: 10%;

    From one to four values expressed as a percentage. The percentages are calculated relative to the size of the border area, which is usually the same as that of the element, unless border-image-outset has a value different from zero.

    border-image-width:20%;
  • border-image-width: 10px 15px 10px 20px;

    When several values are given, separated by spaces, they set the thickness of each of the border images, following the usual CSS rules:

    If only one value is specified, it applies to all borders.

    Border-image-width with a single value
    If two values are specified, the first one handles the top and bottom edges, and the second one handles the left and right edges.
    Border-image-width with two values
    When three values are specified, they are assigned to the edges according to the diagram below.
    Border-image-width with three values
    Finally, when four values are given, they take care of the top, right, bottom, and left edges respectively.
    Border-image-width with faour values
    border-image-width:5px 15px;
  • border-image-width: initial; (1) border-image-width: inherit; border-image-width: revert; border-image-width: revert-layer; border-image-width: revert-rule; border-image-width: unset;

    See the following pages for more details: initial, inherit, revert, revert-layer, revert-rule, unset.

Animation of the border-image-width property.

The property border-image-width can be easily animated. You just need to be careful not to mix unitless values with values that have units (pixels, percentages, etc.) in the @keyframes rule. This is especially critical when you have a zero value, which must explicitly include the unit (whereas normally, you can omit it).

Access the border-image-width property via a program

Change the thickness of a border-image with Javascript.

Two variants of JavaScript code to change the value of border-image-width. The value can be specified exactly like in CSS: in pixels, percentages, or any other unit of measurement.

Javascript
let el = document.getElementById('id'); el.style['border-image-width'] = '1cm'; // or let el = document.getElementById('id'); el.style.borderImageWidth = '1cm';

Read the thickness of an border-image with Javascript.

The code below reads back the value of the border-image-width property that was set directly through the style attribute of the element (so in the HTML code). Values set in the style-sheet via a CSS selector are not taken into account.

Javascript
let el = document.getElementById('id'); let value = el.style['border-image-width']; // or let el = document.getElementById('id'); let value = el.style.borderImageWidth;

Read the computed thickness of the border-image in JavaScript.

The computed value is the one that comes from resolving the inheritance cascade. If not, the computed value is the initial value of the property (1 in the case of border-image-width).

The value is converted into pixels, no matter what unit was used to define it. However, percentages are kept as they are.

Javascript
let el = document.getElementById('id'); let value = window.getComputedStyle(el).getPropertyValue('border-image-width');

With JQuery, read or change the value of border-image-width.

Just like in JavaScript, there’s a syntax with the property name written in camel-case (borderImageWidth) and another syntax with a kebab-case notation.

JQuery

// Read the value:
$('#id').prop('border-image-width');
// Write the value:
$('#id').prop('border-image-width', '1cm');
$('#id').prop('{border-image-width': '1cm'});

With JQuery, read the computed value of border-image-width.

Like in JavaScript, the value is returned in pixels or percentages.

JQuery
let value = $('#id').css('border-image-width');

Other examples.

Find more examples on the Javascript and CSS page.

Test it yourself.

The buttons below apply the entered value to the border-image-width property and then display either the value as it was applied or the computed value. This second option lets you see how the value of border-image-width is stored (serialized). In particular, you'll notice that percentages are correctly stored as percentages. All other units are converted into pixels.

Simulator.

This simulator lets you choose the value of the border-image-width property, with the border-image-slice and border-image-source properties having been set to 10 and a radial gradient, respectively.

border-image-width :

Browsers compatibility with border-image-width.

The property border-image-width, as well as all properties related to border images, have been supported from 2015 to 2017 depending on the browsers.

Column 1
Possibility to use images to create borders and, therefore, support for the border-image property.
Column 2
Support for the property border-image-width to define the width of a border-image.

Notes:

(1) Supports the summary property but not detailed properties.
Doesn't support the space and round values

1
Using images
for borders
2
border-image-width
property
Estimated overall support.
97%
96%

Browsers on computers :

Mobile browsers :

Outdated or marginal browsers :

Internet Explorer

KaiOS Browser

Opéra Mobile

Chrome

Edge

Opéra

Safari

Safari sur IOS

Androïd Brower

Chrome pour Androïd

Firefox pour Androïd

Samsung Internet

Firefox

Baidu Browser

QQ Browser

UC Browser pour Androïd

Opéra mini

Historic of the border-image-width property.

  • CSS Backgrounds and Borders Module Level 3

    Level 3 of the specification also explains how to position the background relative to the background area, and how to crop it.
    Regarding borders, the concept of image borders is introduced, as well as the ideas of rounded corners and box shadows.

    Regarding border-image-width Introduction of borders made with an image, instead of simple paths.
    First definition of the border-image-width property.
    WD
    August 02, 2002
    Working Draft.
    CR
    December 17, 2009
    Candidate Recommendation.
    PR
    REC

See also: other features of borders and backgrounds.

The properties related to borders and backgrounds are described in the W3C specification called CSS Backgrounds and Borders Module. Here is the list:

Properties:

background
Summary of background properties.
background-attachment
Background image scrolling mode.
background-clip
Defines the extent of the background, especially in relation to the border and padding.
background-color
Sets the background color.
background-image
Defines the background image or gradient (multiple images or gradients can coexist).
background-origin
Defines a reference to position the background image.
background-position
Defines how the background image is positioned.
background-position-block
Sets the background positioning in the block direction.
background-position-inline
Sets the background positioning along the lines.
background-position-x
Sets how the background image is positioned horizontally.
background-position-y
Defines how the background image is positioned in the vertical direction.
background-repeat
Defines how the background image is repeated.
background-size
Sizing the background image.
border
A shorthand property that defines the set of border parameters: width, style and color.
border-bottom
Sets the parameters of the bottom border of the element (thickness, line style, color).
border-bottom-color
Sets the border line color for the bottom of the element.
border-bottom-left-radius
Sets the radius of the rounded corner at the bottom left.
border-bottom-right-radius
Sets the radius of the rounded corner in the lower right.
border-bottom-style
Sets the line style for the border below the element.
border-bottom-width
Sets the thickness of the border line located below the element.
border-color
Sets the border color for all four sides of the element.
border-end-end-radius
Sets the radius of the corner rounding at the end of line and end of block.
border-end-start-radius
Sets the radius of the corner rounding at the end of line and beginning of the block.
border-image
Shorthand of border properties made with image.
border-image-outset
Sets the overflow of the border image.
border-image-repeat
Defines how the border image is repeated or expanded to cover the desired area.
border-image-slice
Defines how the border image is clipped.
border-image-source
Sets the path and file name for the image used to build the border.
Border-image-width
Sets the thickness of the border when the border is made with an image.
border-left
Sets the three parameters of the left border of the element (thickness, line style, color).
border-left-color
Sets the color of the left border line of the element.
border-left-style
Sets the border style for the left side of the element.
border-left-width
Sets the thickness of the border on the left side of the element.
border-radius
Radius of rounded corners.
border-right
Sets the three parameters of the right border of the element (thickness, line style, color).
border-right-color
Sets the color of the border line on the right side of the element.
border-right-style
Sets the line style for the right border of the element.
border-right-width
Sets the thickness of the border on the right side of the element.
border-start-end-radius
Sets the radius of the corner rounding at the beginning of the line and the end of the block.
border-start-start-radius
Sets the radius of the corner rounding at the beginning of the line and the beginning of the block.
border-style
Sets the line type for some or all four borders around the element (solid, double, dotted...).
border-top
Sets the parameters of the top border of the element (thickness, line style, color).
border-top-color
Sets the color of the border line above the element.
border-top-left-radius
Sets the radius of the rounded corner at the top left.
border-top-right-radius
Sets the radius of the rounded corner in the upper-right.
border-top-style
Sets the line style for the left border of the element.
border-top-width
Sets the thickness of the border line above the element.
border-width
Sets the thickness of the border line around the element.
box-shadow
Applies a shading effect to the frames by indicating all the parameters: color, shadow shift, blur, etc.