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"

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:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    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:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    Output:

    • Before the click:
    • After the click:
  3. fill: It causes the middle part of the border to be preserved.
    Example-3:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    Output:

    • Before the click:
    • After the click:
  4. initial: Set the property to its default value. Here the default value is 100%.
    Example-4:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    Output:

    • Before the click:
    • After the click:
  5. inherit: Inherits this property from its parent element.
    Example-5:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    Output:

    • Before the click:
    • After the click:

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

  • Google Chorme
  • Edge
  • Mozilla Firefox
  • Opera
  • Safari


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.