Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
Set the color of the border with CSS
The border-color property in CSS specifies the color of an element's border. It works in conjunction with other border properties like border-style and border-width to create complete border styling.
Syntax
border-color: color-value;
The color value can be specified using:
- Hex codes:
#800000 - RGB values:
rgb(128, 0, 0) - Color names:
red,blue,green - HSL values:
hsl(0, 100%, 25%)
Example: Basic Border Color
<html>
<head>
<style>
p.demo {
border: 2px dashed;
border-color: #800000;
padding: 10px;
margin: 10px;
}
</style>
</head>
<body>
<p class="demo">
David Beckham is a legend.
</p>
</body>
</html>
Example: Multiple Border Colors
You can set different colors for each side of the border:
<html>
<head>
<style>
.multi-color {
border: 3px solid;
border-color: red blue green orange;
padding: 15px;
text-align: center;
}
.two-colors {
border: 2px solid;
border-color: purple yellow;
padding: 10px;
margin-top: 10px;
}
</style>
</head>
<body>
<div class="multi-color">Four different border colors</div>
<div class="two-colors">Top/bottom purple, left/right yellow</div>
</body>
</html>
Border Color Values
| Values | Description | Example |
|---|---|---|
| 1 value | All four sides | border-color: red; |
| 2 values | Top/bottom, left/right | border-color: red blue; |
| 3 values | Top, left/right, bottom | border-color: red blue green; |
| 4 values | Top, right, bottom, left | border-color: red blue green orange; |
Key Points
- The
border-colorproperty only works whenborder-styleis defined - Default border color is usually the text color of the element
- You can use
transparentas a color value - Individual sides can be set with
border-top-color,border-right-color, etc.
Conclusion
The border-color property provides flexible color control for element borders. Use it with border-style and border-width to create visually appealing border effects.
Advertisements
