Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Borders, Outlines and Shadows

The border-image-slice property

Reference for the CSS border-image-slice property: set the four inward cuts that split a border image into corners, edges and middle, with live examples.

The border-image-slice property decides where the border image is cut. It sets four lines measured inward from the top, right, bottom and left edges of the source image. They divide the image into nine regions: four corners, four edges and a middle. The corners are painted into the corners of the border area, the edges fill the sides, and the middle is thrown away unless you add the fill keyword.

Slicing is about the source image, not the box. How thick the drawn border is comes from border-image-width.

CSS
.frame {
  border-image-slice: 30;
}

Try it

Slice sizes

Syntax

CSS
border-image-slice: [ <number [0,โˆž]> | <percentage [0,โˆž]> ]{1,4} && fill?;
  • Initial value: 100%
  • Applies to: all elements, except internal table elements when border-collapse is collapse
  • Inherited: no
  • Animatable: yes, by computed value (numbers and percentages)
  • Computed value: one to four percentages or numbers, and optionally fill

Values

Value Description
<number> A distance in image pixels for raster images, or in coordinate units for SVG and gradients. Do not add px.
<percentage> Relative to the image's width (for left and right) or height (for top and bottom).
One to four values Same pattern as margin: one for all sides, two for vertical and horizontal, three, or four clockwise from the top.
fill Keeps the middle region and paints it as a background over the box's padding area. It can appear before or after the numbers.

Usage notes

  • No units on numbers. border-image-slice: 30px is invalid. Write 30.
  • Default surprises people. At 100% each corner takes the whole image and the edge pieces have no size, so a border image with no slice shows four scaled copies of the whole picture in the corners and nothing along the edges.
  • Slices larger than the image are clamped to the image size. If opposite slices overlap, the middle and the edges disappear.
  • Gradients. Gradient images take the size of the border image area, so the number 1 is a handy "just stretch it" value.
  • Combine with width. Match the slice to border-image-width (or to border-width) to keep the image undistorted.

Browser support

Supported in every current browser.