CSS border-color Property

Beginner
⏱️ 6 min read
📚 Updated: Jun 2026
🎯 4 Examples
Box Model & Layout

What You’ll Learn

The border-color property sets the color of an element’s borders. Use one color for all sides or up to four values to color top, right, bottom, and left separately.

01

Border Colors

Color all four sides.

02

One Value

Same color everywhere.

03

Four Values

Top, right, bottom, left.

04

Color Formats

Named, hex, rgb, hsl.

05

currentColor

Match text color.

06

With Style

Needs visible borders.

Definition and Usage

The border-color CSS property controls the color of an element’s border lines. It works on any element that has a visible border style and width. You can apply a uniform color across all four sides or assign different colors to each side for more expressive layouts.

Customizing border color helps elements stand out, match your brand palette, or create subtle separation between sections. It is often used together with border-width and border-style, or through the convenient border shorthand.

💡
Beginner Tip

border-color alone does not draw a border. Pair it with a style like solid and a width greater than 0, or use border: 2px solid red; in one rule.

📝 Syntax

The border-color property accepts one to four color values:

syntax.css
/* one color for all sides */
selector {
  border-color: color;
}

/* top | right | bottom | left */
selector {
  border-color: top right bottom left;
}

Basic Example

border-color.css
.box {
  border: 2px solid red;
  padding: 10px;
}

Syntax Rules

  • One value applies the same color to all four sides.
  • Two values set vertical sides first, then horizontal sides.
  • Three values set top, horizontal sides, then bottom.
  • Four values follow top, right, bottom, left order (clockwise).
  • Any valid CSS color is allowed, including currentColor and transparent.

⚡ Quick Reference

QuestionAnswer
Initial valuecurrentColor
Applies toAll four border sides
InheritedNo
AnimatableYes, as a color
Common useCards, buttons, outlines, and highlighted boxes

Default Value

The default value of border-color is currentColor. That means the border uses the element’s text color unless you set a different color explicitly.

💎 Property Values

border-color accepts any standard CSS color value.

ValueExampleMeaning
Named colorborder-color: red;Uses a CSS color keyword
Hexborder-color: #ff5733;Uses a hexadecimal color
RGBborder-color: rgb(255, 87, 51);Uses an RGB color function
HSLborder-color: hsl(9, 100%, 60%);Uses an HSL color function
currentColorborder-color: currentColor;Uses the element’s text color
transparentborder-color: transparent;Makes the border invisible while keeping layout space
red #ff5733 rgb() hsl()

Multi-Value Syntax

blue1 value — all sides
blue red2 values — vertical | horizontal
blue red green3 values — top | sides | bottom
red green blue yellow4 values — top | right | bottom | left

One Color vs Different Side Colors

Use a single value when every side should match. Use four values when each physical side needs its own color.

Uniform color

Red on every side

Four different colors

Top red, right green, bottom blue, left yellow

border-color vs related properties

PropertyTargetsBest for
border-colorAll four physical sidesSimple boxes with one or more side colors
borderWidth, style, and color togetherQuick borders in one declaration
border-top-color, etc.One physical side onlyChanging a single edge color
border-block-colorLogical block-start and block-endWriting-mode-aware vertical borders

👀 Live Preview

A box with a uniform red border on all sides:

This box has a red border.

Uses border: 3px solid #dc2626; and padding: 1rem;.

Examples Gallery

Try border-color with a uniform red border, four side colors, hex values, and currentColor.

📚 Basic Border Colors

Start with one color on all sides, then try a different color on each edge.

Example 1 — Uniform Red Border

Set a uniform border color of red for all sides of a div, using the border shorthand.

border-color-red.html
<style>
  .box {
    border: 2px solid red;
    padding: 10px;
  }
</style>

<div class="box">
  This box has a red border.
</div>
Try It Yourself

How It Works

The border shorthand sets width, style, and color together. Red applies to all four sides at once.

Example 2 — Different Color on Each Side

Set four border colors using top, right, bottom, and left order.

