HTML DOM Style borderTopWidth Property


The HTML DOM borderTopWidth property is used for setting or getting the Top border width for an element.

Following is the syntax for −

Setting the borderTopWidth property −

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

The property values are explained as follows −

ValueDescription
ThinThis specifies a thin border.
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 borderTopWidth Property −

Example

 Live Demo

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

Output

On clicking the “Change Top Width” button −


Updated on: 23-Oct-2019

20 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements