CSS border-color Property

The border-color property sets the colors of an element's top, right, bottom, and left borders.

It is a shorthand property that accepts one to four color values. You can apply the same color to every border or assign different colors to individual sides. The property changes border colors without changing their specified widths or styles.

border-color Syntax

selector {
  border-color: #1769aa;
}

The property accepts one, two, three, or four color values.

.one-value {
  border-color: red;
}
.two-values {
  border-color: red blue;
}
.three-values {
  border-color: red blue green;
}
.four-values {
  border-color: red blue green orange;
}

Each value must be a valid CSS color. The values are separated by spaces, not commas.

CSS-Wide Keywords

.inherited {
  border-color: inherit;
}
.reset {
  border-color: initial;
}
.unset {
  border-color: unset;
}
.reverted {
  border-color: revert;
}
.layer-reverted {
  border-color: revert-layer;
}

CSS-wide keywords must be used alone rather than combined with individual color values.

Property Values

Value Description
<color> Sets a border color using a valid CSS color value, such as a named color, hexadecimal color, or color function.
currentColor Uses the element's computed color value. This is the initial value for each border side.
transparent Makes the border fully transparent without changing its used width when the border style is visible.
One color Applies the same color to all four borders.
Two colors Applies the first color to the top and bottom, and the second to the right and left.
Three colors Applies the first color to the top, the second to the right and left, and the third to the bottom.
Four colors Applies colors clockwise: top, right, bottom, and left.

CSS-Wide Keywords

Keyword Behavior
inherit Inherits the computed border colors from the parent element.
initial Resets all four border colors to currentColor.
unset Resets all four border colors to their initial values because the longhand properties are not inherited.
revert Reverts the border colors according to cascade origin rules.
revert-layer Reverts the border colors according to cascade layer rules.

The border-color shorthand sets four non-inherited longhand properties. Their initial value is currentColor, and their colors can be animated.

How It Works

The border-color property assigns colors to the four physical border sides. For the colors to be visible, the corresponding borders must have visible styles and nonzero used widths.

Setting All Border Colors

.panel {
  border: 4px solid;
  border-color: #1769aa;
}

All four borders appear blue because the shorthand assigns the same color to every side.

Changing an Existing Border Color

.panel {
  border: 3px solid #777;
  border-color: #1769aa;
}

The later declaration changes all four border colors while preserving their specified widths and styles.

Using Different Colors

.panel {
  border: 5px solid;
  border-color: red green blue orange;
}

The top border is red, the right is green, the bottom is blue, and the left is orange.

Color Without a Border Style

.panel {
  border-color: #1769aa;
}

If no other declarations set visible border styles, the borders remain invisible because their initial style is none.

Preserving Individual Styles

.panel {
  border-style: solid dashed dotted double;
  border-width: 4px;
  border-color: #1769aa;
}

All four borders use the same blue color while retaining their different line styles.

One to Four Color Values

The number of values determines which border sides receive each color. This follows the same clockwise pattern used by margin, padding, and other four-sided CSS shorthand properties.

One Value

.panel {
  border: 5px solid;
  border-color: red;
}

All four borders are red.

Two Values

.panel {
  border: 5px solid;
  border-color: red blue;
}

The top and bottom borders are red. The right and left borders are blue.

Three Values

.panel {
  border: 5px solid;
  border-color: red blue green;
}

The top border is red, the right and left borders are blue, and the bottom border is green.

Four Values

.panel {
  border: 5px solid;
  border-color: red blue green orange;
}

The colors are assigned clockwise, starting at the top: red, blue, green, and orange.

Value Assignment Summary

Number of Values Top Right Bottom Left
1 First First First First
2 First Second First Second
3 First Second Third Second
4 First Second Third Fourth

Remember the four-value order as top, right, bottom, left. This order remains physical and does not change with text direction.

Supported Color Formats

The property accepts CSS <color> values, including named colors, hexadecimal notation, functional color values, and modern color functions.

Named Colors

.named-color {
  border: 4px solid;
  border-color: steelblue;
}

Named colors provide readable values for commonly used colors.

Hexadecimal Colors

.hex-color {
  border: 4px solid;
  border-color: #1769aa;
}

Hexadecimal notation defines colors using red, green, and blue components, with optional alpha transparency.

RGB Colors

.rgb-color {
  border: 4px solid;
  border-color: rgb(23 105 170);
}

The rgb() function defines a color using red, green, and blue channels.

RGB With Transparency

.rgb-alpha {
  border: 4px solid;
  border-color: rgb(23 105 170 / 50%);
}

The alpha component makes the border partially transparent.

HSL Colors

.hsl-color {
  border: 4px solid;
  border-color: hsl(207 76% 38%);
}

