Style borderWidthProperty
Style Object
Definition and Usage
The borderWidth property sets or returns the width of an element's border.
This property can take from one to four values:
- If one value is specified, e.g.: p {border-width: thick} - all four borders are thick.
- If two values are specified, e.g.: p {border-width: thick thin} - the top and bottom borders are thick, while the left and right borders are thin.
- If three values are specified, e.g.: p {border-width: thick thin medium} - the top border is thick, the left and right borders are thin, and the bottom border is medium.
- If four values are specified, e.g.: p {border-width: thick thin medium 10px} - the top border is thick, the right border is thin, the bottom border is medium, and the left border is 10px wide.
Syntax
Set the borderWidth property:
Object.style.borderWidth="thin|medium|thick|length|inherit"
Return the borderWidth property:
Object.style.borderWidth
| Value | Description |
|---|---|
| thin | Defines a thin border. |
| medium | Default. Defines a medium border. |
| thick | Defines a thick border. |
| length | Allows you to customize the width of the border. |
| inherit | The width of the border is inherited from the parent element. |
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the borderWidth property.
Note:IE7 and earlier versions do not support the "inherit" value. IE8 supports "inherit" only if a !DOCTYPE is specified. IE9 supports "inherit".
Example
Example
Change the width of the four borders:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example Tutorial(example.com)</title>
<style type="text/css">
#ex1{
border: 1px solid #FF0000;
}
</style>
<script>
function displayResult(){
document.getElementById("ex1").style.borderWidth="thick thin";
}
</script>
</head>
<body>
<div id="ex1">This is some text</div>
<br>
<button type="button" onclick="displayResult()">Change the width of the four borders</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Example Tutorial(example.com)</title>
<style type="text/css">
#ex1{
border: 1px solid #FF0000;
}
</style>
<script>
function displayResult(){
document.getElementById("ex1").style.borderWidth="thick thin";
}
</script>
</head>
<body>
<div id="ex1">This is some text</div>
<br>
<button type="button" onclick="displayResult()">Change the width of the four borders</button>
</body>
</html>
Try it yourself »
Style Object Other Extensions