Open In App

HTML | DOM Style borderImageSlice Property

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

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: 

  • number
  • %
  • fill
  • initial
  • inherit

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: 

HTML




<!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: 

  • Before the click: 

  • After the click: 

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

Example-2: 

HTML




<!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: 

  • Before the click: 

  • After the click: 

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

Example-3: 

HTML




<!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: 

  • Before the click: 

  • After the click: 

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

Example-4: 

HTML




<!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: 

  • Before the click: 

  • After the click: 

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

Example-5: 

HTML




<!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: 

  • Before the click: 

  • After the click: 

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

  • Google Chrome 15 and above
  • Edge 12 and above
  • Mozilla Firefox 15 and above
  • Opera 15 and above
  • Safari 6 and above
  • Internet Explorer 11 and above

 



Last Updated : 13 Jun, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads