HTML DOM Style borderWidth Property


The HTML DOM borderWidth property is used as a shorthand for getting or setting the border width properties for an element. It takes from one to 4 values in the following ways −

  • It assigns border-width in the clockwise direction if all 4 values are given.

  • If only one value is given then the same width is applied to all 4 borders.

  • If two values are given then top and bottom are set to first value and left and right are set to second value.

  • Following is the syntax for −

Setting the borderWidth property:

object.style.borderWidth = "thin|medium|thick|length|initial|inherit"

The property values are explained as follows −

ValueDescription
thinFor specifying the left border color. The default color is set to black
mediumThis specifies the medium border and is the default value.
thickThis specifies a thin border.
lengthThis is used for specifying the border width in length units.
initialFor setting this property to initial value.
inheritTo inherit the parent property value

Let us look at an example for the borderWidth Property −

Example

 Live Demo

<!DOCTYPE html>
<html>
<head>
<style>
   #DIV1{
      height: 100px;
      width: 200px;
      border: 10px groove orange;
      padding: 10px;
      border-width:30px;
   }
</style>
<script>
   function changeBorderWidth(){
      document.getElementById("DIV1").style.borderWidth="5px";
      document.getElementById("Sample").innerHTML="The border width is now decreased";
   }
</script>
</head>
<body>
   <div id="DIV1">SOME SAMPLE TEXT</div>
   <p>Change the above div border width by clicking the below button</p>
   <button onclick="changeBorderWidth()">Change Border Width</button>
   <p id="Sample"></p>
</body>
</html>

Output

On clicking the “Change Border Width” button −

Updated on: 23-Oct-2019

34 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements