CSS border-color Property
Last Updated :
17 Sep, 2024
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 Value | Description | Example |
---|
name | Specifies a color name | "blue" |
Hex | Specifies a hex value | "#0000ff" |
RGB | Specifies an RGB value | "rgb(0, 0, 255)" |
transparent | Sets 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
Property | Description |
---|
CSS border-left-color Property | Defines the color of the left border. |
CSS border-top-color Property | Specifies the color of the top border. |
CSS border-right-color Property | Determines the color of the right border. |
CSS border-bottom-color Property | Applies a color to the bottom border. |
CSS border-block-color Property | Sets the border color for logical block-level elements in one declaration. |
CSS border-inline-color Property | Controls 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:

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:

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:

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:

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.
Similar Reads
CSS @charset Rule The @charset rule specifies the character encoding used in the style sheet. The @charset must be the first element in the style sheet and if several @charset rules are defined then the only first one is used. It can not be used in the <style> element where the character set of the HTML page is
3 min read
CSS @keyframes Rule The CSS @keyframes rule defines animations by specifying keyframes that describe the styles to be applied at various points during the animation duration. It allows for smooth transitions and transformations in web elements, controlled through percentages or from-to values.Note:For optimal browser s
3 min read
CSS @media Rule The @media CSS at-rule is used to apply a different set of styles for different media/devices using the Media Queries. A Media Query is mainly used to check the height, width, resolution, and orientation(Portrait/Landscape) of the device. This CSS rule is a way out for making more out of responsive
5 min read
CSS align-content property The align-content property changes the behavior of the flex-wrap property. It aligns flex lines. It is used to specify the alignment between the lines inside a flexible container. This property defines how each flex line is aligned within a flexbox and is only applicable if flex-wrap: wrap is applie
4 min read
CSS align-items Property The align-items property in CSS is used to align flex items along the cross-axis within a flex container. It accepts values like flex-start, flex-end, center, baseline, and stretch, controlling the vertical alignment of items in a flexbox.Syntaxalign-items: normal | stretch | center | flex-start | f
7 min read
CSS align-self Property The align-self property in CSS is used to align the selected items in the flexible container in many different manners such as flex-end, center, flex-start, etc. Syntax:align-self: auto|normal|self-start|self-end|stretch|center |baseline, first baseline, last baseline|flex-start |flex-end|baseline|s
5 min read
CSS all Property The all property in CSS is the shorthand property used to set all the element's values to their initial or inherited values or in some cases used to set the values to another spreadsheet origin. This property is used to reset all the CSS properties in a document.Syntax:Â all: initial|inherit|unset|re
3 min read
CSS animation-delay Property The animation-delay property specifies a delay for the start of an animation. Defined in seconds (s) or milliseconds (ms), this value determines how long to wait before beginning the animation. Negative values start the animation as if it had already been playing for the specified duration.Syntaxani
3 min read
CSS animation-direction Property The animation-direction CSS property sets whether an animation should play forward, backward, or alternate back and forth between playing the sequence forward and backward. It controls the visual flow and repetition behavior of animations in web pages, enhancing dynamic content presentation.Syntaxan
4 min read
CSS animation-duration Property The animation-duration property in CSS is essential for controlling the length of time an animation takes to complete one cycle, making it a vital tool for creating dynamic and engaging web designs.Syntax:animation-duration: time | initial | inherit;Property Value:time: This value is used to specify
3 min read