Border-color, CSS property

This page is also about physical property(ies):
- border-bottom-color
Sets the border line color for the bottom of the element.
- border-left-color
Sets the color of the left border line of the element.
- border-right-color
Sets the color of the border line on the right side of the element.
- border-top-color
Sets the color of the border line above the element.
And the logical properties:
- border-block-color
Sets the color of the border strokes, for the start and end sides of the frame in the direction of blocks.
- border-block-end-color
Sets the color of the border strokes for the end side of the block.
- border-block-start-color
Sets the color of the border strokes for the start side of the block.
- border-inline-color
Sets the color of the border strokes, for the beginning and end sides of the lines.
- border-inline-end-color
Sets the color of the border strokes, for the end side of the lines.
- border-inline-start-color
Sets the color of the border strokes, for the beginning side of the lines.
border-color

Summary of characteristics of the border-color property

Quick description
Sets the border color for all four sides of the element.
Status
Standard
Applies to
All elements except annotations and the bases.
Predefined values
currentcolor | transparent
Percentages
Not applicable.
Initial value
currentcolor
Inherited by default
No.
Computed value: during an animation, the border-color property gradually changes from one value to another.
Per grammar: serialization in the order of syntax.
W3C Module
CSS Backgrounds and Borders Module
 🡇  
 🡅  
Document status: CR (Candidate Recommendation)

Document status: WD (Working Draft)

Document status: REC (Recommendation)

Document status: DEPR (Old specification, declared obsolete or superseded)

Syntax diagram of border-color.

border-color - Syntax DiagramSyntax diagram of the border-color CSS property, which sets the color of the border. curentcolor curentcolor transparent transparent color-name color-name #xxxxxx #xxxxxx color color {1,4} {1,4}border-color:;border-color:;
Syntax diagram of the border-color property.
The links in the diagram provide more details about the values.
Download the diagram in SVG.

In the diagram, the bold terms are the predefined words of CSS, the other terms are described below:

Description of the border-color property.

border-color sets the color of an element's borders. The border-color property accepts one to four values:

  • If only one value is specified, it applies to all four sides.
  • If two values are specified, the first one sets the color of the top and bottom borders; the second one sets the color of the left and right borders.
  • If three values are given, the first sets the color of the top border, the second sets the color of the right and left borders, and the last sets the color of the bottom border.
  • Finally, when the four values are given, they correspond respectively to the color of the top, right, bottom, and left borders.

There are also specific properties for each of the edges:

border-top-color
Sets the color of the border line above the element.
border-right-color
Sets the color of the border line on the right side of the element.
border-bottom-color
Sets the border line color for the bottom of the element.
border-left-color
Sets the color of the left border line of the element.

To make the border color visible, also remember to set the border-style property.

Language support.

The so-called 'logical' properties take into account the meaning and writing direction depending on the language:

border-block-start-color
Sets the color of the border strokes for the start side of the block.
border-block-end-color
Sets the color of the border strokes for the end side of the block.
border-inline-start-color
Sets the color of the border strokes, for the beginning side of the lines.
border-inline-end-color
Sets the color of the border strokes, for the end side of the lines.

Finally, two summarised properties that allow you to set the color of the two opposite sides of the element.

border-block-color
Sets the color of the border strokes, for the start and end sides of the frame in the direction of blocks.
border-inline-color
Sets the color of the border strokes, for the beginning and end sides of the lines.

border-top-color
border-left-color
The direction and writing mode of this text adapt to the chosen language.
border-right-color
border-bottom-color

Values for border-color.

Note: the color can be altered by line styles with 3D effect (inset, groove...). Indeed, to create a relief effect, these styles darken the color on some lines or parts of a line, and lighten the color in other areas.

  • border-color: currentcolor;

    Default value. The border is the same color as the text.

  • border-color: transparent;

    The border is invisible, but its thickness is taken into account.

  • border-color: #451498;

    The border is in the indicated color. All standard notations to define a color are accepted (name, RGB code, etc.). See the different notations for Colors.

  • border-color: blue red;

    Two color pieces of information separated by a space. The first applies to the top and bottom lines. The second to the right and left lines.

  • border-color: blue red black;

    Three pieces of color information separated by a space. The first one applies to the top line, the second to the right and left lines, and the last to the bottom line.

  • border-color: blue red yellow green;

    Finally, four color pieces of information separated by a space apply to each of the lines, going clockwise and starting with the top line.

  • border-color: initial; (currentcolor) border-color: inherit; border-color: revert; border-color: revert-layer; border-color: revert-rule; border-color: unset;

    Common values ​​are presented on these pages: initial, inherit, revert, revert-layer, revert-rule, unset.

