CSS CSS Tutorial CSS Advanced CSS Responsive Web Design(RWD) CSS Grid CSS Properties Sass Tutorial Sass Functions



border-color

The border-color property is used to set the color of an element's border. It is a shorthand property that allows you to set the color of all four borders at once, or you can set the color of each border individually using the border-top-color, border-right-color, border-bottom-color, and border-left-color properties.

The value of the border-color property can be specified in several ways. You can use a color name, a hexadecimal value, an RGB value, or an HSL value. You can also use the keyword transparent to make the border transparent.

Here are some examples:

<!-- Set the color of all four borders to red -->
<div style="border-color: red;">...</div>

<!-- Set the color of each border individually -->
<div style="border-top-color: red;
           border-right-color: green;
           border-bottom-color: blue;
           border-left-color: yellow;">...</div>

<!-- Use a hexadecimal value -->
<div style="border-color: #ff0000;">...</div>

<!-- Use an RGB value -->
<div style="border-color: rgb(255, 0, 0);">...</div>

<!-- Use an HSL value -->
<div style="border-color: hsl(0, 100%, 50%);">...</div>

<!-- Make the border transparent -->
<div style="border-color: transparent;">...</div>

It's important to note that if you only specify one value for the border-color property, it will be applied to all four borders. If you specify two values, the first value will be applied to the top and bottom borders, and the second value will be applied to the right and left borders. If you specify three values, the first value will be applied to the top border, the second value will be applied to the right and left borders, and the third value will be applied to the bottom border.

Here's an example:

<!-- Set the color of the top and bottom borders to red,
     and the color of the right and left borders to green -->
<div style="border-color: red green;">...</div>

<!-- Set the color of the top border to red,
     the color of the right and left borders to green,
     and the color of the bottom border to blue -->
<div style="border-color: red green blue;">...</div>

The border-color property can also be used with the border-style and border-width properties to create more complex borders. For example:

<!-- Create a dashed border that is 2 pixels wide and red -->
<div style="border: 2px dashed red;">...</div>

<!-- Create a border that is 1 pixel wide, solid, and has a different color for each side -->
<div style="border-top: 1px solid red;
           border-right: 1px solid green;
           border-bottom: 1px solid blue;
           border-left: 1px solid yellow;">...</div>

Overall, the border-color property is a versatile tool for creating borders that can add visual interest and structure to your web pages.

References

Activity