CSS border-block-color Property
The border-block-color property sets the colors of an element's logical block-start and block-end borders.
It accepts one or two CSS color values, allowing both block borders to share a color or use different colors. The physical sides affected depend on the element's writing mode, making the property useful for layouts that support horizontal and vertical text.
border-block-color Syntax
selector {
border-block-color: #1769aa;
}
The property accepts one or two color values.
.same-color {
border-block-color: blue;
}
.different-colors {
border-block-color: blue orange;
}
.rgb-colors {
border-block-color: rgb(23 105 170) rgb(211 84 0);
}
.transparent-end {
border-block-color: #1769aa transparent;
}
.text-color {
border-block-color: currentColor;
}
When two colors are supplied, the first applies to the block-start border and the second applies to the block-end border.
CSS-wide values are also accepted, including inherit, initial, revert, revert-layer, and unset.
.inherited {
border-block-color: inherit;
}
.reset {
border-block-color: initial;
}
A CSS-wide keyword must be used on its own. It cannot be combined with another color in the same declaration.
Unlike the border-block shorthand, border-block-color changes only border colors. It does not set border widths or styles.
Property Values
| Value | Description |
|---|---|
<color> |
Sets the same color for the block-start and block-end borders. |
<color> <color> |
Sets separate colors for the block-start and block-end borders, respectively. |
currentColor |
Uses the element's computed color value. |
transparent |
Sets a fully transparent border color without changing the border width or style. |
inherit |
Inherits the corresponding logical border colors from the parent element. |
initial |
Resets both logical border colors to their initial value, currentColor. |
unset |
Resets the colors to their initial values because the constituent properties are not inherited. |
The initial value of each constituent border color is currentColor. The property is not inherited, and its constituent colors can be animated as CSS colors.
The property affects the painting of the two logical block borders. It does not determine whether a border is visible.
How border-block-color Works
The border-block-color property is a shorthand for two logical border color properties:
border-block-start-color- controls the block-start border color.border-block-end-color- controls the block-end border color.
One Color for Both Sides
.panel {
border-block-color: #1769aa;
}
This is equivalent to:
.panel {
border-block-start-color: #1769aa;
border-block-end-color: #1769aa;
}
Different Colors for Each Side
.panel {
border-block-color: #1769aa #d35400;
}
This is equivalent to:
.panel {
border-block-start-color: #1769aa;
border-block-end-color: #d35400;
}
Color Does Not Create a Border
.panel {
border-block-color: red;
}
This declaration alone does not normally produce visible borders because the initial border style is none.
Specify a visible border style and an appropriate width when needed.
.panel {
border-block-style: solid;
border-block-width: 3px;
border-block-color: red;
}
Both logical block borders now have a visible 3-pixel solid red line.
Writing Modes and Border Mapping
Logical border properties use the element's writing mode to determine which physical sides they affect.
| Writing Mode | Block-Start Color | Block-End Color |
|---|---|---|
horizontal-tb |
Top border | Bottom border |
vertical-rl |
Right border | Left border |
vertical-lr |
Left border | Right border |
sideways-rl |
Right border | Left border |
sideways-lr |
Left border | Right border |
Horizontal Writing
.horizontal-panel {
writing-mode: horizontal-tb;
border-block: 4px solid;
border-block-color: blue orange;
}
The top border is blue, and the bottom border is orange.
Vertical Writing
.vertical-panel {
writing-mode: vertical-rl;
border-block: 4px solid;
border-block-color: blue orange;
}
The right border is blue, and the left border is orange.
Changing Text Direction
.rtl-panel {
direction: rtl;
writing-mode: horizontal-tb;
border-block: 4px solid;
border-block-color: blue orange;
}
The colors remain on the top and bottom borders. Changing direction alone does not change the block axis in horizontal writing mode.
This logical mapping allows the same component styles to work across writing systems without rewriting the border color declarations.
Using One Color
When one color is specified, the browser applies it to both the block-start and block-end borders.
.section-panel {
border-block: 2px solid;
border-block-color: #1769aa;
}
In horizontal writing mode, the top and bottom borders are blue.
Using a Named Color
.notice {
border-block: 3px solid;
border-block-color: teal;
}
Using a Custom Property
.themed-panel {
--accent-color: #1769aa;
border-block: 3px solid;
border-block-color: var(--accent-color);
}
Custom properties make it easier to reuse a consistent border color across multiple components.
Updating the Color
.status-panel {
border-block: 3px solid;
border-block-color: #1769aa;
}
.status-panel.warning {
border-block-color: #b45309;
}
The warning class changes both logical border colors without changing their widths or styles.
Using Two Colors
Two color values allow the block-start and block-end borders to have different colors.
.two-tone-panel {
border-block: 4px solid;
border-block-color: #1769aa #d35400;
}
The first value applies to block-start. The second applies to block-end.
A Section Divider
.content-section {
border-block-style: solid;
border-block-width: 2px;
border-block-color: #c5d8e8 #1769aa;
padding-block: 20px;
}
This creates a lighter border at block-start and a darker border at block-end.
Using Individual Longhands
.content-section {
border-block: 3px solid;
border-block-start-color: #1769aa;
border-block-end-color: #d35400;
}
Individual color properties provide the same result and can be useful when only one side needs to change.
Overriding One Side
.content-section {
border-block: 3px solid;
border-block-color: #1769aa;
border-block-end-color: #d35400;
}
The block-start border remains blue, while the block-end border becomes orange.
Place the individual override after the shorthand when both declarations have the same cascade priority.
CSS Color Formats
The border-block-color property accepts CSS color values, including named colors, hexadecimal notation, and color functions.
Named Colors
.named-colors {
border-block-color: navy teal;
}
Hexadecimal Colors
.hex-colors {
border-block-color: #1769aa #d35400;
}
RGB Colors
.rgb-colors {
border-block-color: rgb(23 105 170) rgb(211 84 0);
}
HSL Colors
.hsl-colors {
border-block-color: hsl(207 76% 38%) hsl(24 100% 41%);
}
Colors with Alpha Transparency
.alpha-colors {
border-block-color: rgb(23 105 170 / 80%) rgb(211 84 0 / 40%);
}
Alpha values control the transparency of the border colors without changing border thickness.
Using color-mix()
.mixed-colors {
border-block-color: color-mix(in srgb, blue 70%, white) color-mix(in srgb, orange 70%, white);
}
The color-mix() function creates colors by mixing specified color values. Its compatibility should be checked separately from the border-block-color property.
For broadly compatible styling, hexadecimal and standard RGB color values remain straightforward choices.
Using currentColor
The currentColor keyword represents the element's computed color value.
.matching-panel {
color: #1769aa;
border-block: 3px solid;
border-block-color: currentColor;
}
Both logical block borders match the text color.
Default Border Color
.default-color {
color: #1769aa;
border-block: 3px solid;
}
Because the color component is omitted, the border-block shorthand resets both border colors to currentColor.
Combining currentColor with Another Color
.mixed-panel {
color: #1769aa;
border-block: 3px solid;
border-block-color: currentColor #d35400;
}
The block-start border follows the text color, while the block-end border uses a fixed orange color.
Inherited Text Colors
.theme {
color: #1769aa;
}
.theme .panel {
border-block: 2px solid currentColor;
}
The panel inherits its text color through the normal CSS inheritance rules, and currentColor uses that computed value for the borders.
The border-block-color property itself is not inherited, even though currentColor can reflect an inherited text color.
Transparent Border Colors
The transparent keyword makes a border color fully transparent while preserving the border's specified width and style.
.transparent-panel {
border-block: 4px solid;
border-block-color: transparent;
}
The borders occupy space but are not visibly painted.
One Transparent Side
.one-visible-side {
border-block: 4px solid;
border-block-color: transparent #1769aa;
}
The block-start border is transparent, while the block-end border is blue.
Reserving Space for Hover States
.hover-panel {
border-block: 3px solid transparent;
}
.hover-panel:hover {
border-block-color: #1769aa;
}
The border thickness remains constant, helping prevent layout changes when the user hovers over the element.
Partial Transparency
.semi-transparent {
border-block: 3px solid;
border-block-color: rgb(23 105 170 / 50%);
}
Partial transparency allows the background beneath the border to influence its visible color.
Border Style and Width
The border-block-color property changes border colors only. A visible border requires a suitable style and a nonzero used width.
Color Without Style
.invisible-border {
border-block-color: red;
}
No border appears if the border styles remain at their initial value of none.
Setting the Style and Width
.visible-border {
border-block-style: solid;
border-block-width: 4px;
border-block-color: red;
}
This creates visible red borders on both logical block sides.
Using the border-block Shorthand
.panel {
border-block: 4px solid #1769aa;
}
The shorthand sets width, style, and color together.
Changing Color Separately
.panel {
border-block: 4px solid #1769aa;
border-block-color: #1769aa #d35400;
}
The second declaration changes only the colors, preserving the solid style and 4-pixel width.
Using Different Widths
.panel {
border-block-style: solid;
border-block-width: 2px 6px;
border-block-color: #1769aa #d35400;
}
The block-start border is 2 pixels wide and blue. The block-end border is 6 pixels wide and orange.
Shorthand and Longhand Interactions
Several border properties can affect the same logical border colors. Declaration order and the CSS cascade determine which values apply.
border-block Resets Colors
.panel {
border-block-color: blue orange;
border-block: 3px solid green;
}
The later border-block shorthand resets both block border colors to green.
border-block-color Overrides Shorthand Colors
.panel {
border-block: 3px solid green;
border-block-color: blue orange;
}
The later color shorthand changes the block-start border to blue and the block-end border to orange.
Individual Color Overrides
.panel {
border-block-color: blue;
border-block-end-color: orange;
}
Both sides initially receive blue. The later declaration changes only the block-end color.
The border Shorthand
.panel {
border-block-color: blue orange;
border: 2px solid gray;
}
The later border shorthand sets all four physical border colors to gray, overriding the earlier logical colors where they map to those physical sides.
CSS Cascade Priority
These examples assume the declarations have equal origin, importance, specificity, and cascade layer priority. A higher-priority declaration can win regardless of source order.
For maintainability, establish general border styles first and apply more specific logical color overrides afterward.
Logical vs. Physical Border Colors
Physical border color properties always target fixed physical sides. Logical border color properties follow the element's writing mode.
Physical Border Colors
.physical-panel {
border-top: 3px solid blue;
border-bottom: 3px solid orange;
}
The colors remain on the physical top and bottom borders, even if the writing mode changes.
Logical Border Colors
.logical-panel {
border-block: 3px solid;
border-block-color: blue orange;
}
In horizontal writing mode, blue appears at the top and orange at the bottom. In vertical-rl, blue appears on the right and orange on the left.
Conflicting Declarations
.panel {
border-top-color: red;
border-block-start-color: blue;
}
In horizontal-tb, both declarations affect the top border. At equal cascade priority, the later blue declaration wins.
In vertical-rl, the first declaration affects the top border while the second affects the right border.
Choosing the Appropriate Property
Use physical properties when a border must remain on a specific physical side, such as the bottom edge of a fixed horizontal toolbar.
Use logical properties when the border should follow the content's writing direction and layout structure.
Interactive States and Transitions
Border colors can change in response to user interaction, including hover, focus, and component state changes.
Hover State
.interactive-card {
border-block: 3px solid #c5d8e8;
}
.interactive-card:hover {
border-block-color: #1769aa;
}
Both logical block borders change color when the card is hovered.
Color Transition
.animated-card {
border-block: 3px solid #c5d8e8;
transition: border-block-start-color 200ms ease, border-block-end-color 200ms ease;
}
.animated-card:hover {
border-block-color: #1769aa #d35400;
}
The two logical border colors transition independently to their new values.
Reduced Motion
@media (prefers-reduced-motion: reduce) {
.animated-card {
transition: none;
}
}
Disabling the transition for users who prefer reduced motion can make interactive state changes more comfortable.
Focus Styling
.form-control {
border: 1px solid #8a99a8;
border-block-color: #8a99a8;
}
.form-control:focus-visible {
border-block-color: #1769aa;
outline: 2px solid #1769aa;
outline-offset: 2px;
}
The logical borders change color on keyboard focus, while the outline provides an additional visible focus indicator.
When borders communicate an important state, avoid relying on color alone. Include another visual cue or descriptive text where appropriate.
border-block-color Example
The following example shows how two border colors follow the logical block-start and block-end sides in different writing modes.
Each box uses a blue block-start border and an orange block-end border.
<div class="border-block-color-demo">
<div class="demo-item">
<p>horizontal-tb</p>
<div class="demo-box horizontal">Block colors</div>
</div>
<div class="demo-item">
<p>vertical-rl</p>
<div class="demo-box vertical-right">Block colors</div>
</div>
<div class="demo-item">
<p>vertical-lr</p>
<div class="demo-box vertical-left">Block colors</div>
</div>
</div>
.border-block-color-demo {
display: flex;
flex-wrap: wrap;
align-items: flex-start;
gap: 24px;
}
.border-block-color-demo .demo-item {
padding: 10px;
}
.border-block-color-demo .demo-item p {
margin-bottom: 10px;
font-weight: bold;
}
.border-block-color-demo .demo-box {
box-sizing: border-box;
inline-size: 180px;
block-size: 120px;
padding: 15px;
border-block-style: solid;
border-block-width: 8px;
border-block-color: #1769aa #d35400;
background-color: #e8f2fb;
color: #173b5e;
font-weight: bold;
text-align: center;
}
.border-block-color-demo .horizontal {
writing-mode: horizontal-tb;
}
.border-block-color-demo .vertical-right {
writing-mode: vertical-rl;
}
.border-block-color-demo .vertical-left {
writing-mode: vertical-lr;
}
horizontal-tb
vertical-rl
vertical-lr
In horizontal-tb, blue appears at the top and orange at the bottom.
In vertical-rl, blue appears on the right and orange on the left.
In vertical-lr, blue appears on the left and orange on the right.
The colors remain assigned to the same logical sides even though their physical positions change.
Important Considerations
Keep the following points in mind when using border-block-color:
- Logical color shorthand: The property controls the colors of the block-start and block-end borders.
- One value: A single color applies to both logical block sides.
- Two values: The first color applies to block-start, and the second applies to block-end.
- Writing mode: The physical sides affected depend on
writing-mode. - Horizontal writing: The property normally affects the top and bottom border colors.
- Vertical writing: The property normally affects the left and right border colors.
- Initial value: Both constituent border colors initially use
currentColor. - Inheritance: The property is not inherited, although
currentColorcan use an inherited text color. - Color formats: Named colors, hexadecimal values, RGB, HSL, and supported CSS color functions are accepted.
- Transparency: Transparent colors do not remove the border's layout space.
- Border visibility: A visible border style and nonzero used width are needed for the color to appear.
- Widths and styles: The property does not modify border thickness or line style.
- Individual sides: Use
border-block-start-colorandborder-block-end-colorto change one side independently. - Shorthand resets: Later
borderorborder-blockdeclarations can reset previously specified logical border colors. - Physical properties: Logical and physical color properties can affect the same physical border depending on writing mode.
- Transitions: Border colors can be animated using the constituent logical color properties.
- Compatibility: Modern browsers support logical border colors, but newer CSS color functions have separate compatibility requirements.
- Accessibility: Ensure important border colors have sufficient contrast and are not the only indication of an interactive state.
Use border-block-color when border colors should follow the logical block axis. It is especially useful for components that must adapt to different writing modes without changing their CSS color declarations.
Browser Support
The border-block-color property has Baseline Widely available status and is supported in modern versions of Chrome, Edge, Firefox, Safari, and other major browsers.
Standard color values work without vendor prefixes. Compatibility for newer CSS color functions should be checked separately.
Standard Declaration
.panel {
border-block: 3px solid;
border-block-color: #1769aa #d35400;
}
Physical Color Fallback
.panel {
border-top: 3px solid #1769aa;
border-bottom: 3px solid #d35400;
}
@supports (border-block-color: red blue) {
.panel {
border-top: 0;
border-bottom: 0;
border-block-style: solid;
border-block-width: 3px;
border-block-color: #1769aa #d35400;
}
}
This fallback assumes horizontal writing mode. Browsers that support the logical color property use logical block borders, while older browsers retain the physical top and bottom borders.
For vertical writing modes, the physical fallback must be adapted to the corresponding left and right sides.
Visit Can I Use? to review current browser compatibility.
Specifications
The border-block-color property is defined in the CSS Logical Properties and Values Module Level 1 specification.
CSS Logical Properties and Values Module Level 1
General border color behavior is defined in the CSS Backgrounds and Borders Module Level 3 specification.
