Skip to content
Related Articles

Related Articles

HTML | DOM Style borderImageWidth Property
  • Last Updated : 30 Jul, 2019

The Style borderImageWidth property in HTML DOM is used to set or return the width of the border image.

Syntax:

  • It returns the borderImageWidth property
    object.style.borderImageWidth
  • It is used to set the borderImageWidth property
    object.style.borderImageWidth = "number|percentage|auto|
    initial|inherit"

Property Values

  • number: It is used to set the width as a multiple of corresponding computed value of border-width. This is the default value when set to 1.

    Example 1:




    <!DOCTYPE html>
    <html>
          
    <head>
        <title>
            DOM Style borderImageWidth Property
        </title>
          
        <style>
            .item {
                height: 70px;
                border: 10px solid transparent;
                border-image: 
                border-image-slice: 60;
                border-image-repeat: round;
                text-align:center;
                padding-top:20px;
                font-size:40px;
                font-weight:bold;
            }
        </style>
    </head>
      
    <body>
        <h2>
            DOM Style borderImageWidth Property
        </h2>
          
        <p>
            Click on the button to change the 
            width of border-image
        </p>
          
        <div class = "item">
            GeeksforGeeks
        </div>
          
        <button onclick = "changeWidth()">
            Click Here!
        </button>
      
        <script>
            function changeWidth() {
                elem = document.querySelector('.item');
      
                // Setting the image width to a multiple of 3
                elem.style.borderImageWidth = '3';
            }
        </script>
    </body>
      
    </html>                    

    Output:
    Before Click on the button:
    multiple-before
    After Click on the button:
    multiple-after

  • length: It is used to set the width in terms of a length unit.

    Example:






    <!DOCTYPE html>
    <html>
          
    <head>
        <title>
            DOM Style borderImageWidth Property
        </title>
          
        <style>
            .item {
                height: 70px;
                border: 10px solid transparent;
                border-image: 
                border-image-slice: 60;
                border-image-repeat: round;
                text-align:center;
                padding-top:20px;
                font-size:40px;
                font-weight:bold;
            }
        </style>
    </head>
      
    <body>
        <h2>
            DOM Style borderImageWidth Property
        </h2>
          
        <p>
            Click on the button to change the 
            width of border-image
        </p>
          
        <div class = "item">
            GeeksforGeeks
        </div>
          
        <button onclick = "changeWidth()">
            Click Here!
        </button>
      
        <script>
            function changeWidth() {
                elem = document.querySelector('.item');
      
                // Setting the image width to a multiple of 3
                elem.style.borderImageWidth = '30px';
            }
        </script>
    </body>
      
    </html>                    

    Output:
    Before Click on the button:
    multiple-before
    After Click on the button:
    multiple-after

  • percentage: It is used to set the width in terms of percentage. Percentage is relative to the width of the border image area for horizontal offsets and the height of the border image area for vertical offsets.

    Example:




    <!DOCTYPE html>
    <html>
          
    <head>
        <title>
            DOM Style borderImageWidth Property
        </title>
          
        <style>
            .item {
                height: 70px;
                border: 10px solid transparent;
                border-image: 
                border-image-slice: 60;
                border-image-repeat: round;
                text-align:center;
                padding-top:20px;
                font-size:40px;
                font-weight:bold;
            }
        </style>
    </head>
      
    <body>
        <h2>
            DOM Style borderImageWidth Property
        </h2>
          
        <p>
            Click on the button to change the 
            width of border-image
        </p>
          
        <div class = "item">
            GeeksforGeeks
        </div>
          
        <button onclick = "changeWidth()">
            Click Here!
        </button>
      
        <script>
            function changeWidth() {
                elem = document.querySelector('.item');
      
                // Setting the image width to a multiple of 3
                elem.style.borderImageWidth = '10%';
            }
        </script>
    </body>
      
    </html>                    

    Output:
    Before Click on the button:
    multiple-before
    After Click on the button:
    multiple-after

  • auto: It makes width of the border equal to the intrinsic width or height of the corresponding image slice.

    Example:




    <!DOCTYPE html>
    <html>
          
    <head>
        <title>
            DOM Style borderImageWidth Property
        </title>
          
        <style>
            .item {
                height: 70px;
                border: 10px solid transparent;
                border-image: 
                border-image-slice: 60;
                border-image-repeat: round;
                text-align:center;
                padding-top:20px;
                font-size:40px;
                font-weight:bold;
            }
        </style>
    </head>
      
    <body>
        <h2>
            DOM Style borderImageWidth Property
        </h2>
          
        <p>
            Click on the button to change the 
            width of border-image
        </p>
          
        <div class = "item">
            GeeksforGeeks
        </div>
          
        <button onclick = "changeWidth()">
            Click Here!
        </button>
      
        <script>
            function changeWidth() {
                elem = document.querySelector('.item');
      
                // Setting the image width to a multiple of 3
                elem.style.borderImageWidth = 'auto';
            }
        </script>
    </body>
      
    </html>                    

    Output:
    Before Click on the button:
    multiple-before
    After Click on the button:
    multiple-after

  • initial: It is used to set borderImageWidth property to its default value.

    Example:




    <!DOCTYPE html>
    <html>
          
    <head>
        <title>
            DOM Style borderImageWidth Property
        </title>
          
        <style>
            .item {
                height: 70px;
                border: 10px solid transparent;
                border-image: 
                border-image-slice: 60;
                border-image-repeat: round;
                text-align:center;
                padding-top:20px;
                font-size:40px;
                font-weight:bold;
            }
        </style>
    </head>
      
    <body>
        <h2>
            DOM Style borderImageWidth Property
        </h2>
          
        <p>
            Click on the button to change the 
            width of border-image
        </p>
          
        <div class = "item">
            GeeksforGeeks
        </div>
          
        <button onclick = "changeWidth()">
            Click Here!
        </button>
      
        <script>
            function changeWidth() {
                elem = document.querySelector('.item');
      
                // Setting the image width to a multiple of 3
                elem.style.borderImageWidth = 'initial';
            }
        </script>
    </body>
      
    </html>                    

    Output:
    Before Click on the button:
    multiple-before
    After Click on the button:
    multiple-after

  • inherit: It inherits the property from its parent.

    Example:




    <!DOCTYPE html>
    <html>
          
    <head>
        <title>
            DOM Style borderImageWidth Property
        </title>
          
        <style>
            .item {
                height: 70px;
                border: 10px solid transparent;
                border-image: 
                border-image-slice: 60;
                border-image-repeat: round;
                text-align:center;
                padding-top:20px;
                font-size:40px;
                font-weight:bold;
            }
      
            .Geeks {
                  
                /* Setting the border-width to of parent */
                border-image-width: 30px;
            }
        </style>
    </head>
      
    <body>
          
        <h2>
            DOM Style borderImageWidth Property
        </h2>
          
        <p>
            Click on the button to change the 
            width of border-image
        </p>
      
        <div class = "Geeks">
            <div class = "item">
                GeeksforGeeks
            </div>
        </div>
          
        <button onclick = "changeWidth()">
            Click Here!
        </button>
      
        <script>
            function changeWidth() {
                elem = document.querySelector('.item');
      
                // Setting the image width to inherit
                elem.style.borderImageWidth = 'inherit';
            }
        </script>
    </body>
    </html>                    

    Output:
    Before Click on the button:
    multiple-before
    After Click on the button:
    multiple-after

Supported Browsers: The browser supported by borderImageWidth Property are listed below:

  • Chrome
  • Internet Explorer 11
  • Firefox
  • Safari 6
My Personal Notes arrow_drop_up
Recommended Articles
Page :