Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Borders, Outlines and Shadows

The border-color property

Reference for the CSS border-color property: set border colors with one to four values, use currentcolor and transparent, and mix with other properties.

The border-color property sets the color of an element's borders. It is a shorthand for the four side colors (border-top-color and the rest) and takes one to four values.

If you do not set it, borders use the element's text color (currentcolor). That makes it easy to build components whose borders follow the text, for example a button that changes both on hover by changing color alone.

CSS
.input {
  border: 2px solid;
  border-color: #94a3b8 #94a3b8 #475569;
}

Try it

Colors per side and currentcolor

Syntax

CSS
border-color: <color>{1,4}
  • Initial value: currentcolor
  • Applies to: all elements
  • Inherited: no
  • Animatable: yes, as a color
  • Computed value: the computed color for each side

Values

Value Description
<color> Any color value: keyword, hex, rgb(), oklch(), and so on. Alpha is allowed.
currentcolor The element's color. This is the default.
transparent A fully transparent border. It still takes up space, and the background shows through it (see below).
One value All four sides.
Two values Top and bottom, then left and right.
Three values Top, then left and right, then bottom.
Four values Top, right, bottom, left (clockwise).

Usage notes

  • Needs a style to show. The color only matters when border-style is not none or hidden.
  • Transparent borders still paint the background under them. By default the background extends under the border (background-clip: border-box), so a transparent border shows the element's background color or image. Set background-clip to padding-box if you want the gap to be see-through.
  • A reliable spacing trick. Reserve space for a border that appears on hover by giving the element border: 2px solid transparent and changing only the color. Layout never jumps.
  • Triangles and corners. Different colors on adjacent sides meet at a diagonal. This was once used to draw CSS triangles with a zero-size box; today clip-path or SVG is clearer.
  • Hover transitions work well because the color is animatable. Add transition: border-color 0.2s.
  • Contrast. Borders that identify controls should have enough contrast with the background, commonly at least 3:1.
  • Forced colors mode replaces border colors with system colors, which is usually helpful.

Browser support

Supported in every browser.