border-color-multi.html
<style>
  .box {
    border-width: 2px;
    border-style: solid;
    border-color: red green blue yellow;
    padding: 10px;
  }
</style>

<div class="box">
  This box has different colors for each border.
</div>
Try It Yourself

How It Works

When width and style are set separately, border-color can assign a unique color to each physical side.

🎨 Color Formats

Use hex, functional colors, and currentColor for flexible border styling.

Example 3 — Hex Border Color

Use a hexadecimal color for a brand-accurate border.

border-color-hex.css
.card {
  border-width: 3px;
  border-style: solid;
  border-color: #2563eb;
  padding: 1rem;
  border-radius: 0.5rem;
}
Try It Yourself

How It Works

Hex colors work the same as named colors for borders. They are useful when you need precise brand colors.

Example 4 — Border Matches Text with currentColor

Let the border inherit the element’s text color automatically.

border-color-current.css
.note {
  color: #059669;
  border-width: 2px;
  border-style: solid;
  border-color: currentColor;
  padding: 0.75rem;
}
Try It Yourself

How It Works

currentColor is the default border color. Setting it explicitly keeps the border synced when text color changes in themes or states.

🧠 How border-color Works

1

You set border width and style

Borders need a visible style and thickness before color can appear on screen.

Prerequisite
2

You choose one or more colors

Apply a single color or up to four values with border-color.

CSS rule
3

The browser paints each side

Each border edge uses the matching color from your value list.

Rendering
=

Colored borders

Your element gets visible, theme-ready borders that help structure the layout.

Universal Browser Support

The border-color property is supported in all major browsers, including Chrome, Firefox, Safari, Edge, Opera, and Internet Explorer. It is one of the most reliable CSS properties.

Baseline · All browsers

Reliable border colors on every platform

Chrome, Firefox, Safari, Edge, and Opera all support border-color consistently.

100% Universal support
Google ChromeAll versions
Full support
Mozilla FirefoxAll versions
Full support
Apple SafariAll versions
Full support
Microsoft EdgeAll versions
Full support
OperaAll versions
Full support
border-color property 100% supported

Bottom line: Use border-color freely in any project. It works consistently across all browsers.

Conclusion

The border-color property is a versatile CSS tool for customizing border appearance. Whether you need one matching color or a unique color on each side, it gives you precise control over how elements are outlined on the page.

Experiment with named colors, hex values, and multi-value syntax to create borders that fit your design theme and improve visual hierarchy.

💡 Best Practices

✅ Do

  • Use the border shorthand for simple one-line borders
  • Pair border-color with a visible border-style
  • Use currentColor when borders should match text
  • Check contrast between border and background colors
  • Use side longhands when only one edge needs a different color

❌ Don’t

  • Expect color alone to show a border without width and style
  • Use very low-contrast border colors on important UI controls
  • Forget the top-right-bottom-left order with four values
  • Rely on physical side colors when logical properties fit RTL layouts better
  • Overuse rainbow borders without a clear design purpose

Key Takeaways

Knowledge Unlocked

Five things to remember about border-color

Use these points when styling borders on your next layout.

5
Core concepts
02

currentColor

Default value.

Default
🖌03

1 to 4 Values

Per-side control.

Syntax
🖼️04

Any CSS Color

Named, hex, rgb, hsl.

Values
🛠05

Needs Style

Width + style required.

Usage

❓ Frequently Asked Questions

The border-color property sets the color of an element's borders. You can apply one color to all four sides or use up to four values for top, right, bottom, and left.
The initial value is currentColor, which uses the element's text color for the border.
border-color only sets color. You also need a visible border-style such as solid and a border-width greater than zero, or use the border shorthand.
Yes. Use four values in top, right, bottom, left order — for example, border-color: red green blue yellow;
border-color sets colors on all four physical sides. border-block-color targets only the logical block axis sides and adapts when writing mode changes.

Practice in the Live Editor

Open the HTML editor, try border-color, and preview colored borders instantly.

HTML Editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful