HTML | DOM Style borderWidth Property
The borderWidth property in HTML DOM is used to set or return the width of the border element.
Syntax:
- It is used to set the border of width.
object.style.borderWidth = value
- It returns the border width property.
object.style.borderWidth
Return Value: It returns the selected border element with the given style.
There are six different value of border-width property which are listed below:
- thick: It sets the border width to thick.
Syntax:
document.getElementById("id_name").style.borderWidth = "thick";Example :
<!DOCTYPE html><html><head><title>HTML | DOM Style borderWidth Property</title><style>div {border: 1px solid green;padding: 10px;text-align: center;}</style></head><body><divid="d1"><p>Welocme to GeeksforGeeks.!</p><p>This tutorial is onHTML | DOM Style borderWidth Property.</p></div><br><inputtype="button"onclick="myFunction()"value="Click Me.!"/><script>function myFunction() {document.getElementById("d1").style.borderWidth= "thick";}</script></body></html>chevron_rightfilter_noneOutput:
Before Click on the button:

After Click on the button:

length: It is use to set each side of the border-width to given length. The length can be set in terms of px, em, etc.
Syntax:
document.getElementById("id_name").style.borderWidth = top_px right_px bottom_px left_px;Example: This example set each side of the width of the border.
<!DOCTYPE html><html><head><title>HTML | DOM Style borderWidth Property</title><style>div {border-style: solid;border: 1px solid green;padding: 10px;text-align: center;}</style></head><body><divid="d1"><p>Welocme to GeeksforGeeks.!</p><p>This tutorial is onHTML | DOM Style borderWidth Property.</p></div><br><inputtype="button"onclick="mainFunction()"value="Click Me.!"/><script>function mainFunction() {document.getElementById("d1").style.borderWidth= "1px 7px 15px 25px";}</script></body></html>chevron_rightfilter_noneOutput:
Before Click on the button:

After Click on the button:

thin: It is used to set the border width to thin.
Syntax:
document.getElementById("id_name").style.borderWidth = "thin";Example:
<!DOCTYPE html><html><head><title>HTML | DOM Style borderWidth Property</title><style>div {border: 8px solid green;padding: 10px;text-align: center;}</style></head><body><divid="d1"><p>Welocme to GeeksforGeeks.!</p><p>This tutorial is onHTML | DOM Style borderWidth Property.</p></div><br><inputtype="button"onclick="myFunction()"value="Click Me.!"/><script>function myFunction() {document.getElementById("d1").style.borderWidth= "thin";}</script></body></html>chevron_rightfilter_noneOutput:
Before Click on the button:

After Click on the button:

medium: It is used to change the border with to medium. It is the default value of border-width.
Syntax:
document.getElementById("id_name").style.borderWidth = "medium";Example:
<!DOCTYPE html><html><head><title>HTML | DOM Style borderWidth Property</title><style>div {border: 30px solid green;padding: 10px;text-align: center;}</style></head><body><divid="d1"><p>Welocme to GeeksforGeeks.!</p><p>This tutorial is onHTML | DOM Style borderWidth Property.</p></div><br><inputtype="button"onclick="myFunction()"value="Click Me.!"/><script>function myFunction() {document.getElementById("d1").style.borderWidth= "medium";}</script></body></html>chevron_rightfilter_noneOutput:
Before Click on the button:

After Click on the button:

inherit: It specifies that the border-width property inherited from its parent element.
Syntax:
document.getElementById("id_name").style.borderWidth = "inherit";Example:
<!DOCTYPE html><html><head><title>HTML | DOM Style borderWidth Property</title><style>span {color: blue;border: 3px solid black;padding: 3px;}.d1 span {color: inherit;}div {padding: 5px;display: block;margin: 6px;}.c2 {width: 50%;height: 40%;padding: 20px;border: 2px solid green;}</style></head><body><divclass="c2"><div>This is first<span>span element</span>.</div><divclass="d1"style="color:green">This is second<spanid="gfg">span element</span>.</div><divstyle="color:red">This is third<span>span element</span>.</div></div><br><inputtype="button"onclick="myFunction()"value="Click Me.!"/><script>function myFunction() {document.getElementById("gfg").style.borderWidth= "inherit";}</script></body></html>chevron_rightfilter_noneOutput:
Before Click on the button:

After Click on the button:

initial: It sets the borderWidth property to its default value.
Syntax:
document.getElementById("id_name").style.borderWidth = "initial";Example:
<!DOCTYPE html><html><head><title>HTML | DOM Style borderWidth Property</title><style>div {border: 10px solid;border-color: green;padding: 10px;text-align: center;}</style></head><body><divid="d1"><p>Welocme to GeeksforGeeks.!</p><p>This tutorial is onHTML | DOM Style borderWidth Property. </p></div><br><inputtype="button"onclick="myFunction()"value="Click Me.!"/><script>function myFunction() {document.getElementById("d1").style.borderWidth= "initial";}</script></body></html>chevron_rightfilter_noneOutput:
Before Click on the button:

After Click on the button:

Supported Browsers: The browser supported by DOM borderWidth property are listed below:
- Google Chrome
- Internet Explorer
- Firefox
- Safari
- Opera
Recommended Posts:
- HTML | DOM Style top Property
- HTML | DOM Style right Property
- HTML | DOM Style borderLeftWidth Property
- HTML | DOM Style borderTopLeftRadius Property
- HTML | DOM Style borderTopRightRadius Property
- HTML | DOM Style overflowY Property
- HTML | DOM Style borderStyle Property
- HTML | DOM Style captionSide Property
- HTML | DOM Style backfaceVisibility Property
- HTML | DOM Style backgroundImage Property
- HTML | DOM Style wordSpacing Property
- HTML | DOM Style textDecorationLine Property
- HTML | DOM Style textAlignLast Property
- HTML | DOM Style textAlign Property
- HTML | DOM Style animationName Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



