Skip to content

CSS border-color Property

The CSS border-color property sets the color of the four sides of an element's border. It corresponds to the following properties:

Each side can have its own value. The border-color property is used with the border-style property. If the border-width is 0, or if border-style is none or hidden, the border color will not be visible.

This property takes any CSS colors value. Default color is the current color of the element.

The border-color property can have 4 values. If it has one value, the color is applied to all four borders. If it has two values, the first value is set to the top and bottom borders, the second value is set to the right and left. If it has three values, the first one is applied to the top border, the second one to the right and left, and the third one to the bottom. If it has four values the first is set to the top, the second to the right, the third to the bottom and the fourth to the left.

Initial ValuecurrentColor
Applies toAll elements. It also applies to ::first-letter.
InheritedNo.
AnimatableYes. The borders of the box are animatable.
VersionCSS1
DOM Syntaxobject.style.borderColor = "red";

Syntax

Syntax of CSS border-color Property

css
border-color: color | transparent | initial | inherit;

Here we have an example where only one value is applied. It sets the color to all four sides of the element.

Example of the border-color property:

Example of CSS border-color Property with only one value

html
<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      .dotted {
        border-style: dotted;
        border-color: #1c87c9;
        padding: 5px;
      }
    </style>
  </head>
  <body>
    <div class="dotted">Example with blue dotted border.</div>
  </body>
</html>

Result

CSS border-color Property

Let’s see another example where four values are applied. The first one is applied to the top border, the second one to the right, the third one to the bottom and the fourth one to the left.

Example of the border-color property with 4 values:

Example of CSS border-color Property with 4 values

html
<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      .solid {
        border-style: solid;
        border-color: #1c87c9 cyan yellow #8ebf42;
        padding: 5px;
      }
    </style>
  </head>
  <body>
    <div class="solid">Example with border-color property.</div>
  </body>
</html>

You can set hexadecimal, RGB, RGBA, HSL, HSLA or color names as a value for the border-color property.

TIP

Learn more about HTML Colors.

Example of the border-color property with the "color" value:

Example of CSS border-color Property with hexadecimal, RGB, HSL and named color values

html
<!DOCTYPE html>
<html>
  <head>
    <style>
      p {
        border: 5px solid #666;
        width: 60%;
        padding: 5px;
      }
      .name {
        border-color: lightblue;
      }
      .hex {
        border-color: #1c87c9;
      }
      .rgb {
        border-color: rgba(0, 0, 0, 0.15);
      }
      .hsl {
        border-color: hsl(89, 43%, 51%);
      }
    </style>
  </head>
  <body>
    <p class="name">Border with a named color.</p>
    <p class="hex">Border with a hexadecimal value.</p>
    <p class="rgb">Border with a RGB color value.</p>
    <p class="hsl">Border with a HSL color value.</p>
  </body>
</html>

Values

ValueDescriptionPlay it
colorSets a color for the borders. Default color is the current color of the element. Color names, hexadecimal color codes, rgb(), rgba(), hsl(), hsla() can be used. Optional. Defaults to currentColor.Play it »
transparentMakes the border color transparent.Play it »
initialSets the property to its default value.Play it »
inheritInherits the property from its parent element.

Practice

Which of the following statements are true about the 'border-color' property in CSS?

Do you find this helpful?

Dual-run preview — compare with live Symfony routes.