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 −
| Value | Description |
|---|---|
| thin | For specifying the left border color. The default color is set to black |
| medium | This specifies the medium border and is the default value. |
| thick | This specifies a thin border. |
| length | This is used for specifying the border width in length units. |
| initial | For setting this property to initial value. |
| inherit | To inherit the parent property value |
Let us look at an example for the borderWidth Property −
Example
<!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 −