The hsl() function defines colors using hue, saturation, and lightness.

HWB Colors

.hwb-color {
  border: 4px solid;
  border-color: hwb(207 9% 33%);
}

The hwb() function defines a color using hue, whiteness, and blackness.

Modern Color Functions

.lab-color {
  border: 4px solid;
  border-color: lab(45% -5 -35);
}
.oklch-color {
  border: 4px solid;
  border-color: oklch(55% 0.15 250);
}

Modern color functions provide additional ways to specify colors. Their browser compatibility should be considered separately from support for the border-color property itself.

Using color-mix()

.mixed-color {
  border: 4px solid;
  border-color: color-mix(in srgb, #1769aa 70%, white);
}

The color-mix() function calculates a color by mixing two specified colors.

Different color formats may be used together in the same border-color declaration.

Using currentColor

The currentColor keyword uses the element's computed color value. It is the initial color for each border side.

Matching Text and Border Colors

.panel {
  color: #1769aa;
  border: 3px solid currentColor;
}

The text and all four borders use the same blue color.

Omitting the Border Color

.panel {
  color: #1769aa;
  border: 3px solid;
}

Because no explicit border color is provided, the border uses currentColor.

Combining currentColor With Other Colors

.panel {
  color: #1769aa;
  border: 4px solid;
  border-color: currentColor #777;
}

The top and bottom borders match the text color. The right and left borders use gray.

Inherited Text Color

.container {
  color: #1769aa;
}
.container .panel {
  border: 3px solid currentColor;
}

The panel's color property is inherited from its parent, and its border uses that computed color.

Although border color properties are not inherited, currentColor allows borders to follow an inherited text color.

Transparent Borders

The transparent keyword creates a fully transparent border. The border can still occupy space when its style is visible and its width is nonzero.

Fully Transparent Border

.panel {
  border: 5px solid transparent;
}

The border is not visible, but its 5-pixel thickness still contributes to the element's box dimensions.

Transparent Hover Border

.button {
  border: 3px solid transparent;
}
.button:hover {
  border-color: #1769aa;
}

The border reserves space in both states, helping prevent a layout shift when the pointer moves over the button.

Partially Transparent Border

.panel {
  border: 5px solid rgb(23 105 170 / 40%);
}

The border is partially transparent, allowing underlying colors to influence its appearance.

Different Transparent Sides

.panel {
  border: 5px solid;
  border-color: transparent #1769aa transparent #1769aa;
}

The top and bottom borders are transparent. The right and left borders are blue.

Transparent vs. none

Declaration Visible Border Used Width
border: 5px solid transparent; No 5px
border: 5px none #1769aa; No 0
border: 0 solid #1769aa; No 0

Use transparent borders when invisible border space needs to be preserved. Use none or a zero width when no border thickness is needed.

Individual Border Colors

The border-color shorthand sets four individual border color properties. Each longhand can also be used independently.

Top Border Color

.panel {
  border: 4px solid #777;
  border-top-color: red;
}

Only the top border changes to red.

Right Border Color

.panel {
  border: 4px solid #777;
  border-right-color: blue;
}

Only the right border changes to blue.

Bottom Border Color

.panel {
  border: 4px solid #777;
  border-bottom-color: green;
}

Only the bottom border changes to green.

Left Border Color

.panel {
  border: 4px solid #777;
  border-left-color: orange;
}

Only the left border changes to orange.

Combining Longhand Properties

.panel {
  border: 4px solid;
  border-top-color: red;
  border-right-color: blue;
  border-bottom-color: green;
  border-left-color: orange;
}

This is equivalent to:

.panel {
  border: 4px solid;
  border-color: red blue green orange;
}

Use the shorthand for concise declarations. Use individual properties when only one border side needs a different color.

Border Shorthand Interactions

The border-color property interacts with the border shorthand and the four side-specific border shorthands.

Overriding the border Shorthand

.panel {
  border: 3px solid #777;
  border-color: #1769aa;
}

The later declaration changes all four border colors to blue.

border Shorthand After border-color

.panel {
  border-color: red blue green orange;
  border: 3px solid #777;
}

The later border shorthand resets all four border colors to gray.

Omitting the Color

.panel {
  border-color: red blue green orange;
  border: 3px solid;
}

The later shorthand resets all four border colors to currentColor.

Overriding One Side

.panel {
  border: 3px solid #777;
  border-color: #1769aa;
  border-bottom-color: orange;
}

The top, right, and left borders remain blue. The bottom border becomes orange.

Side Shorthand After border-color

.panel {
  border: 3px solid;
  border-color: red blue green orange;
  border-left: 5px dashed purple;
}

The left border becomes a 5-pixel dashed purple line. The other three sides retain their previously specified colors and styles.

border-color After Individual Longhands

.panel {
  border: 3px solid;
  border-top-color: red;
  border-bottom-color: green;
  border-color: #1769aa;
}

The later shorthand sets every border color to blue, replacing the earlier top and bottom color declarations.

These examples assume declarations with equal cascade priority. Specificity, importance, origins, and cascade layers can affect which declaration wins.

Logical vs. Physical Border Colors

The border-color shorthand assigns colors to physical sides: top, right, bottom, and left. Logical border color properties follow the writing mode and text direction.

Physical Border Colors

.physical-border {
  writing-mode: vertical-rl;
  border: 4px solid;
  border-color: red blue green orange;
}

The colors remain assigned to the same physical edges, regardless of writing mode.

Logical Border Colors

.logical-border {
  border: 4px solid #777;
  border-block-start-color: red;
  border-block-end-color: blue;
  border-inline-start-color: green;
  border-inline-end-color: orange;
}

The logical properties follow the block and inline directions of the element's writing mode.

Horizontal Writing Mode

Logical Property Physical Edge in horizontal-tb
border-block-start-color Top
border-block-end-color Bottom
border-inline-start-color Left in LTR, right in RTL
border-inline-end-color Right in LTR, left in RTL

Logical Border Color Shorthands

.logical-border {
  border-style: solid;
  border-width: 4px;
  border-block-color: red blue;
  border-inline-color: green orange;
}

The first border-block-color value applies to block-start and the second to block-end. The border-inline-color values apply to inline-start and inline-end.

Use physical border colors when the sides must remain fixed. Use logical border color properties when the colors should follow the document's writing direction.

Border Styles and Widths

The border-color property does not control border thickness or line style. Those properties must be specified separately or through a border shorthand.

Color Without a Visible Style

.panel {
  border-color: red;
  border-width: 5px;
}

The borders remain invisible if their styles retain the initial value of none.

Color With a Visible Style

.panel {
  border-color: red;
  border-width: 5px;
  border-style: solid;
}

The borders become visible because all three components are specified.

Different Border Styles

.panel {
  border-width: 5px;
  border-style: solid dashed dotted double;
  border-color: red blue green orange;
}

Each side has its own style and color while using the same specified width.

Different Border Widths

.panel {
  border-style: solid;
  border-width: 2px 4px 6px 8px;
  border-color: red blue green orange;
}

The top border is 2 pixels and red, the right is 4 pixels and blue, the bottom is 6 pixels and green, and the left is 8 pixels and orange.

Hidden Border Style

.panel {
  border: 5px solid red;
  border-bottom-style: hidden;
}

The bottom border is not painted because its style is hidden, even though its specified color remains red.

A border's final appearance depends on the combination of its color, width, and style.

Transitions and Animation

Border colors can transition smoothly between compatible color values.

Hover Color Transition

.animated-panel {
  border: 3px solid #777;
  transition: border-color 250ms ease;
}
.animated-panel:hover {
  border-color: #1769aa;
}
@media (prefers-reduced-motion: reduce) {
  .animated-panel {
    transition: none;
  }
}

All four border colors gradually change from gray to blue when the pointer moves over the element.

Individual Border Color Transition

.nav-link {
  border-bottom: 3px solid transparent;
  transition: border-bottom-color 200ms ease;
}
.nav-link:hover {
  border-bottom-color: #1769aa;
}
@media (prefers-reduced-motion: reduce) {
  .nav-link {
    transition: none;
  }
}

Only the bottom border color changes during the transition.

Focus Color Transition

.form-input {
  border: 2px solid #777;
  transition: border-color 200ms ease;
}
.form-input:focus-visible {
  border-color: #1769aa;
  outline: 2px solid #1769aa;
  outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
  .form-input {
    transition: none;
  }
}

The border changes color when the input receives visible keyboard focus. The outline provides an additional focus indicator.

Keyframe Animation

.animated-border {
  border: 4px solid #1769aa;
  animation: border-color-change 2s ease-in-out infinite alternate;
}
@keyframes border-color-change {
  from {
    border-color: #1769aa;
  }
  to {
    border-color: #e67e22;
  }
}
@media (prefers-reduced-motion: reduce) {
  .animated-border {
    animation: none;
  }
}

The border colors alternate between blue and orange.

Changing border colors does not change the border's used width, making color transitions useful for interactive effects without border-width-related layout shifts.

Practical Uses

The border-color property is useful for highlighting content, indicating interaction states, and creating visual separation.

Highlighted Content Panel

.highlight-panel {
  border: 2px solid #1769aa;
  padding: 20px;
  background-color: #e8f2fb;
}

A colored border distinguishes the panel from surrounding content.

Active Navigation Link

.nav-link {
  border-bottom: 3px solid transparent;
}
.nav-link[aria-current="page"] {
  border-bottom-color: #1769aa;
}

The active link receives a colored bottom border without changing its dimensions.

Form Validation

.form-input {
  border: 2px solid #777;
}
.form-input[aria-invalid="true"] {
  border-color: #b42318;
}

An invalid input receives a red border. Pair this visual indicator with an accessible error message rather than relying on color alone.

Callout Border

.info-callout {
  border: 1px solid #b8c6d1;
  border-left-width: 5px;
  border-left-color: #1769aa;
  padding: 16px;
}

A stronger left border adds emphasis while the other sides remain subtle.

Two-Tone Border

.two-tone-panel {
  border: 4px solid;
  border-color: #1769aa #d0d7de;
}

The top and bottom borders are blue, while the right and left borders are gray.

Theme Variables

:root {
  --border-primary: #1769aa;
  --border-muted: #d0d7de;
}
.themed-panel {
  border: 3px solid;
  border-color: var(--border-primary) var(--border-muted);
}

Custom properties make it easier to maintain consistent border colors across multiple components.

border-color Example

The following example demonstrates how one, two, three, and four color values are assigned to an element's borders.

<div class="border-color-demo">
  <div class="demo-box one">One Color</div>
  <div class="demo-box two">Two Colors</div>
  <div class="demo-box three">Three Colors</div>
  <div class="demo-box four">Four Colors</div>
</div>
.border-color-demo {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 20px;
}
.border-color-demo .demo-box {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 110px;
  padding: 16px;
  border-width: 8px;
  border-style: solid;
  background-color: #e8f2fb;
  color: #173b5e;
  font-weight: bold;
  text-align: center;
}
.border-color-demo .one {
  border-color: #1769aa;
}
.border-color-demo .two {
  border-color: #1769aa #e67e22;
}
.border-color-demo .three {
  border-color: #1769aa #e67e22 #2e8540;
}
.border-color-demo .four {
  border-color: #1769aa #e67e22 #2e8540 #8e44ad;
}
Browser Result
One Color
Two Colors
Three Colors
Four Colors

The first example uses one color for all four sides.

The second uses blue for the top and bottom borders and orange for the right and left borders.

The third uses blue for the top, orange for the right and left, and green for the bottom.

The fourth assigns a different color to every side in clockwise order: blue, orange, green, and purple.

Important Considerations

Keep the following points in mind when using border-color:

  • Shorthand property: Sets the colors of the top, right, bottom, and left borders.
  • Initial values: Each border side initially uses currentColor.
  • Inheritance: The individual border color properties are not inherited.
  • One to four values: The shorthand accepts one, two, three, or four colors.
  • Value order: Four values apply clockwise, starting at the top.
  • Physical sides: The shorthand always assigns colors to physical border edges.
  • Visible border: A visible style and nonzero used width are required for a border to appear.
  • Default style: The initial border style is none.
  • Default width: The initial specified border width is medium.
  • Color formats: Named colors, hexadecimal colors, CSS color functions, and other valid color values are supported.
  • currentColor: Allows border colors to follow the element's computed text color.
  • Transparency: Transparent borders can retain their used widths and occupy space.
  • Individual sides: Use the four border color longhands to change one side independently.
  • Shorthand interactions: Later border or side-specific border shorthands may reset border colors.
  • Logical alternatives: Use logical border color properties when colors should follow writing direction.
  • Animation: Border colors can transition between compatible color values.
  • Layout stability: Changing only border colors does not change the border's used width.
  • Browser support: The property is widely supported, but individual modern color functions may have different compatibility requirements.
  • Accessibility: Do not use border color alone to communicate important states or information.

Use border-color when multiple border colors need to be assigned or updated without changing the borders' specified widths and styles.

Browser Support

The border-color property is widely supported across Chrome, Edge, Firefox, Safari, and other major browsers, including older browser versions.

The standard property does not require vendor prefixes. Traditional color formats are broadly supported, while newer CSS color functions may have separate browser compatibility requirements.

Standard Declaration

.panel {
  border: 4px solid;
  border-color: #1769aa;
}

Multiple Border Colors

.panel {
  border: 4px solid;
  border-color: red blue green orange;
}

Both declarations use standard CSS supported by modern browsers.

Visit Can I Use? and search for border-color to review browser compatibility.

Specifications

The border-color property is defined in the CSS Backgrounds and Borders Module Level 3 specification.

CSS Backgrounds and Borders Module Level 3

CSS color values and color functions are defined in the CSS Color specifications.

CSS Color Module Level 4

Logical border color properties are defined in the CSS Logical Properties and Values Module Level 1 specification.

CSS Logical Properties and Values Module Level 1