Skip to: content, navigation

by Tommy Olsson and Paul O’Brien

border-right (CSS property)

Browser support full matrix
IE5.5+ FF1+ Saf1.3+ Op9.2+
Buggy Full Full Full
Spec
Inherited Initial Version
No CSS1

Example

This style rule assigns a 2px red border to the right-hand side of paragraphs within the element with ID "example":

#example p {
  border-right: 2px solid red;
}

Try it yourself!View all demos

Description

The border-right shorthand property sets the border-right-width and/or border-right-style and/or border-right-color to the right side of an element simultaneously.

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

Value

Refer to the following individual properties for specific information on allowed and initial values: border-width, border-style, and border-color.

Negative length values are illegal.

As with most shorthand properties, you don’t need to specify all the properties listed, but any omitted properties will revert to their default values. In the case of border-style, if you omit a value no border will show at all, because the default value is none. A border will only be visible as long as the border-style property has been set to something other than none or hidden, or has been restated explicitly after the initial shorthand declaration. Otherwise, no border will show and the border-width will be reset to zero. Therefore, it’s good practice to specify a value for the border’s style when you’re using shorthand notation.

Compatibility

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

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.

When dotted borders are specified as the border-style, and the border’s width is only 1px, Internet Explorer for Windows versions up to and including 6 will display the borders as dashed instead of dotted. At a width of 2px and above, the dotted borders will display correctly. This glitch was fixed in Internet Explorer Version 7 for cases when all four sides are set to 1px. However, if one of the sides is set to 2px or more, the 1px dotted borders revert to dashed in IE7.

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

Internet Explorer for Windows versions up to and including 7:

  • don’t support the value hidden
  • don’t support the value inherit

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.

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