CSS border-right Property
The CSS border-right shorthand sets the width, style, and color of an element's right border. Learn its syntax, values, and examples.
The CSS border-right property sets the width, line style, and color of the right border of an element. It is a shorthand property that lets you set three separate properties in a single declaration:
- border-right-width — how thick the border is,
- border-right-style — the line style (
solid,dotted,dashed, etc.), - border-right-color — the color of the line.
Instead of writing three rules, you can write one:
/* shorthand */
border-right: 3px solid #1c87c9;
/* equivalent longhand */
border-right-width: 3px;
border-right-style: solid;
border-right-color: #1c87c9;The three values can be specified in any order, and one or two of them may be omitted. When a value is left out, its default is used:
- If the style is omitted, the border does not render at all —
border-right-styledefaults tonone, which is why you must always include a style to see a border. - If the width is omitted, it defaults to
medium. - If the color is omitted, the border takes the element's color value; when that is not set either, it falls back to the current text color (black by default).
When to use border-right
Use border-right when you want a line on only one side of a box — for example, a vertical divider between a sidebar and main content, a decorative accent on a card, or an underline-style separator rotated to a column. If you need the same border on all four sides, use the border shorthand instead; for the other single sides see border-left, border-top, and border-bottom.
| Default Value | medium none currentColor |
|---|---|
| Applies to | All elements. It also applies to ::first-letter. |
| Inherited | No |
| Animatable | Yes. The width and color are animatable. |
| Version | CSS1 |
| DOM Syntax | object.style.borderRight = "1px solid black"; |
Syntax
Syntax of CSS border-right Property
border-right: border-width border-style border-color | initial | inherit;Example of the border-right property:
Example of CSS border-right Property
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style>
div {
border-right: 5px solid #1c87c9;
padding: 10px;
}
</style>
</head>
<body>
<h2>Border-right example</h2>
<div> This is a simple example for the border-right property.</div>
</body>
</html>Result

The border-right property can be applied to different elements and can take various style values.
Example of the border-right property with multiple values:
Example of CSS border-right Property with solid, dotted and double values
<!DOCTYPE html>
<html>
<head>
<style>
h1,
p,
div {
padding: 10px;
}
h1 {
border-right: 7px solid #8ebf42;
}
p {
border-right: 5px dotted #1c87c9;
}
div {
border-right: thick double #666;
}
</style>
</head>
<body>
<h1>A heading with a solid green right border</h1>
<p>A heading with a dotted blue right border.</p>
<div>A div element with a thick double right border.</div>
</body>
</html>You can also create a box with the <div> element and set a background-color for your box, then add a right border to have a fancy box.
Example of using the border-right property to create a fancy box:
Example of CSS border-right Property with solid property
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style>
div {
width: 300px;
height: 80px;
text-align: center;
padding: 20px;
background: #ccc;
border-right: 5px solid #000;
}
</style>
</head>
<body>
<div>This box has a solid border on the right side.</div>
</body>
</html>Tips and gotchas
- Always include a style. Setting only
border-right: 2px #1c87c9;shows nothing because the style defaults tonone. Add a keyword likesolid. - Order is flexible.
border-right: solid 5px red;andborder-right: 5px solid red;are equivalent. - The shorthand resets omitted parts. Writing
border-right: 5px solid;resets the color back to the current text color, even if you had setborder-right-colorearlier. Use the longhand properties when you want to change just one part without touching the others. - Borders add to layout size unless
box-sizing: border-boxis set, because the defaultcontent-boxadds the border width to the element's overall width.
Values
The shorthand accepts the values of its three longhand properties, plus the CSS-wide keywords:
| Value | Description |
|---|---|
| border-right-width | Sets the right border width of an element. The default value is "medium". Required value. |
| border-right-style | Sets the line style of the right border of an element. The default value is "none". Required value. |
| border-right-color | Sets the color of the right border of an element. The default value is the current color of the text. |
| initial | Sets the property to its default value. |
| inherit | Inherits the property from its parent element. |
Practice
Related properties
- border — set all four borders at once.
- border-left, border-top, border-bottom — the other single-side shorthands.
- border-right-width, border-right-style, border-right-color — the individual right-border longhands.
- border-radius — round the corners where borders meet.