The Wayback Machine - https://web.archive.org/web/20240717024656/https://www.geeksforgeeks.org/css-border-image-slice-property/
Open In App

CSS border-image-slice Property

Last Updated : 02 Aug, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

In CSS the border-image-slice property is used to divide or slice an image specified by border-image-source property. 
The border-slice property divides a given image into: 

  • 9 regions
  • 4 corners
  • 4 edges
  • A middle region.

Note: The middle region remains transparent as default and fill value is used to make it opaque/translucent.

The below image illustrate the regions mentioned above: 

  • The regions 1, 3, 7, and 9 are the corner regions. 
  • The regions 2, 4, 6, and 8 are the edge regions. 
  • The region 5 is the middle region.

Syntax: 

border-image-slice= value;

Default Value: Its default value is 100%.

Property values: This causes

Value Effect/Functionality
Number Represents an edge offset in pixels for raster images and coordinates for vector images. (See: vector vs raster graphics)
Percentage Represents an edge offset as a percentage of the source image’s size: the width of the image for horizontal offsets, and the height for vertical offsets.
Fill  Causes the middle region to be displayed as a background image. 
Initial  Initializes the property to its default value. 
Inherit  Inherits the value of the property from its parent element. 

The below program illustrates the border-image-slice Property: 

Example: 

HTML




<!DOCTYPE html>
<html>
   
<head>
    <title>
        CSS | border-image-slice Property
    </title>
    <style>
        body {
            text-align: center;
        }
 
        h1 {
            color: green;
        }
 
        .border1 {
            border: 10px solid transparent;
            padding: 15px;
            border-image-source:
                url(
            border-image-repeat: round;
            border-image-slice: 30;
            border-image-width: 20px;
        }
 
        .border2 {
            border: 10px solid transparent;
            padding: 15px;
            border-image-source:
                url(
            border-image-repeat: round;
            border-image-slice: 30%;
            border-image-width: 20px;
        }
 
        .border3 {
            border: 10px solid transparent;
            padding: 15px;
            border-image-source:
                url(
            border-image-repeat: round;
            border-image-slice: fill;
            border-image-width: 20px;
        }
 
        .border4 {
 
            border: 10px solid transparent;
            padding: 15px;
            border-image-source: url(
            border-image-repeat: round;
            border-image-slice: initial;
            border-image-width: 20px;
        }
 
        .border5 {
            border: 10px solid transparent;
            padding: 15px;
            border-image-source: url(
            border-image-repeat: round;
            border-image-slice: inherit;
            border-image-width: 20px;
        }
 
        div {
            margin-top: 20px;
        }
    </style>
</head>
 
<body>
    <h1>GeeksforGeeks</h1>
    <h2>border-image-slice property</h2>
    <div class="border1">Border 1</div>
    <div class="border2">Border 2</div>
    <div class="border3">Border 3</div>
    <div class="border4">Border 4</div>
    <div class="border5">Border 5</div>
</body>
   
</html>


Output: 

Supported Browser: The browser supported by the border-image property are listed below: 

  • Google Chrome 15 and above
  • Edge 12 and above
  • Firefox 15.0 and above
  • Opera 15.0 and above
  • Safari 6.0 and above


Previous Article
Next Article

Similar Reads

How to slice image specified by border-image-source in CSS ?
In this article, we will see how to add a border image as a slice image using CSS. To make the border slice image, the border-image-slice property is used. This property divides or slices an image specified by the border-image-source property. The border-image-slice property divides a given image into - 9 regions4 corners4 edgesA middle region The
2 min read
CSS border-image-outset Property
The CSS border-image-outset property is a shorthand property used to specify the distance by which an element's border image is placed outside its box. Note: The border-image-outset takes effect on the picture specified by the border-image-source. Syntax: border-image-outset: value; Property Values: ValueEffectLengthSpecifies the size of border out
2 min read
CSS border-image-repeat Property
The border-image-repeat property in CSS is used to scale and tiling the border images. It can be used to match the middle part of the border image to the size of the border. It can have either one or two values. One is for the horizontal and one for the vertical axis. Only one value is given then it applies to all sides, but two values are given it
2 min read
CSS border-image Property
The border-image property in CSS is used to set the border of an element. Syntax: border-image: source slice width outset repeat|initial|inherit; The border-image property is the combination of many properties which are listed below: border-image-sourceborder-image-sliceborder-image-widthborder-image-outsetborder-image-repeat Property Values: borde
2 min read
CSS border-image-width Property
The CSS border-image-width Property is used to set width of border image. It can be set by providing multiple values. If only one value is provided, it is applied to all four sides.When two values are specified, The first value is applied to 'top and bottom' and The second value is applied to the 'left and right'.When three values are specified, Th
2 min read
CSS border-image-source Property
The border-image-source property is used to specify the image source which is to be set as the border of an element. Syntax: border-image-source: url(image-path.png)| none| initial| inherit; Note: If the value is none, the border styles will be used. The specified image can be divided into regions with the help of border-image-slice property. Defau
1 min read
Which one should we use 'border: none' or 'border: 0 '?
In this article, we will learn the validity of CSS border properties. We can specify the no border property using CSS border: none, border-width : 0, border : 0 properties. Syntax: border: none | 0 Differences: border: noneborder : 0For this property, the browser does not render.For this property, the browser renders border-color and border-width p
1 min read
How to specify the width of the border image using CSS?
In this article, we will set the width of the border image using CSS. To set the width of the border image, we use CSS border-image-width property. The border-image-width property is used to set the width of the border-image. It can be set by providing multiple values. If only one value is provided, it is applied to all four sides.When two values a
2 min read
How to repeat border image using CSS ?
You can repeat border images using the border-image-repeat property in CSS. It is generally used for scaling and tiling the border-image. It is used to match the middle part of the border-image to the size of the border. Syntax: border-image-repeat: stretch|repeat|round|initial|inherit Note: The border-image-slice property is used to divide or slic
2 min read
How to Animate SVG with border-image using CSS ?
Scalable Vector Graphics or SVG is used to set vector-based graphics for the web. In this article, we will learn how to animate an SVG with border-image using CSS. Approach: Using the border-image property, there is an SVG element within which a rect element is defined to represent a rectangle of a set width and height. The border-image for this SV
4 min read
three90RightbarBannerImg