HTML DOM Style borderColor Property


The borderColor property is used for setting or getting the border color of an element. Using the borderColor property we can manipulate the colors on each side of the border i.e. each side border having different color.

Syntax

Following is the syntax for −

Setting the borderColor property

object.style.borderColor = "color|transparent|initial|inherit"

Values

The property values are explained as follows −

Sr.NoValues & Description
1Color
For specifying the border color.
2Transparent
This makes the border color transparent and the content under it can be seen.
3initial
For setting this property to initial value.
4inherit
To inherit the parent property value

Example

Let us look at an example for the borderColor Property −

Live Demo

<!DOCTYPE html>
<html>
<head>
<style>
   #DIV1{
      width:100px;
      height:100px;
      border:solid 10px ;
      border-color: limegreen crimson;
      top: 10px;
   }
</style>
<script>
   function changeBorderColor(){
      document.getElementById("DIV1").style.borderColor="crimson limegreen";
      document.getElementById("Sample").innerHTML="The border colors are now reversed ";
   }
</script>
</head>
<body>
<div id="DIV1"></div>
<p>Reverse the above div border colors by clicking the below button</p>
<button onclick="changeBorderColor()">Change Border Color</button>
<p id="Sample"></p>
</body>
</html>

Output

This will produce the following output −

On clicking the COLLAPSE BORDER button −

Updated on: 15-Feb-2021

30 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements