Set the color of the four borders using CSS

The CSS border-color property is used to set the color of the four borders of an element. You can specify different colors for each border or apply a single color to all borders.

Syntax

selector {
    border-color: value;
}

Possible Values

Value Description
color-name Specifies a color by name (e.g., red, blue)
hex-value Specifies a color using hexadecimal notation (e.g., #FF0000)
rgb-value Specifies a color using RGB values
transparent Sets the border color to transparent

Example: Four Different Border Colors

The following example sets different colors for each of the four borders −

<!DOCTYPE html>
<html>
<head>
<style>
    p {
        border-style: solid;
        border-width: 5px;
        border-color: #808000 #800000 #FF0000 #FFFF00;
        padding: 20px;
        margin: 20px;
        font-family: Arial, sans-serif;
    }
</style>
</head>
<body>
    <p>This paragraph has four different colored borders: olive (top), maroon (right), red (bottom), and yellow (left).</p>
</body>
</html>
A paragraph appears with four different colored borders: olive green on top, maroon on the right, red on the bottom, and yellow on the left.

Example: Single Border Color

You can also apply the same color to all four borders by specifying a single value −

<!DOCTYPE html>
<html>
<head>
<style>
    .single-color {
        border-style: solid;
        border-width: 3px;
        border-color: #4CAF50;
        padding: 15px;
        margin: 20px;
        background-color: #f9f9f9;
    }
</style>
</head>
<body>
    <div class="single-color">This div has a uniform green border on all sides.</div>
</body>
</html>
A light gray box with a solid green border (3px width) on all four sides containing the specified text.

Conclusion

The border-color property provides flexible control over border colors. Use one value for uniform colors or four values to create unique color combinations for each side.

Updated on: 2026-03-15T12:12:01+05:30

92 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements