Loading
The border-color property in CSS allows you to define the color of the borders of an HTML element. It can be used to set the same color for all four sides or apply different colors to each side individually.

Note: A border-style must be declared for the border color to be visible. Without it, the border would not render even if the color is set.



Syntax:

selector {
  border-style: value;
  border-color: value;
}

You can set:

  • One value for all four sides
  • Two values: top/bottom and left/right
  • Three values: top, left/right, bottom
  • Four values: top, right, bottom, left



Ways to Set Border Color in CSS

MethodSyntax ExampleOutput
Named Colorborder-color: red;Red
Hex Codeborder-color: #FF0000Red
RGBborder-color: rgb(255, 0, 0);Red
RGBA (Transparent)border-color: rgba(255, 0, 0, 0.5);Semi-transparent Red
HSLborder-color: hsl(0, 100%, 50%);Red
HSLAborder-color: hsla(0, 100%, 50%, 0.5);Semi-transparent Red



Example: Different Border Colors

<!DOCTYPE html>
<html>
<body>
  <h2>border-color with different values</h2>

  <p style="border-style: double; border-color: red;">
    Red Color Border
  </p>

  <p style="border-style: dashed; border-color: #40a944;">
    Green Color Border
  </p>

  <p style="border-style: solid; border-color: rgb(255,200,0);">
    Yellow Color Border
  </p>

  <p style="border-style: dotted; border-color: hsl(0, 50%, 50%)">
    Brown Color Border
  </p>

  <p style="border-style: solid; border-color: red blue green yellow">
    Mixed Color Borders (Top, Right, Bottom, Left)
  </p>

</body>
</html>

Output:

Uploaded Image




Key Point

  • Always define border-style before border-color.
  • You can style all sides or individual sides using 1–4 values.
  • Supports multiple formats: named colors, hex, RGB, RGBA, HSL, HSLA.
  • Useful for adding visual emphasis and separating elements.