How to Change the Border Color in CSS
border-color changes the color of a border that's already there, and leaves its width and style alone. That makes it ideal for a state such as an error: one class turns a text box's grey border red.
Syntax
<selector> {
border-color: <color>;
}
| Part | What it does |
|---|---|
<selector> | The element whose border to recolor. It needs a border with a style already. |
<color> | The new color. Two values color the top and bottom, then the left and right. |
MDN's border-color page shows how one to four values color the sides.
The Example
The example is a form with two text boxes. Both have a grey border, and the Email box, whose value is incomplete, has the class error, which turns its border red.
Step 1: Write the Code
Create a file named index.html in a text editor, such as Visual Studio Code:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Border color</title>
<style>
input {
border: 1px solid #8a8886;
}
.error {
border-color: #c50f1f;
}
</style>
</head>
<body>
<p><label>Name <input value="Ana"></label></p>
<p><label>Email <input class="error" value="ana@example"></label></p>
</body>
</html>
The input rule gives every text box a 1-pixel solid grey border. The .error rule changes only the color.
Step 2: Open It in a Browser
Double-click index.html. It opens in your browser:

The screenshot comes from Chromium 159, the open-source browser that Chrome is built on.
What Happened
- The Email box has a red border,
rgb(197, 15, 31), still 1 pixel wide and solid. - The Name box kept the grey,
rgb(138, 136, 134), because it doesn't have the class.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Setting only border-color on an element with no border | No border appears: the paragraph's border style stayed none and its width 0px | Give it a border first, such as border: 1px solid |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| No border appears | The element has no border style | Add border with a style first |
| The color doesn't change | The class isn't on the element, or the selector doesn't match | Check the class in the HTML |
FAQ
Can each side have its own color?
Yes. With two values, border-color: #c50f1f #0f6cbd, the top and bottom were red and the left and right blue.
Does border-color change the width?
No. The red border was still 1 pixel wide, as the input rule set it.
Conclusion
Give the element its border once, then use border-color wherever only the color should change, such as in an error class.
Additional Resources
- border-color, on MDN.
