CSS BORDER COLOR
To set the color of the borders, we use border-color property. The color can be set by following value types:
- name - simply sepecify the color name, like,
red
- hex - a hex (hexadecimal) value, like,
#ff0000
- rgb - an rgb(red,green,blue) value, like
rgb(255,0,0)
- hsl - specify an hsl value, like
hsl(0,100%,50%)
hsl is for hue, saturation and lightness. - transparent - keeps the border transparent i.e. no color.
The border-color property does not work if it is used alone. Use the border-style property to set the borders first.
For Example:
<!DOCTYPE html>
<html>
<head>
<style>
.first {
border-style: solid;
border-color: green;
}
.second {
border-style: solid;
border-color: #0000ff; /* blue hex value*/;
}
.third {
border-style: dotted;
border-color: rgb(187, 187, 187); /* grey rgb value*/;
}
.fourth{
border-style: dashed;
border-color: hsl(0, 100%, 50%); /* red hsl value*/
}
</style>
</head>
<body>
<h2>The border-color Property</h2>
<p>This property specifies the color of the four borders:</p>
<p class="first">A solid green border</p>
<p class="second">A solid blue border in hex value</p>
<p class="third">A dotted grey border in rgb value</p>
<p class="fourth">A dashed red border in hsl value</p>
</body>
</html>
Live Demo!
Output:
The border-color Property
This property specifies the color of the four borders:
A solid green border
A solid blue border in hex value
A dotted grey border in rgb value
A dashed red border in hsl value
Specific side colors
The border-color property can have different colors for different sides of the border.
For example:
<!DOCTYPE html>
<html>
<head>
<style>
p.one {
border-style: solid;
border-color: red green blue yellow;
/* red top, green right, blue bottom and yellow left */
}
</style>
</head>
<body>
<h2>The border-color Property</h2>
<p>The border-color property can have from one to four values
(for the top border, right border, bottom border, and the left border):</p>
<p class="one">A solid multicolor border</p>
</body>
</html>
Live Demo!
Output:
The border-color Property
The border-color property can have from one to four values (for the top border, right border, bottom border, and the left border):
A solid multicolor border