CSS border-right Property
The border-right property is a shorthand that sets the width, style, and color of an element's right border.
It combines border-right-width, border-right-style, and border-right-color into a single declaration. The values can appear in any order, and each component is optional.
The property controls the physical right border regardless of the element's writing mode or text direction.
border-right Syntax
The property accepts a border width, style, and color in any order. At least one component must be provided.
selector {
border-right: 5px solid #1769aa;
}
The general syntax is:
selector {
border-right: <line-width> || <line-style> || <color>;
}
Width, Style, and Color
.panel {
border-right: 5px solid #1769aa;
}
Style and Color
.panel {
border-right: solid #1769aa;
}
The width defaults to medium.
Width and Style
.panel {
border-right: 5px solid;
}
The color defaults to currentcolor.
Style Only
.panel {
border-right: solid;
}
The border uses medium width and currentcolor.
Width Only
.panel {
border-right: 5px;
}
The border is not visible because the style defaults to none.
Color Only
.panel {
border-right: #1769aa;
}
The border is not visible because the style defaults to none.
Different Value Order
.panel {
border-right: solid #1769aa 5px;
}
This produces the same result as 5px solid #1769aa.
No Right Border
.panel {
border-right: none;
}
Zero Width
.panel {
border-right: 0;
}
CSS-Wide Keywords
.inherited {
border-right: inherit;
}
.reset {
border-right: initial;
}
.unset {
border-right: unset;
}
.reverted {
border-right: revert;
}
.layer-reverted {
border-right: revert-layer;
}
CSS-wide keywords must be used by themselves rather than combined with width, style, or color values.
Property Values
The border-right shorthand accepts values from three categories: width, style, and color.
| Component | Accepted Values | Initial Value |
|---|---|---|
| Width | thin, medium, thick, or a non-negative CSS length |
medium |
| Style | none, hidden, dotted, dashed, solid, double, groove, ridge, inset, outset |
none |
| Color | Any valid CSS color, including currentcolor and transparent |
currentcolor |
CSS-Wide Keywords
| Keyword | Description |
|---|---|
inherit |
Inherits all three right border components from the parent. |
initial |
Resets all three components to their initial values. |
unset |
Resets all three components to their initial values because they are not inherited. |
revert |
Reverts the shorthand's components according to cascade origin rules. |
revert-layer |
Reverts the shorthand's components according to cascade layer rules. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | medium none currentcolor |
| Inherited | No |
| Applies to | Elements that support border properties |
| Computed value | Determined individually by the width, style, and color longhands |
| Animation type | Determined by the individual longhand properties |
| Property type | Shorthand |
| Physical edge | Right |
Although the initial specified width is medium, the computed width becomes zero when the border style is none or hidden.
How It Works
The browser expands the shorthand into three longhand properties and uses their combined values to draw the right border.
Step 1: Set a Right Border
.panel {
border-right: 6px solid #1769aa;
}
This declaration creates a 6-pixel solid blue border on the right edge.
Step 2: Understand the Longhands
.panel {
border-right-width: 6px;
border-right-style: solid;
border-right-color: #1769aa;
}
These declarations produce the same result as the shorthand.
Step 3: Change the Width
.panel {
border-right: 6px solid #1769aa;
border-right-width: 10px;
}
The right border becomes 10 pixels thick without changing its style or color.
Step 4: Change the Style
.panel {
border-right: 6px solid #1769aa;
border-right-style: dashed;
}
The border becomes dashed while retaining its width and color.
Step 5: Change the Color
.panel {
border-right: 6px solid #1769aa;
border-right-color: #27ae60;
}
The border becomes green while retaining its width and style.
Use the shorthand to establish the complete border and longhand properties to change individual components.
Border Width Values
The width component controls the thickness of the right border.
Thin Border
.panel {
border-right: thin solid #1769aa;
}
Medium Border
.panel {
border-right: medium solid #1769aa;
}
Thick Border
.panel {
border-right: thick solid #1769aa;
}
The browser determines the exact thickness of the three keywords.
Pixel Width
.panel {
border-right: 5px solid #1769aa;
}
Relative Width
.panel {
border-right: 0.4rem solid #1769aa;
}
Calculated Width
.panel {
border-right: calc(2px + 0.2rem) solid #1769aa;
}
Clamped Width
.panel {
border-right: clamp(2px, 0.5vw, 8px) solid #1769aa;
}
Zero Width
.panel {
border-right: 0 solid #1769aa;
}
The border occupies no width and is not visible.
Invalid Negative Width
.panel {
border-right: -5px solid #1769aa;
}
This declaration is invalid because negative border widths are not accepted.
Invalid Percentage Width
.panel {
border-right: 10% solid #1769aa;
}
Percentages are not valid border width values.
Use explicit lengths when a precise border thickness is required.
Border Style Values
The style component determines how the right border is drawn.
| Style | Appearance |
|---|---|
none |
No border is drawn. |
hidden |
No border is drawn; has special behavior in collapsed table border conflicts. |
dotted |
A series of dots. |
dashed |
A series of short line segments. |
solid |
A continuous line. |
double |
Two parallel lines separated by a gap. |
groove |
A border with a carved appearance. |
ridge |
A border with a raised appearance. |
inset |
A border with an inset appearance. |
outset |
A border with an outset appearance. |
Solid Border
.panel {
border-right: 5px solid #1769aa;
}
Dashed Border
.panel {
border-right: 5px dashed #1769aa;
}
Dotted Border
.panel {
border-right: 5px dotted #1769aa;
}
Double Border
.panel {
border-right: 8px double #1769aa;
}
A sufficiently wide border helps make both lines of the double style visible.
Groove Border
.panel {
border-right: 8px groove #1769aa;
}
Ridge Border
.panel {
border-right: 8px ridge #1769aa;
}
Inset Border
.panel {
border-right: 8px inset #1769aa;
}
Outset Border
.panel {
border-right: 8px outset #1769aa;
}
The exact rendering of dotted, dashed, and three-dimensional border styles can vary between browsers.
Border Color Values
The color component accepts any valid CSS color value.
Hexadecimal Color
.panel {
border-right: 5px solid #1769aa;
}
RGB Color
.panel {
border-right: 5px solid rgb(23 105 170);
}
HSL Color
.panel {
border-right: 5px solid hsl(207 76% 38%);
}
Named Color
.panel {
border-right: 5px solid steelblue;
}
currentcolor
.panel {
color: #1769aa;
border-right: 5px solid currentcolor;
}
The border uses the element's computed text color.
Transparent Color
.panel {
border-right: 5px solid transparent;
}
The border occupies space but is not visibly painted.
Color With Transparency
.panel {
border-right: 5px solid rgb(23 105 170 / 50%);
}
Custom Color
:root {
--accent-color: #1769aa;
}
.panel {
border-right: 5px solid var(--accent-color);
}
When the color is omitted from the shorthand, it resets to currentcolor.
Optional Values and Resets
Each component of the border-right shorthand is optional, but omitted components are reset to their initial values.
Omitting the Width
.panel {
border-right: solid #1769aa;
}
The width becomes medium.
Omitting the Color
.panel {
color: #1769aa;
border-right: 5px solid;
}
The border color becomes currentcolor.
Omitting the Style
.panel {
border-right: 5px #1769aa;
}
The style becomes none, so no border is visible.
Resetting an Earlier Width
.panel {
border-right-width: 12px;
border-right: solid #1769aa;
}
The later shorthand resets the specified width to medium.
Resetting an Earlier Color
.panel {
border-right-color: #c0392b;
border-right: 5px solid;
}
The later shorthand resets the color to currentcolor.
Resetting an Earlier Style
.panel {
border-right-style: dashed;
border-right: 5px #1769aa;
}
The later shorthand resets the style to none.
Reset All Components
.panel {
border-right: initial;
}
This resets the right border to its initial width, style, and color.
When changing only one border component, use its corresponding longhand property to preserve the others.
Individual Border Properties
The shorthand combines three right border longhand properties.
| Property | Purpose |
|---|---|
border-right-width |
Controls the thickness of the right border. |
border-right-style |
Controls the line style of the right border. |
border-right-color |
Controls the color of the right border. |
Using Longhands
.panel {
border-right-width: 6px;
border-right-style: solid;
border-right-color: #1769aa;
}
Equivalent Shorthand
.panel {
border-right: 6px solid #1769aa;
}
Change Width Only
.panel {
border-right: 6px solid #1769aa;
border-right-width: 10px;
}
Change Style Only
.panel {
border-right: 6px solid #1769aa;
border-right-style: dotted;
}
Change Color Only
.panel {
border-right: 6px solid #1769aa;
border-right-color: #27ae60;
}
Longhand declarations are useful when a component's border style is already established and only one value needs to change.
Border Visibility
A right border may occupy space without appearing, depending on its width, style, and color.
Visible Border
.panel {
border-right: 6px solid #1769aa;
}
Style none
.panel {
border-right: 6px none #1769aa;
}
The computed border width becomes zero.
Style hidden
.panel {
border-right: 6px hidden #1769aa;
}
The computed border width also becomes zero. The hidden style has special behavior in collapsed table border conflicts.
Transparent Border
.panel {
border-right: 6px solid transparent;
}
The border retains its width and occupies space, but its color is transparent.
Zero Width
.panel {
border-right: 0 solid #1769aa;
}
The border has no visible thickness.
Width Without Style
.panel {
border-right: 6px;
}
The style resets to none, preventing the border from appearing.
When a right border does not appear, check the style first, followed by its width, color, and any border-image settings.
Physical vs. Logical Borders
The border-right property always targets the physical right border. Logical border properties adapt to writing mode and direction.
Physical Right Border
.panel {
border-right: 6px solid #1769aa;
}
The border remains on the right edge in both left-to-right and right-to-left layouts.
Logical Inline-End Border
.panel {
border-inline-end: 6px solid #1769aa;
}
In horizontal left-to-right writing, the inline-end border is on the right. In horizontal right-to-left writing, it is on the left.
Logical Inline-Start Border
.panel {
border-inline-start: 6px solid #1769aa;
}
In horizontal left-to-right writing, the inline-start border is on the left. In horizontal right-to-left writing, it is on the right.
Writing Mode Comparison
| Writing Mode | Direction | Logical Border Matching Right |
|---|---|---|
horizontal-tb |
ltr |
border-inline-end |
horizontal-tb |
rtl |
border-inline-start |
vertical-rl |
ltr or rtl |
border-block-start |
vertical-lr |
ltr or rtl |
border-block-end |
Vertical Writing Example
.panel {
writing-mode: vertical-rl;
border-right: 6px solid #1769aa;
}
The border remains on the physical right edge.
Use border-right when the right edge must remain fixed. Use logical border properties when the border should follow the writing direction.
Box Sizing and Layout
A visible right border contributes to the element's dimensions and can affect the available content space.
Default content-box
.panel {
box-sizing: content-box;
width: 300px;
padding: 20px;
border-right: 10px solid #1769aa;
border-left: 2px solid #cccccc;
}
The declared width applies to the content box. Padding and borders are added outside it.
Ignoring margins, the total outer width is 352 pixels: 300 pixels of content, 40 pixels of horizontal padding, and 12 pixels of horizontal borders.
Using border-box
.panel {
box-sizing: border-box;
width: 300px;
padding: 20px;
border-right: 10px solid #1769aa;
border-left: 2px solid #cccccc;
}
The declared width includes padding and borders, keeping the outer width at 300 pixels.
Changing Width on Hover
.panel {
border-right: 4px solid #1769aa;
}
.panel:hover {
border-right-width: 12px;
}
Increasing border width can change the element's outer dimensions or reduce its content area.
Avoiding Layout Changes
.panel {
border-right: 8px solid transparent;
}
.panel:hover {
border-right-color: #1769aa;
}
The border retains the same width in both states, preventing a change in its contribution to layout.
Outline Alternative
.panel {
border-right: 4px solid #1769aa;
}
.panel:focus-visible {
outline: 3px solid #1769aa;
outline-offset: 3px;
}
An outline provides an additional focus indicator without changing the CSS box dimensions.
Cascade and Overrides
The CSS cascade determines which right border declarations apply when multiple rules target the same element.
Later Declaration
.panel {
border-right: 4px solid #1769aa;
border-right: 8px dashed #27ae60;
}
The later declaration replaces the earlier right border when cascade priority is otherwise equal.
Higher Specificity
.panel {
border-right: 4px solid #1769aa;
}
.panel.featured {
border-right: 10px solid #27ae60;
}
The featured panel uses the more specific declaration.
Longhand Override
.panel {
border-right: 4px solid #1769aa;
border-right-width: 10px;
}
The width becomes 10 pixels while the style and color remain unchanged.
Later Shorthand Reset
.panel {
border-right-color: #c0392b;
border-right: 5px solid;
}
The later shorthand resets the color to currentcolor.
border Shorthand Override
.panel {
border-right: 8px solid #1769aa;
border: 2px solid #cccccc;
}
The later border shorthand sets all four borders, including the right border.
Physical and Logical Conflict
.panel {
border-right: 4px solid #1769aa;
border-inline-end: 8px dashed #27ae60;
}
In horizontal left-to-right writing, both declarations target the right edge. The later logical declaration wins when cascade priority is otherwise equal.
CSS Layers
@layer base, components;
@layer base {
.panel {
border-right: 2px solid #cccccc;
}
}
@layer components {
.panel {
border-right: 6px solid #1769aa;
}
}
For normal declarations, the later layer takes precedence.
When a right border appears incorrect, check shorthand resets, specificity, cascade layers, and conflicting logical border declarations.
CSS Custom Properties
CSS custom properties allow right border values to be reused across components.
Shared Border
:root {
--accent-border: 5px solid #1769aa;
}
.panel {
border-right: var(--accent-border);
}
Separate Components
:root {
--border-width: 5px;
--border-style: solid;
--border-color: #1769aa;
}
.panel {
border-right: var(--border-width) var(--border-style) var(--border-color);
}
Fallback Border
.panel {
border-right: var(--panel-border, 5px solid #1769aa);
}
The fallback is used when the custom property is unavailable or has the guaranteed-invalid value.
Component Variants
.notice {
--notice-border-color: #1769aa;
border-right: 5px solid var(--notice-border-color);
}
.notice.success {
--notice-border-color: #27ae60;
}
.notice.error {
--notice-border-color: #c0392b;
}
Theme-Based Border
:root {
--panel-border-color: #1769aa;
}
[data-theme="dark"] {
--panel-border-color: #79b8e8;
}
.panel {
border-right: 5px solid var(--panel-border-color);
}
Custom properties make it easier to maintain consistent border widths, styles, and colors throughout a design.
Interactive States
The right border can change in response to hover, focus, selection, and other interface states.
Hover State
.panel {
border-right: 4px solid #1769aa;
}
.panel:hover {
border-right-color: #27ae60;
}
Focus State
.form-field {
border-right: 3px solid #cccccc;
}
.form-field:focus {
border-right-color: #1769aa;
}
Keyboard Focus
.form-field {
border-right: 3px solid #cccccc;
}
.form-field:focus-visible {
border-right-color: #1769aa;
outline: 2px solid #1769aa;
outline-offset: 2px;
}
Selected Card
.card {
border-right: 5px solid transparent;
}
.card.is-selected {
border-right-color: #1769aa;
}
Current Navigation Item
.nav-link {
border-right: 4px solid transparent;
}
.nav-link[aria-current="page"] {
border-right-color: #1769aa;
}
Invalid Form Field
.form-field {
border-right: 4px solid #cccccc;
}
.form-field[aria-invalid="true"] {
border-right-color: #c0392b;
}
Keeping border width constant while changing color helps avoid layout changes during interaction.
Transitions and Animation
The border-right shorthand is not animated as a single value. Its individual longhand properties have their own animation behavior.
Color Transition
.panel {
border-right: 5px solid #1769aa;
transition: border-right-color 0.3s ease;
}
.panel:hover {
border-right-color: #27ae60;
}
Width Transition
.panel {
border-right: 4px solid #1769aa;
transition: border-right-width 0.3s ease;
}
.panel:hover {
border-right-width: 12px;
}
Width and Color Transition
.panel {
border-right: 4px solid #1769aa;
transition: border-right-width 0.3s ease, border-right-color 0.3s ease;
}
.panel:hover {
border-right-width: 10px;
border-right-color: #27ae60;
}
Keyframe Animation
@keyframes right-border-change {
from {
border-right-width: 4px;
border-right-color: #1769aa;
}
to {
border-right-width: 12px;
border-right-color: #27ae60;
}
}
.animated-panel {
border-right: 4px solid #1769aa;
animation: right-border-change 2s ease-in-out infinite alternate;
}
Reduced Motion Preference
.panel {
border-right: 5px solid #1769aa;
transition: border-right-color 0.3s ease;
}
.panel:hover {
border-right-color: #27ae60;
}
@media (prefers-reduced-motion: reduce) {
.panel {
transition: none;
}
}
Avoiding Layout Animation
.panel {
border-right: 10px solid transparent;
transition: border-right-color 0.3s ease;
}
.panel:hover {
border-right-color: #1769aa;
}
Changing border color is generally less disruptive than animating border width because the border's dimensions remain constant.
Responsive Design
The right border can adapt to viewport size, container size, and design requirements.
Media Query
.panel {
border-right: 8px solid #1769aa;
}
@media (max-width: 600px) {
.panel {
border-right-width: 4px;
}
}
Container Query
.panel-container {
container-type: inline-size;
}
.panel {
border-right: 4px solid #1769aa;
}
@container (min-width: 500px) {
.panel {
border-right-width: 10px;
}
}
Fluid Border Width
.panel {
border-right: clamp(2px, 0.5vw, 8px) solid #1769aa;
}
Responsive Border Removal
.sidebar {
border-right: 2px solid #cccccc;
}
@media (max-width: 600px) {
.sidebar {
border-right: none;
border-bottom: 2px solid #cccccc;
}
}
The border moves from the right edge to the bottom edge on smaller screens.
Responsive Custom Property
:root {
--panel-border-width: 8px;
}
@media (max-width: 600px) {
:root {
--panel-border-width: 4px;
}
}
.panel {
border-right: var(--panel-border-width) solid #1769aa;
}
Responsive borders can provide consistent visual separation as layouts change.
Practical Uses
The border-right property is useful for separating content, emphasizing panels, and indicating interface states.
Sidebar Separator
.sidebar {
padding-right: 20px;
border-right: 2px solid #d5dce3;
}
Featured Panel
.featured-panel {
padding: 20px;
border-right: 8px solid #1769aa;
background-color: #f3f8fc;
}
Navigation Divider
.nav-item {
padding-right: 15px;
margin-right: 15px;
border-right: 1px solid #cccccc;
}
Decorative Quote
blockquote {
margin: 20px 0;
padding-right: 20px;
border-right: 6px solid #1769aa;
}
Selected Card
.card {
border-right: 5px solid transparent;
}
.card.is-selected {
border-right-color: #27ae60;
}
Form Validation
.form-field {
border-right: 4px solid #cccccc;
}
.form-field[aria-invalid="true"] {
border-right-color: #c0392b;
}
Right-Aligned Callout
.callout {
padding: 20px;
border-right: 6px solid #1769aa;
background-color: #f3f8fc;
text-align: right;
}
Use consistent border styles and colors to establish visual hierarchy. Important interface states should also be communicated through accessible text or attributes.
border-right Example
The following example demonstrates several right border styles using the same width and color.
<div class="border-right-demo">
<div class="demo-box border-solid">Solid Border</div>
<div class="demo-box border-dashed">Dashed Border</div>
<div class="demo-box border-dotted">Dotted Border</div>
<div class="demo-box border-double">Double Border</div>
<div class="demo-box border-groove">Groove Border</div>
<div class="demo-box border-ridge">Ridge Border</div>
</div>
.border-right-demo {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: 16px;
}
.border-right-demo .demo-box {
padding: 20px;
background-color: #f3f8fc;
color: #173b5e;
font-weight: bold;
}
.border-right-demo .border-solid {
border-right: 8px solid #1769aa;
}
.border-right-demo .border-dashed {
border-right: 8px dashed #1769aa;
}
.border-right-demo .border-dotted {
border-right: 8px dotted #1769aa;
}
.border-right-demo .border-double {
border-right: 8px double #1769aa;
}
.border-right-demo .border-groove {
border-right: 8px groove #1769aa;
}
.border-right-demo .border-ridge {
border-right: 8px ridge #1769aa;
}
Each example uses an 8-pixel blue right border. Only the border style changes.
The appearance of dotted, dashed, groove, and ridge borders may vary slightly between browsers.
Important Considerations
Keep the following points in mind when using border-right:
- Purpose: Sets the width, style, and color of the physical right border.
- Property type: Shorthand.
- Longhands:
border-right-width,border-right-style, andborder-right-color. - Initial values:
medium none currentcolor. - Inheritance: The component properties are not inherited.
- Value order: Width, style, and color can appear in any order.
- Optional components: Omitted values reset to their initial values.
- Width: Accepts non-negative CSS lengths and the keywords
thin,medium, andthick. - Percentages: Not accepted for border width.
- Negative widths: Not accepted.
- Style: Controls how the border line is drawn.
- Color: Accepts any valid CSS color.
- Default style:
none, so no border appears unless a visible style is set. - Default color:
currentcolor. - Zero width: Produces no visible border thickness.
- Transparent border: Can reserve space without showing a visible line.
- Physical edge: Always targets the right side.
- Logical borders: May target the same edge depending on writing mode and direction.
- Shorthand resets: Later shorthand declarations can replace earlier longhand values.
- Box sizing: Visible border width contributes to the element's dimensions.
- Animation: Width and color can animate through their longhand properties.
- Custom properties: Can store reusable border components.
- Responsive design: Supports media queries, container queries, and calculated widths.
- Accessibility: Borders should not be the only indicator of important interface states.
- Browser support: Supported by all major browsers.
Use border-right when setting a complete right border, and use the individual longhands when changing only its width, style, or color.
Browser Support
The border-right property is widely supported in Chrome, Edge, Firefox, Safari, and other major browsers.
It is a long-established CSS property and does not require vendor prefixes. Compatibility for newer color functions and calculated values may depend on browser version.
.panel {
border-right: 5px solid #1769aa;
}
For current compatibility details, visit Can I Use? and search for border-right.
Specifications
The border-right property is defined in the CSS Backgrounds and Borders Module Level 3 specification.
CSS Backgrounds and Borders Module Level 3
The specification defines the shorthand's components, accepted values, and behavior when individual values are omitted.
