Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Borders, Outlines and Shadows

The border-image property

Reference for the CSS border-image shorthand: paint a picture or gradient in the border area using source, slice, width, outset and repeat, with live examples.

The border-image property draws an image, SVG or gradient in the border area of a box instead of the plain border line. The browser cuts the image into nine regions with four slice lines, puts the four corners into the box's corners, and stretches or repeats the four edge pieces along the sides. The middle piece is dropped unless you ask for it with fill.

It is a shorthand for five properties: border-image-source, border-image-slice, border-image-width, border-image-outset and border-image-repeat. The most popular modern use is a gradient border, which border-radius cannot round (see the usage notes).

CSS
.frame {
  border: 6px solid;
  border-image: linear-gradient(45deg, #f97316, #db2777) 1;
}

Try it

Gradient border
Picture frame from an SVG

Syntax

CSS
border-image: <'border-image-source'>
              || <'border-image-slice'> [ / <'border-image-width'> | / <'border-image-width'>? / <'border-image-outset'> ]?
              || <'border-image-repeat'>;
  • Initial value: none 100% / 1 / 0 stretch (each longhand at its own initial value)
  • Applies to: all elements, except internal table elements when border-collapse is collapse
  • Inherited: no
  • Animatable: the slice, width and outset parts can animate; source and repeat change discretely
  • Computed value: as specified for each longhand

Values

Part Description
Source none, a url(), or any image function such as a gradient. See border-image-source.
Slice One to four numbers or percentages, optionally with fill. Defines where the image is cut.
/ width How thick the drawn border area is. Numbers multiply border-width.
/ / outset How far the image extends outside the border box (after two slashes if width is omitted).
Repeat stretch, repeat, round or space, one or two keywords (horizontal, then vertical).

Usage notes

  • Set a border width. The image is drawn where the border is, and the box still reserves space using border-width. The default image width is 1 times the border width, so a border: 6px solid plus border-image is the usual starting point.
  • Gradients and slice 1. A gradient has no intrinsic size, so slice 1 means "one unit from each edge", which leaves every part of the border showing the matching part of the gradient.
  • No rounded corners. border-radius still rounds the background and clips content, but the border image is drawn square on top. For a rounded gradient border, layer two backgrounds with background-clip, or use a mask.
  • Order of values. The slash is required between slice, width and outset. Leaving the slice out means 100%.
  • Overriding. Writing a plain border-style afterwards does not remove the image. Set border-image: none to turn it off.
  • Accessibility and performance. It is purely decorative, so keep text contrast measured against the box's background. Large raster images cost memory, so prefer SVG or gradients.
  • Cross-origin images are fine for painting; no CORS headers are needed.

Browser support

Supported in every current browser, without prefixes.