Skip to: content, navigation

by Tommy Olsson and Paul O’Brien

border-color (CSS property)

Browser support full matrix
IE5.5+ FF1+ Saf1.3+ Op9.2+
Buggy Full Full Full
Spec
Inherited Initial Version
No CSS1, 2.1
border-color: { { color | transparent }  1 to 4 values | inherit } ;

Example

This style rule assigns a red border to the top, a green border to the bottom, and blue borders to the left- and right-hand sides of paragraphs within the element with ID "example":

#example p {
  border-color: red blue green;
  border-style: solid;
}

Try it yourself!View all demos

Description

The shorthand property border-color sets the border color on all four sides of an element using from one to four of the values specified. Each border can have its own value—refer to the mnemonic (TRouBLe) in Shorthand Properties for an easy way to remember the shorthand order.

Borders are placed on top of the element’s background.

If no color value is specified for border-color, the border will use the color value of the element.

Value

This property takes any valid CSS color value or color keyword. The initial value for this property is the value of the color property for the element.

The value transparent allows the border to be transparent, but it will still occupy the space set by the border-width property and allow the background of the element to show through the transparent border.

Note that a border will only be visible as long as a border-style has been set. The default for border-style is none, which means that no border will display, and the border-width will be reset to zero.

Compatibility

IE5.5Buggy
6.0Buggy
7.0Buggy
Firefox1.0Full
1.5Full
2.0Full
Safari1.3Full
2.0Full
3.0Full
Opera9.2Full
9.5Full

Internet Explorer for Windows versions up to and including 6 do not support transparent borders.

User agents are supposed to place borders on the element’s background, but in Internet Explorer for Windows versions up to and including 7, the background only reaches the inside edge of the border when the element has a layout. This means that for dotted or dashed borders, the background won’t be visible through the spaces within the border. When the element doesn’t have a layout, the background will extend under the borders.

The appearance of the borders may vary between user agents (within limits). The algorithms that define the relationship between the colors used to achieve an effect (for example, groove, ridge, inset, and outset) are not explicitly defined in the CSS specifications, so the colors may vary between user agents. In CSS2.1, the three-dimensional border styles (groove, ridge, inset, and outset) depend on the corresponding border-color, rather than on color.

Internet Explorer for Windows versions up to and including 7 don’t support the value inherit.

User-contributed notes

There are no comments yet.

Add a note

To post a note on this topic, please log in with your SitePoint username and password. If you don't have an account yet, you can create a new account for free.

Related Products

The Principles of Beautiful Web Design

Best Seller!

You don’t need to go to Art School to design great looking web sites!

Book Cover: The Principles of Beautiful Web Design

Download the FREE sample chapters