Border-image - CSS Property

border-image

Summary of characteristics of the border-image property

Quick description
Shorthand of border properties made with image.
Status
Standard
Percentages
See individual properties.
Initial value
See individual properties.
Inherited by default
No.
See individual properties.
Per grammar: serialization in the order of syntax.
W3C Module
CSS Backgrounds and Borders Module
Document status: CR (Candidate Recommendation)

Description of the border-image property.

border-image is a shorthand property, which allows you to set all the values for image-border properties in a single rule:

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

These properties allow you to create a border from an image. In other words, to replace the predefined line style (double, dotted, etc.) with an image. The creative possibilities are endless.

The image that will be used to create the border will be divided into 9 parts: one for each of the four corners, one for each of the four edges, and one for the center. The border-image-slice property defines how the image should be sliced. The nine parts don't necessarily have to be the same size.

Slicing an image for the CSS border-image property

border-image-slice also lets you decide whether part number 5 will be applied to the element's background. Otherwise, the element's background stays transparent.

After this slicing, the image parts are resized by border-image to match the border thickness. They can then be repeated or stretched to cover the entire length of the border: see border-image-repeat.

Each of the values assigned to border-image can be set differently for the four sides (except for the source). In that case, the usual CSS rules apply:

border-image with a single value
Only one value is given: it applies to all four sides of the element.
border-image with two values
Two values given: the first applies to the top and bottom sides, the second to the left and right sides.
border-image with three values
Three values indicated: they apply according to the diagram above.
border-image with four values
Four values are given: each one applies to one side of the element, starting from the top edge and going clockwise.

Border-image don't follow rounded corners. So the border-radius property doesn't work with an border-image.

If both an border-image AND a regular border are set on the same element, CSS priority rules decide which of the two borders will be displayed. Browsers are not supposed to stack both borders. See the tutorial at Priorities.

Exemples de syntaxes.

  • border-image: none;

    This value cancels the image border, which makes any simple border on the element reappear.

    border-image:none;
  • border-image: source  slice / width / outset  repeat;

    This is the general syntax of border-image: the information must be listed in this order, but only the first three are mandatory.
    You can see that the border thickness (width) and the outward offset (outset) are introduced by a slash character ( / ).

    border-image:url('img/border-image-3.png')
    30 / 30px / 0 repeat;
  • border-image: url('...') 200 / 15px;

    This syntax defines the image to use, the value to use for its cropping (200 pixels), and the border thickness (15px). The other properties are set to their default values.

    border-image:url('img/border-image-3.png')
    30 / 30px;
  • border-image: url('...') 20 15 30 12 / 15px 20px;

    Of course, all of these values can be different for each side.
    The syntax above and the example below set four values for slicing the image, and two border thicknesses.

    border-image:url('img/border-image-3.png')
    30 40 30 20 / 15px 10px;
  • border-image: initial; border-image: inherit; border-image: revert; border-image: revert-layer; border-image: revert-rule; border-image: unset;

    Common values ​​are presented on these pages: initial, inherit, revert, revert-layer, revert-rule, unset.

Examples with the border-image property.

Here are the images used for the examples below:

CSS Border-image property

border-image-1.png
45 x 45 pixels
CSS Border-image property
border-image-2.png
600 x 600 pixels
CSS Border-image property
border-image-3.png
172 x 164 pixels
Simple use of an border-image.
 
In this second example, the fill value has been added to border-image-slice. So the background of the element is filled with the central part of the border-image.

This third example shows a border that works better when the pattern is repeated rather than stretched (see border-image-repeat).

Browsers compatibility with border-image.

The ability to use an image to create a border is now well supported by browsers. The properties that define this border are also well recognized.

Column 1
Possibility to use images to create borders and, therefore, support for the border-image property.

Notes:

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

1
Using images
for borders
Estimated overall support.
97%

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 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 Introduction of the border-image shorthand property to define the characteristics of new borders made with images.
    WD
    August 02, 2002
    Working Draft.
    CR
    December 17, 2009
    Candidate Recommendation.
    PR
    REC

See also, about borders.

The specification of W3C "CSS Backgrounds and Borders Module" brings together everything related to borders and backgrounds. The border-image property is described in this standard, along with the following:

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.