The border-color property is utilized to define the color for all four borders.
The color can be designated using:
Note: When border-color is not explicitly specified, it adopts the color of the element it belongs to. |
Example
Illustration showcasing various border colors:
p.one { border-style: solid; border-color: red; } p.two { border-style: solid; border-color: green; } p.three { border-style: dotted; border-color: blue; } |
Outcome:
The border-color property can accept anywhere from one to four values, corresponding to the top, right, bottom, and left borders, respectively.
Example
p.one { border-style: solid; border-color: red green blue yellow; /* red top, green right, blue bottom and yellow left */ } |
You can also define the border color using a hexadecimal value (HEX).
Example
p.one { border-style: solid; border-color: #ff0000; /* red */ } |
Alternatively, you can specify the border color by using RGB values.
Example
p.one { border-style: solid; border-color: rgb(255, 0, 0); /* red */ } |
HSL values can also be utilized for specifying the border color.
Example
p.one { border-style: solid; border-color: hsl(0, 100%, 50%); /* red */ } |
For more information on HEX, RGB, and HSL values, refer to our CSS Colors chapters. |