Examples with the border-color property.

The borders follow the curves when border-radius is used.
The border is drawn on top of the background but underneath the content.
This matters in case of overflow.
The border line goes behind this line of text)

 

Note: the color is changed by the inset border style: the top and left borders are darker than the bottom and right ones.

Animation of the border-color property.

As usual, we try to suggest original ideas to liven up the properties. Here's a little rotating visual effect created with the animation of the border-color property.

Access the border-color property via a program

Change the border color in Javascript.

Here's how to change the value of border-color with Javascript. The property name can be written in kebab-case (a dash to separate words), or in camel-case (a capital letter to separate words).

Javascript
let el = document.getElementById('id'); el.style['border-color'] = 'blue'; // or let el = document.getElementById('id'); el.style.borderColor = 'blue';

Read the border color in JavaScript.

This code example works when the property has been set in the HTML code, using the style attribute, and not in CSS via a selector. The color or colors are returned exactly as they were defined (name, hexadecimal code, hsl() function, etc...).

Javascript
let el = document.getElementById('id'); let value = el.style['border-color']; // or let el = document.getElementById('id'); let value = el.style.borderColor;

Read the computed value of border-color in Javascript.

The computed value is the color applied to the property border-color for this element, a value that may be inherited, or if not, the value currentcolor, which is the initial value of this property.

In the case of border-color, the color or colors are returned in the form rgb(r,g,b), or rgba(r,g,b,a) if the color isn't fully opaque. However, if the color was set using the color() function (another color space), the color() function is kept.

Javascript
let el = document.getElementById('id'); let value = window.getComputedStyle(el).getPropertyValue('border-color');

Change the border color with JQuery.

Two possible syntaxes, just like in Javascript.

JQuery

$('#id').css('border-color', 'blue');
// or
$('#id').css('borderColor', 'blue');

Read the computed value of the border-color property with JQuery.

You can read the property with the following code. Like in JavaScript, the color is returned in the form rgb(r,g,b), rgba(r,g,b,a) or color().

JQuery
let value = $('#id').css('border-color');

Other code examples.

Other examples of Javascript and JQuery code are given on the page Javascript and CSS.

Test it yourself.

The buttons below apply the entered value to the border-color property and then show either the value as it was applied or the computed value. This second option lets you see how the value of border-color is stored (serialized). In particular, you'll notice that the color is always returned in rgb() or rgba() format. However, the new color() function can also be stored as-is because it allows you to select a color space.

Simulator.

border-color :

Browsers compatibility with border-color.

No compatibility issues are reported. Support for border-color is fine on all current browsers.

Column 1
Support for the property border-color which defines the color of the borders.
Column 2
Support for the properties border-top-color, border-right-color, border-bottom-color, and border-left-color (physical properties).
Column 3
Support for properties border-block-color, border-inline-color, etc. (logical properties).
1
border-color
property
2
Physical
properties
3
Logical
properties
Estimated overall support.
96%
96%
94%

Browsers on computers :

Mobile browsers :

Outdated or marginal browsers :

Internet Explorer

KaiOS Browser

Opéra Mobile

Chrome

Edge

Opéra

Safari

Safari sur IOS

Androïd Brower

Chrome pour Androïd

Firefox pour Androïd

Samsung Internet

Firefox

Baidu Browser

QQ Browser

UC Browser pour Androïd

Opéra mini

Historic of the border-color property.

