Open In App

HTML | DOM Style borderImageSlice Property

The borderImageSlice property is used to specify the inward offsets of the image border. The user can specify the value of this property in terms of percentage, number or global values.

Syntax: 



object.style.borderImageSlice = "number|%|fill|initial|inherit"

Return Values: It returns a  string value, which represents the border-image-slice property of an element

Property Values: 



1. number: The borderImageSlice property can take the number as the value where this number represents the pixels in the image or vector coordinates (if the image is vector image).

Example-1: 




<!DOCTYPE html>
<html>
 
<head>
    <style>
        div {
            background-color: green;
            border: 30px solid transparent;
            border-image: url(
            border-image-slice: 40;
            border-image-width: 1 1 1 1;
            border-image-outset: 0;
            border-image-repeat: round;
        }
    </style>
</head>
 
<body>
    <center>
        <div id="main">
             
 
<p>
                GeeksforGeeks :
              A computer science portal for geeks.
            </p>
 
 
        </div>
        <p style="color:green;">Click below</p>
 
 
       
        <button onclick="myFunction()">Change</button>
    </center>
 
    <script>
        function myFunction() {
           
            document.getElementById(
              "main").style.borderImageSlice = "30";
        }
    </script>
</body>
 
</html>

Output: 

2. percentage(%): Percentage are relative to the size of the image whose default value is 100%. 

Example-2: 




<!DOCTYPE html>
<html>
 
<head>
    <style>
        div {
            background-color: green;
            border: 30px solid transparent;
            border-image: url(
            border-image-slice: 40;
            border-image-width: 1 1 1 1;
            border-image-outset: 0;
            border-image-repeat: round;
        }
    </style>
</head>
 
<body>
    <center>
        <div id="main">
             
 
<p>
                GeeksforGeeks :
              A computer science portal for geeks.
            </p>
 
 
        </div>
        <p style="color:green;">Click below</p>
 
 
        <button onclick="myFunction()">Change</button>
    </center>
 
    <script>
        function myFunction() {
           
            document.getElementById(
              "main").style.borderImageSlice = "30% 30%";
        }
    </script>
</body>
 
</html>

Output: 

3. fill: It causes the middle part of the border to be preserved. 

Example-3: 




<!DOCTYPE html>
<html>
 
<head>
    <style>
        div {
            background-color: green;
            border: 30px solid transparent;
            border-image: url(
            border-image-slice: 40;
            border-image-width: 1 1 1 1;
            border-image-outset: 0;
            border-image-repeat: round;
        }
    </style>
</head>
 
<body>
    <center>
        <div id="main">
             
 
<p>
                GeeksforGeeks :
              A computer science portal for geeks.
            </p>
 
 
        </div>
        <p style="color:green;">Click below</p>
 
 
        <button onclick="myFunction()">Change</button>
    </center>
 
    <script>
        function myFunction() {
           
            document.getElementById(
              "main").style.borderImageSlice = "fill";
        }
    </script>
</body>
 
</html>

Output: 

4. initial: Set the property to its default value. Here the default value is 100%. 

Example-4: 




<!DOCTYPE html>
<html>
 
<head>
    <style>
        div {
            background-color: green;
            border: 30px solid transparent;
            border-image: url(
            border-image-slice: 40;
            border-image-width: 1 1 1 1;
            border-image-outset: 0;
            border-image-repeat: round;
        }
    </style>
</head>
 
<body>
    <center>
        <div id="main">
             
 
<p>
                GeeksforGeeks :
              A computer science portal for geeks.
            </p>
 
 
        </div>
        <p style="color:green;">Click below</p>
 
 
        <button onclick="myFunction()">Change</button>
    </center>
 
    <script>
        function myFunction() {
           
            document.getElementById(
              "main").style.borderImageSlice = "initial";
        }
    </script>
</body>
 
</html>

Output: 

5. inherit: Inherits this property from its parent element. 

Example-5: 




<!DOCTYPE html>
<html>
 
<head>
    <style>
        div {
            background-color: green;
            border: 30px solid transparent;
            border-image: url(
            border-image-slice: 40;
            border-image-width: 1 1 1 1;
            border-image-outset: 0;
            border-image-repeat: round;
        }
    </style>
</head>
 
<body>
    <center>
        <div id="main">
             
 
<p>
                GeeksforGeeks :
              A computer science portal for geeks.
            </p>
 
 
        </div>
        <p style="color:green;">Click below</p>
 
 
        <button onclick="myFunction()">Change</button>
    </center>
 
    <script>
        function myFunction() {
           
            document.getElementById(
          "main").style.borderImageSlice = "inherit";
        }
    </script>
</body>
 
</html>

Output: 

Supported Browsers: The supported browser by DOM Style borderImageSlice Property listed below:  

 


Article Tags :