Style borderColorProperty
Style Object
Definition and Usage
The borderColor property sets or returns the color of an element's border.
This property can accept 1 to 4 colors:
- If one color is specified, e.g., p {border-color: red} - all four borders are red.
- If two colors are specified, e.g., p {border-color: red transparent} - top and bottom borders are red, while left and right borders are transparent.
- If three colors are specified, e.g., p {border-color: red green blue} - top border is red, left and right borders are green, bottom border is blue.
- If four colors are specified, e.g., p {border-color: red green blue yellow} - top border is red, right border is green, bottom border is blue, left border is yellow.
Syntax
Set the borderColor property:
Object.style.borderColor="color|transparent|inherit"
Return the borderColor property:
Object.style.borderColor
| Value | Description |
|---|---|
| color | Specifies the color of the border. InCSS color valuesfind a complete list of possible color values. |
| transparent | Default. The color of the border is transparent (the underlying content will show through). |
| inherit | The color of the border is inherited from the parent element. |
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the borderColor 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 color of all four borders:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Rookie Tutorial (example.com)</title>
<style type="text/css">
#ex1{
border: thick solid #FF0000;
}
</style>
<script>
function displayResult(){
document.getElementById("ex1").style.borderColor="#0080FF #0000FF";
}
</script>
</head>
<body>
<div id="ex1">This is some text.</div>
<br>
<button type="button" onclick="displayResult()">Change the color of the four borders</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Rookie Tutorial (example.com)</title>
<style type="text/css">
#ex1{
border: thick solid #FF0000;
}
</style>
<script>
function displayResult(){
document.getElementById("ex1").style.borderColor="#0080FF #0000FF";
}
</script>
</head>
<body>
<div id="ex1">This is some text.</div>
<br>
<button type="button" onclick="displayResult()">Change the color of the four borders</button>
</body>
</html>
Try it Yourself »
Style Object Other Extensions