The shorthand property border-color and the corresponding detailed properties haven't changed over the CSS language versions, but the color specification has changed a lot: see our page on Colors.

  • Cascading Style Sheets specification - Version 1

    This first level of the CSS specification describes the mechanism of cascading style sheets. Authors and readers can add styles to documents. Mainly intended for formatting HTML documents, CSS allows defining colors, fonts, text formatting, spacing (margins), etc. The CSS language is easy to understand, readable, and easy to write; it uses common terms from desktop publishing.

    Regarding border-color Initial definition of the shorthand property border-color and the corresponding longhand properties.
    WD
    November 17, 1995
    Working Draft.
    PR
    November 12, 1996
    Proposed for recommendation.
    REC
    December 17, 1996
    Recommendation .
    DEPR
    September 13, 2018
    Old specification, declared obsolete.
  • Cascading Style Sheets Level 2 - Revision 1 Specification

    This level 2 of the specification describes the mechanism of cascading styles in CSS. This language is used to format HTML or XML documents. It supports media-specific style sheets so that authors can adapt the presentation of their documents for visual browsers, auditory devices, printers, braille devices, portable devices, etc.

    Regarding border-color No change to the properties defining the border color, except that they accept the inherit value.
    WD
    November 04, 1997
    Working Draft.
    PR
    March 24, 1998
    Proposed for recommendation.
    REC
    May 11, 1998
    Recommendation .
  • CSS Logical Properties and Values Level 1

    This specification module defines properties that indirectly define certain other properties depending on the writing mode: left to right, right to left, or top to bottom. They are useful in simple and generic style sheets, such as browser style sheets, but can also save a few lines of styles for documents containing both left-to-right and right-to-left text.

    Regarding border-color Introduction des propriétés logiques (prenant en charge le mode d'écriture en fonction de la langue).
    WD
    May 18, 2017
    Working Draft.
    CR
    PR
    REC
  • CSS Backgrounds and Borders Module Level 3

    Level 3 of the specification also explains how to position the background relative to the background area, and how to crop it.
    Regarding borders, the concept of image borders is introduced, as well as the ideas of rounded corners and box shadows.

    Regarding border-color No changes directly concerning the properties defining the color of the borders, but numerous developments concerning the colors themselves (see our page on colors).
    WD
    August 02, 2002
    Working Draft.
    CR
    December 17, 2009
    Candidate Recommendation.
    PR
    REC

See also, about borders.

The W3C specification "CSS Backgrounds and Borders Module" covers everything related to borders and backgrounds, which is quite a lot. To make your search easier, we’ve listed the main related terms below.

Properties:

background
Summary of background properties.
background-attachment
Background image scrolling mode.
background-clip
Defines the extent of the background, especially in relation to the border and padding.
background-color
Sets the background color.
background-image
Defines the background image or gradient (multiple images or gradients can coexist).
background-origin
Defines a reference to position the background image.
background-position
Defines how the background image is positioned.
background-position-block
Sets the background positioning in the block direction.
background-position-inline
Sets the background positioning along the lines.
background-position-x
Sets how the background image is positioned horizontally.
background-position-y
Defines how the background image is positioned in the vertical direction.
background-repeat
Defines how the background image is repeated.
background-size
Sizing the background image.
border
A shorthand property that defines the set of border parameters: width, style and color.
border-bottom
Sets the parameters of the bottom border of the element (thickness, line style, color).
Border-bottom-color
Sets the border line color for the bottom of the element.
border-bottom-left-radius
Sets the radius of the rounded corner at the bottom left.
border-bottom-right-radius
Sets the radius of the rounded corner in the lower right.
border-bottom-style
Sets the line style for the border below the element.
border-bottom-width
Sets the thickness of the border line located below the element.
Border-color
Sets the border color for all four sides of the element.
border-end-end-radius
Sets the radius of the corner rounding at the end of line and end of block.
border-end-start-radius
Sets the radius of the corner rounding at the end of line and beginning of the block.
border-image
Langue française
Shorthand of border properties made with images.
border-image-outset
Langue française
Sets the overflow of the border image.
border-image-repeat
Langue française
Defines how the border image is repeated or expanded to cover the desired area.
border-image-slice
Langue française
Defines how the border image is clipped.
border-image-source
Sets the path and file name for the image used to build the border.
border-image-width
Langue française
Sets the thickness of the border when the border is made with an image.
border-left
Sets the three parameters of the left border of the element (thickness, line style, color).
Border-left-color
Sets the color of the left border line of the element.
border-left-style
Sets the border style for the left side of the element.
border-left-width
Sets the thickness of the border on the left side of the element.
border-radius
Radius of rounded corners.
border-right
Sets the three parameters of the right border of the element (thickness, line style, color).
Border-right-color
Sets the color of the border line on the right side of the element.
border-right-style
Sets the line style for the right border of the element.
border-right-width
Sets the thickness of the border on the right side of the element.
border-start-end-radius
Sets the radius of the corner rounding at the beginning of the line and the end of the block.
border-start-start-radius
Sets the radius of the corner rounding at the beginning of the line and the beginning of the block.
border-style
Sets the line type for some or all four borders around the element (solid, double, dotted...).
border-top
Sets the parameters of the top border of the element (thickness, line style, color).
Border-top-color
Sets the color of the border line above the element.
border-top-left-radius
Sets the radius of the rounded corner at the top left.
border-top-right-radius
Sets the radius of the rounded corner in the upper-right.
border-top-style
Sets the line style for the left border of the element.
border-top-width
Sets the thickness of the border line above the element.
border-width
Sets the thickness of the border line around the element.
box-shadow
Applies a shading effect to the frames by indicating all the parameters: color, shadow shift, blur, etc.