CSS border-right-color Property
The border-right-color property sets the color of an element's right border.
It accepts CSS color values, including named colors, hexadecimal values, RGB, HSL, currentcolor, and transparent. It changes only the border color, leaving the existing border width and style unchanged.
The property controls the physical right border regardless of writing mode or text direction. A visible border style and a nonzero border width are required for the color to appear.
border-right-color Syntax
The property accepts a single CSS color value or a CSS-wide keyword.
selector {
border-right-color: #1769aa;
}
The general syntax is:
selector {
border-right-color: <color>;
}
Named Color
.panel {
border-right-color: steelblue;
}
Hexadecimal Color
.panel {
border-right-color: #1769aa;
}
RGB Color
.panel {
border-right-color: rgb(23 105 170);
}
HSL Color
.panel {
border-right-color: hsl(207 76% 38%);
}
Transparent Color
.panel {
border-right-color: transparent;
}
Current Text Color
.panel {
border-right-color: currentcolor;
}
Custom Property
.panel {
border-right-color: var(--accent-color, #1769aa);
}
CSS-Wide Keywords
.inherited {
border-right-color: inherit;
}
.reset {
border-right-color: initial;
}
.unset {
border-right-color: unset;
}
.reverted {
border-right-color: revert;
}
.layer-reverted {
border-right-color: revert-layer;
}
The property accepts one color value. Multiple colors separated by spaces are invalid.
Property Values
The border-right-color property supports CSS color values and CSS-wide keywords.
| Value | Description |
|---|---|
<color> |
Any valid CSS color, including named colors, hexadecimal values, and color functions. |
currentcolor |
Uses the element's computed color value. |
transparent |
Makes the border fully transparent without changing its width or style. |
inherit |
Inherits the computed right border color from the parent. |
initial |
Resets the color to currentcolor. |
unset |
Resets the color to currentcolor because the property is not inherited. |
revert |
Reverts the property according to cascade origin rules. |
revert-layer |
Reverts the property according to cascade layer rules. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | currentcolor |
| Inherited | No |
| Applies to | Elements that support border properties |
| Computed value | Computed color |
| Animation type | By computed value type (color) |
| Percentages | Not accepted as standalone values; may appear within color functions |
| Property type | Longhand |
| Physical edge | Right |
The property changes only the color component of the right border. It does not set the border's width or style.
How It Works
The browser uses the value of border-right-color when painting the right border, provided that the border has a visible style and nonzero width.
Step 1: Establish a Border
.panel {
border-right: 6px solid #cccccc;
}
The panel has a 6-pixel solid gray border on its right edge.
Step 2: Change the Color
.panel {
border-right: 6px solid #cccccc;
border-right-color: #1769aa;
}
The border becomes blue while retaining its width and style.
Step 3: Change the Color Again
.panel {
border-right: 6px solid #cccccc;
border-right-color: #27ae60;
}
The border becomes green.
Step 4: Make the Border Transparent
.panel {
border-right: 6px solid #cccccc;
border-right-color: transparent;
}
The border remains 6 pixels wide but becomes invisible.
Step 5: Restore the Text Color
.panel {
color: #1769aa;
border-right: 6px solid #cccccc;
border-right-color: currentcolor;
}
The border now follows the element's text color.
Use the longhand property when the border's width and style should remain unchanged.
CSS Color Formats
The border-right-color property supports the CSS color formats available in the browser.
Named Colors
.panel {
border-right: 5px solid;
border-right-color: steelblue;
}
Hexadecimal Colors
.panel {
border-right: 5px solid;
border-right-color: #1769aa;
}
RGB Colors
.panel {
border-right: 5px solid;
border-right-color: rgb(23 105 170);
}
HSL Colors
.panel {
border-right: 5px solid;
border-right-color: hsl(207 76% 38%);
}
HWB Colors
.panel {
border-right: 5px solid;
border-right-color: hwb(207 9% 33%);
}
LAB Colors
.panel {
border-right: 5px solid;
border-right-color: lab(44% -3 -42);
}
OKLCH Colors
.panel {
border-right: 5px solid;
border-right-color: oklch(55% 0.15 245);
}
color() Function
.panel {
border-right: 5px solid;
border-right-color: color(display-p3 0.1 0.4 0.7);
}
color-mix() Function
.panel {
border-right: 5px solid;
border-right-color: color-mix(in srgb, #1769aa 70%, white);
}
light-dark() Function
.panel {
color-scheme: light dark;
border-right: 5px solid;
border-right-color: light-dark(#1769aa, #79b8e8);
}
The light-dark() function selects a color based on the element's used color scheme.
For older browser compatibility, provide a widely supported fallback before using newer color functions.
Using currentcolor
The currentcolor keyword makes the right border use the element's computed text color.
Basic currentcolor
.panel {
color: #1769aa;
border-right: 5px solid;
border-right-color: currentcolor;
}
The border uses the same blue as the text.
Omitting the Border Color
.panel {
color: #1769aa;
border-right: 5px solid;
}
The omitted border color defaults to currentcolor.
Changing Text Color
.panel {
color: #1769aa;
border-right: 5px solid currentcolor;
}
.panel:hover {
color: #27ae60;
}
The border changes to green along with the text.
Inherited Text Color
.container {
color: #1769aa;
}
.container .panel {
border-right: 5px solid currentcolor;
}
If the panel does not override color, its border uses the inherited text color.
Resetting to currentcolor
.panel {
color: #1769aa;
border-right: 5px solid #c0392b;
border-right-color: initial;
}
The border color resets to currentcolor, so it follows the blue text color.
The currentcolor keyword is useful for icons, separators, and components that should automatically match their text color.
Transparency and Alpha Values
The right border can be fully transparent or partially transparent using CSS color values with alpha channels.
Fully Transparent Border
.panel {
border-right: 6px solid;
border-right-color: transparent;
}
The border retains its width but is not visibly painted.
50% Opacity With RGB
.panel {
border-right: 6px solid;
border-right-color: rgb(23 105 170 / 50%);
}
25% Opacity With HSL
.panel {
border-right: 6px solid;
border-right-color: hsl(207 76% 38% / 25%);
}
Hexadecimal Alpha
.panel {
border-right: 6px solid;
border-right-color: #1769aa80;
}
The final two hexadecimal digits represent the alpha channel.
Transparent to Visible State
.panel {
border-right: 6px solid transparent;
}
.panel:hover {
border-right-color: #1769aa;
}
The border remains the same width in both states, preventing a layout change.
Partially Transparent Divider
.sidebar {
border-right: 1px solid rgb(23 105 170 / 30%);
}
The divider allows the background behind it to show through.
Transparency changes the painted appearance of the border, not the space occupied by its width.
Border Visibility
Setting border-right-color does not guarantee a visible border. The border must also have a visible style and nonzero width.
Color Without Style
.panel {
border-right-color: #1769aa;
}
No right border appears because the initial border style is none.
Visible Border
.panel {
border-right-width: 5px;
border-right-style: solid;
border-right-color: #1769aa;
}
Style none
.panel {
border-right-width: 5px;
border-right-style: none;
border-right-color: #1769aa;
}
The computed border width becomes zero because the style is none.
Zero Width
.panel {
border-right-width: 0;
border-right-style: solid;
border-right-color: #1769aa;
}
The border has no visible thickness.
Transparent Border
.panel {
border-right: 5px solid transparent;
}
The border occupies 5 pixels but is not visible.
Matching Background Color
.panel {
background-color: #ffffff;
border-right: 5px solid #ffffff;
}
The border may be difficult to distinguish from the background even though it is present.
If a border color does not appear, inspect the computed border style, width, color, and any border-image settings.
Shorthand Interactions
The border-right-color property is affected by shorthand declarations that include the right border color.
border-right Shorthand
.panel {
border-right: 5px solid #1769aa;
}
This sets the width, style, and color of the right border.
Override the Shorthand Color
.panel {
border-right: 5px solid #1769aa;
border-right-color: #27ae60;
}
The border becomes green while retaining its width and style.
Later Shorthand Reset
.panel {
border-right-color: #c0392b;
border-right: 5px solid;
}
The later shorthand resets the color to currentcolor.
border-color Shorthand
.panel {
border-color: #1769aa #27ae60 #c0392b #f39c12;
}
The second value controls the right border color.
Override border-color
.panel {
border: 5px solid;
border-color: #1769aa;
border-right-color: #27ae60;
}
All borders are blue except the right border, which is green.
border Shorthand
.panel {
border-right-color: #c0392b;
border: 2px solid #1769aa;
}
The later border shorthand resets the right border color along with the other border components.
border-inline-color Shorthand
.panel {
direction: ltr;
border-inline-color: #1769aa #27ae60;
}
In horizontal left-to-right writing, the second value sets the physical right border color.
Use the longhand after a shorthand when you want to change only the right border color.
Physical vs. Logical Borders
The border-right-color property always targets the physical right edge. Logical border color properties adapt to writing mode and direction.
Physical Right Border Color
.panel {
border-right: 5px solid;
border-right-color: #1769aa;
}
The right border remains blue regardless of writing direction.
Logical Inline-End Color
.panel {
border-inline-end: 5px solid;
border-inline-end-color: #1769aa;
}
In horizontal left-to-right writing, this targets the right border. In horizontal right-to-left writing, it targets the left border.
Logical Inline-Start Color
.panel {
border-inline-start: 5px solid;
border-inline-start-color: #1769aa;
}
In horizontal right-to-left writing, this targets the right border.
Writing Mode Comparison
| Writing Mode | Direction | Logical Color Property Matching Right |
|---|---|---|
horizontal-tb |
ltr |
border-inline-end-color |
horizontal-tb |
rtl |
border-inline-start-color |
vertical-rl |
ltr or rtl |
border-block-start-color |
vertical-lr |
ltr or rtl |
border-block-end-color |
Vertical Writing Example
.panel {
writing-mode: vertical-rl;
border-right: 5px solid;
border-right-color: #1769aa;
}
The border remains on the physical right edge.
Use physical properties when the border must remain on a fixed edge and logical properties when it should follow the writing direction.
Cascade and Overrides
The CSS cascade determines which right border color applies when multiple declarations target the same element.
Later Declaration
.panel {
border-right-color: #1769aa;
border-right-color: #27ae60;
}
The later green value wins when cascade priority is otherwise equal.
Higher Specificity
.panel {
border-right-color: #1769aa;
}
.panel.featured {
border-right-color: #27ae60;
}
The featured panel uses green.
Shorthand Override
.panel {
border-right-color: #c0392b;
border-right: 5px solid #1769aa;
}
The later shorthand sets the right border color to blue.
Longhand Override
.panel {
border-right: 5px solid #1769aa;
border-right-color: #27ae60;
}
The later longhand changes only the color.
Physical and Logical Conflict
.panel {
border-right: 5px solid;
border-right-color: #1769aa;
border-inline-end-color: #27ae60;
}
In horizontal left-to-right writing, both color declarations target the right border. The later logical declaration wins when cascade priority is otherwise equal.
CSS Layers
@layer base, components;
@layer base {
.panel {
border-right-color: #1769aa;
}
}
@layer components {
.panel {
border-right-color: #27ae60;
}
}
For normal declarations, the later layer takes precedence.
When a border color appears incorrect, check declaration order, specificity, shorthand resets, cascade layers, and logical border properties.
CSS Custom Properties
CSS custom properties can store reusable right border colors for components and themes.
Shared Accent Color
:root {
--accent-color: #1769aa;
}
.panel {
border-right: 5px solid;
border-right-color: var(--accent-color);
}
Fallback Color
.panel {
border-right: 5px solid;
border-right-color: var(--accent-color, #1769aa);
}
The fallback is used when the custom property is unavailable or has the guaranteed-invalid value.
Component Variants
.notice {
--notice-color: #1769aa;
border-right: 5px solid var(--notice-color);
}
.notice.success {
--notice-color: #27ae60;
}
.notice.error {
--notice-color: #c0392b;
}
Theme-Based Color
:root {
--border-accent: #1769aa;
}
[data-theme="dark"] {
--border-accent: #79b8e8;
}
.panel {
border-right: 5px solid var(--border-accent);
}
Calculated Color
:root {
--accent-color: #1769aa;
}
.panel {
border-right: 5px solid;
border-right-color: color-mix(in srgb, var(--accent-color) 70%, white);
}
Color Based on currentcolor
.panel {
color: #1769aa;
border-right: 5px solid;
border-right-color: color-mix(in srgb, currentcolor 60%, transparent);
}
Custom properties make it easier to update border colors consistently across a website.
Interactive States
Right border colors can communicate hover, focus, selection, and validation states.
Hover State
.panel {
border-right: 5px solid #1769aa;
}
.panel:hover {
border-right-color: #27ae60;
}
Focus State
.form-field {
border-right: 4px solid #cccccc;
}
.form-field:focus {
border-right-color: #1769aa;
}
Keyboard Focus
.form-field {
border-right: 4px 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;
}
Disabled State
.form-field {
border-right: 4px solid #1769aa;
}
.form-field:disabled {
border-right-color: #cccccc;
}
Border color can reinforce interface feedback, but important states should also be communicated through text, labels, or accessible attributes.
Transitions and Animation
The border-right-color property supports color interpolation and can be animated or transitioned between compatible values.
Basic Color Transition
.panel {
border-right: 5px solid #1769aa;
transition: border-right-color 0.3s ease;
}
.panel:hover {
border-right-color: #27ae60;
}
Transparent to Visible
.panel {
border-right: 5px solid transparent;
transition: border-right-color 0.3s ease;
}
.panel:hover {
border-right-color: #1769aa;
}
The border becomes visible without changing its width.
Keyframe Animation
@keyframes right-border-color-change {
from {
border-right-color: #1769aa;
}
to {
border-right-color: #27ae60;
}
}
.animated-panel {
border-right: 5px solid #1769aa;
animation: right-border-color-change 2s ease-in-out infinite alternate;
}
Multiple Color Stops
@keyframes border-colors {
0% {
border-right-color: #1769aa;
}
50% {
border-right-color: #27ae60;
}
100% {
border-right-color: #c0392b;
}
}
.animated-panel {
border-right: 5px solid #1769aa;
animation: border-colors 4s linear infinite;
}
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;
}
}
Changing only border color avoids the layout changes that can occur when animating border width.
Responsive Design
The right border color can adapt to viewport size, container size, and color scheme preferences.
Media Query
.panel {
border-right: 5px solid #1769aa;
}
@media (max-width: 600px) {
.panel {
border-right-color: #27ae60;
}
}
Container Query
.panel-container {
container-type: inline-size;
}
.panel {
border-right: 5px solid #1769aa;
}
@container (min-width: 500px) {
.panel {
border-right-color: #27ae60;
}
}
Dark Color Scheme
.panel {
border-right: 5px solid #1769aa;
}
@media (prefers-color-scheme: dark) {
.panel {
border-right-color: #79b8e8;
}
}
Custom Property for Themes
:root {
--border-color: #1769aa;
}
@media (prefers-color-scheme: dark) {
:root {
--border-color: #79b8e8;
}
}
.panel {
border-right: 5px solid var(--border-color);
}
High Contrast Preference
.panel {
border-right: 5px solid #1769aa;
}
@media (forced-colors: active) {
.panel {
border-right-color: CanvasText;
}
}
In forced-colors mode, the browser may override author-defined colors. System colors can help preserve meaningful borders.
Responsive color changes should maintain sufficient visual distinction from surrounding content.
Practical Uses
The border-right-color property is useful for changing separators, accents, and interface indicators without modifying border dimensions.
Sidebar Divider
.sidebar {
border-right: 2px solid #d5dce3;
}
.sidebar.featured {
border-right-color: #1769aa;
}
Selected Navigation Item
.nav-link {
border-right: 4px solid transparent;
}
.nav-link[aria-current="page"] {
border-right-color: #1769aa;
}
Status Panel
.status-panel {
border-right: 6px solid #1769aa;
}
.status-panel.success {
border-right-color: #27ae60;
}
.status-panel.error {
border-right-color: #c0392b;
}
Hover Accent
.card {
border-right: 5px solid #cccccc;
}
.card:hover {
border-right-color: #1769aa;
}
Form Validation
.form-field {
border-right: 4px solid #cccccc;
}
.form-field[aria-invalid="true"] {
border-right-color: #c0392b;
}
Theme Accent
.panel {
border-right: 5px solid var(--accent-color, #1769aa);
}
Subtle Divider
.content-column {
border-right: 1px solid rgb(23 105 170 / 25%);
}
Use consistent border colors for related components, and avoid relying on color alone to communicate important information.
border-right-color Example
The following example demonstrates several right border colors while keeping the border width and style consistent.
<div class="border-right-color-demo">
<div class="demo-box color-blue">Blue Border</div>
<div class="demo-box color-green">Green Border</div>
<div class="demo-box color-red">Red Border</div>
<div class="demo-box color-orange">Orange Border</div>
<div class="demo-box color-current">currentcolor</div>
<div class="demo-box color-transparent">Transparent Border</div>
</div>
.border-right-color-demo {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: 16px;
}
.border-right-color-demo .demo-box {
box-sizing: border-box;
padding: 20px;
border-right: 8px solid;
background-color: #f3f8fc;
color: #173b5e;
font-weight: bold;
}
.border-right-color-demo .color-blue {
border-right-color: #1769aa;
}
.border-right-color-demo .color-green {
border-right-color: #27ae60;
}
.border-right-color-demo .color-red {
border-right-color: #c0392b;
}
.border-right-color-demo .color-orange {
border-right-color: #f39c12;
}
.border-right-color-demo .color-current {
border-right-color: currentcolor;
}
.border-right-color-demo .color-transparent {
border-right-color: transparent;
}
Every box uses an 8-pixel solid right border. Only the border color changes.
The currentcolor example uses the box's text color, while the transparent example reserves the same border space without displaying a visible line.
Important Considerations
Keep the following points in mind when using border-right-color:
- Purpose: Sets the color of the physical right border.
- Property type: Longhand.
- Initial value:
currentcolor. - Inheritance: The property is not inherited.
- Accepted values: Any valid CSS color or CSS-wide keyword.
- Named colors: Supported.
- Hexadecimal colors: Supported.
- Color functions: Supported according to browser compatibility.
- currentcolor: Uses the element's computed text color.
- transparent: Makes the border invisible without removing its width.
- Alpha values: Allow partially transparent borders.
- Border style: Must be visible for the color to appear.
- Border width: Must be nonzero for the color to appear.
- Shorthand interactions: Later shorthand declarations can reset the color.
- Physical edge: Always targets the right side.
- Logical borders: Can target the same edge depending on writing mode and direction.
- Box sizing: Changing only the color does not change the border's dimensions.
- Animation: Color changes can transition smoothly.
- Custom properties: Can store reusable color values.
- Responsive design: Supports media queries, container queries, and color scheme changes.
- Accessibility: Border color should not be the only indicator of an important interface state.
- Browser support: Supported by all major browsers.
Use border-right-color when changing the right border's color without modifying its width or style.
Browser Support
The border-right-color 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. Support for newer color functions depends on browser version.
.panel {
border-right: 5px solid;
border-right-color: #1769aa;
}
For current compatibility details, visit Can I Use? and search for border-right-color.
Specifications
The border-right-color property is defined in the CSS Backgrounds and Borders Module Level 3 specification.
CSS Backgrounds and Borders Module Level 3
The specification defines border color values, initial behavior, and how border colors interact with the other border properties.
