HTML DOM Style borderTopStyle Property


The HTML DOM borderTopStyle property is used for setting or returning the Top border style for an element.

Following is the syntax for −

Setting the borderTopStyle property −

object.style.borderTopStyle = value

The above properties are explained as follows −

ValueDescription
NoneThis is the default value specifying no border.
HiddenThis is same as "none" but will still take border space. It is basically transparent but still there.
DottedThis defines a dotted border.
DashedThis defines a dashed border.
SolidThis defines a solid border.
DoubleThis defines a double border
GrooveThis defines a 3d groove border and is the opposite of ridge.
RidgeThis defines a 3D ridged border and is the opposite of groove
InsetThis defines a 3D inset border and the effect looks like it is embossed. It produces the opposite effect of inset.
outsetThis defines a 3D inset border and the effect looks like it is embossed. It produces the opposite effect of inset.
initialFor setting this property to initial value.
inheritTo inherit the parent property value

Let us look at an example for the borderTopStyle Property minus;

Example

 Live Demo

<!DOCTYPE html>
<html>
<head>
<style>
   #DIV1{
      width:300px;
      height:100px;
      border-top: 8px solid dodgerblue;
      border-top-style: groove;
   }
</style>
<script>
   function changeTopStyle(){
      document.getElementById("DIV1").style.borderTopStyle="dashed";
      document.getElementById("Sample").innerHTML="The Top border style is now changed";
   }
</script>
</head>
<body>
   <div id="DIV1">SOME SAMPLE TEXT</div>
   <p>Change the above div Top border style by clicking the below button</p>
   <button onclick="changeTopStyle()">Change Top Style</button>
   <p id="Sample"></p>
</body>
</html>

Output

On clicking the “Change Top Style” button −

In the above example −

We have first created a div with id “DIV1” and apply a CSS style to it based on its id. The style contains the border-top style and its width mainly −

#DIV1{
   width:300px;
   height:100px;
   border-top: 8px solid dodgerblue;
   border-top-style: groove;
}
<div id="DIV1">SOME SAMPLE TEXT</div>

We then created a button “Change Top Style” that will execute changeTopStyle() method on being clicked by the user −

<button onclick="changeTopStyle()">Change Top Style</button>

The changeTopStyle() method gets the div element with id “DIV1” using getElementById() and sets its borderTopStyle style property to dashed. This change is then reflected in the paragraph with id “Sample” by displaying the given text using its innerHTML property.

function changeTopStyle(){
   document.getElementById("DIV1").style.borderTopStyle="dashed";
   document.getElementById("Sample").innerHTML="The Top border style is now changed";
}

Updated on: 23-Oct-2019

20 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements