Open In App

CSS border-color Property

Last Updated : 17 Sep, 2024
Summarize
Comments
Improve
Suggest changes
Share
Like Article
Like
Report

The CSS border-color property allows developers to define the color of an element's border, enhancing the visual design of a webpage. It works in conjunction with the border property to provide control over the appearance of borders using various color values like-named colors, hex codes, or RGB values.

By combining border color with border-style and border width, you can create custom borders. For example, using border-color: red green blue yellow; apply different colors to each side of the border, adding a creative touch to your design

Syntax

border-color: color-value;

Multiple Sides Syntax

border-color: top-color right-color bottom-color left-color;

Default Value: The current color of the element

Property Values for border-color

Here are the possible values you can use with the border-color property:

Property ValueDescriptionExample
nameSpecifies a color name"blue"
HexSpecifies a hex value"#0000ff"
RGBSpecifies an RGB value"rgb(0, 0, 255)"
transparentSets the color to transparent"transparent"

This table outlines the different ways you can define a color value in CSS, from named colors to hex.

Individual Border Color Properties

The border-color property can be set individually for each side of the element using the following specific properties

PropertyDescription
CSS border-left-color PropertyDefines the color of the left border.
CSS border-top-color PropertySpecifies the color of the top border.
CSS border-right-color PropertyDetermines the color of the right border.
CSS border-bottom-color PropertyApplies a color to the bottom border.
CSS border-block-color PropertySets the border color for logical block-level elements in one declaration.
CSS border-inline-color PropertyControls the border color for logical inline-level elements in one declaration.

We will understand each property value through the examples:

Examples of Using border-color

1. Set color-value by name:

All the 140 valid CSS color names can be assigned to the border color.

Syntax:

border-color: blue;

Example: This example illustrates the border-color property by setting the color using the name value.

HTML
<!DOCTYPE html>
<html>
<head>
    <title>CSS border-color property</title>
    <style>
    h1 {
        color: #009900;
    }
    
    p.one {
        border-style: solid;
        border-color: blue;
    }
    
    p.two {
        border-style: solid;
        border-color: blue red yellow green;
    }
    
    p.three {
        border-style: solid;
        color: green;
    }
    </style>
</head>

<body>
    <h1 align="center">GeeksforGeeks</h1>
    <p class="one">A solid blue border</p>


    <p class="two">A solid multicolor border</p>


    <p class="three">A solid inherited color border</p>


</body>
</html>

Output:

Output

2. Set Color Using Hex Value

HEX color value can be assigned to the border color. The pair of values in #rrggbb represent RGB values in the hexadecimal system.

Syntax:

border-color: #0000ff;

Example: This example illustrates the border-color property by setting the color using the hexadecimal value.

HTML
<!DOCTYPE html>
<html>
<head>
    <title>CSS border-color property</title>
    <style>
    h1 {
        color: #009900;
    }
    
    p.one {
        border-style: solid;
        border-color: #0000ff;
    }
    
    p.two {
        border-style: solid;
        border-color: #0000ff #ff0000 #ffff00 #00ff00;
    }
    </style>
</head>

<body>
    <h1 align="center">GeeksforGeeks</h1>
    <p class="one">A solid blue border</p>


    <p class="two">A solid multicolor border</p>


</body>
</html>

Output:

output

3. Set Color Using RGB Value

RGB color value can be assigned to the border color. In rgb(r, g, b) values r, g, and b can vary from 0 to 255 for each of three.

Syntax:

border-color: rgb(0, 0, 255);

Example: This example illustrates the border-color property by setting the color using the RGB value.

HTML
<!DOCTYPE html>
<html>
<head>
    <title>CSS border-color property</title>
    <style>
    h1 {
        color: #009900;
    }
    
    p.one {
        border-style: solid;
        border-color: rgb(0, 0, 255);
    }
    
    p.two {
        border-style: solid;
        border-color: rgb(0, 0, 255) 
                      rgb(255, 0, 0) 
                      rgb(255, 255, 0) 
                      rgb(0, 255, 0);
    }
    </style>
</head>

<body>
    <h1 align="center">GeeksforGeeks</h1>
    <p class="one">A solid blue border</p>


    <p class="two">A solid multicolor border</p>


</body>
</html>

Output:

output

4. Set Color to Transparent

Transparent value can be assigned to the border color. The transparent value effect is not observed as it lets pass the background color pass through it.

Syntax:

border-color: transparent;

Example: This example illustrates the border-color property by setting the color using the transparent value.

HTML
<!DOCTYPE html>
<html>
<head>
    <title>CSS border-color property</title>
    <style>
    h1 {
        color: #009900;
    }
    
    p.one {
        border-style: solid;
        border-color: transparent;
    }
    </style>
</head>

<body>
    <h1 align="center">GeeksforGeeks</h1>
    <p class="one">A transparent border</p>


</body>
</html>

Output:

Output

Notes:

The border-color property may be defined by using one, two, three, or four values, as given below:

  • If a single color value is assigned, it will set it to all sides.
  • If two color values are assigned, the first color is set to the top and bottom sides and the second color will be set to the left & right sides.
  • If three color values are assigned, the first color is set to the top, the second to the left and right, the third is set to the bottom.
  • If four-color values are assigned, the colors are set to the top, right, bottom, and left, which follows the clockwise order.

Supported Browsers

The border-color property is supported by all major browsers, including:

  • Google Chrome: Version 1.0+
  • Microsoft Edge: Version 12.0+
  • Mozilla Firefox: Version 1.0+
  • Opera: Version 3.5+
  • Safari: Version 1.0+

Note: These major browsers fully support the background-color property across various versions, ensuring consistent rendering of background colors on web pages.


Article Tags :

Similar Reads