Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

border-block-color: separate the start and end colors

Set one color for both block borders or a start/end pair while keeping their widths and line styles.

Version: CSS Modules

Syntax

border-block-color: red blue;

border-block-color controls only the two block-axis colors. One color applies to both ends; with two, the first is block-start and the second block-end. That order is logical, not always top then bottom. In vertical-rl, red blue means a red right border and a blue left border. In horizontal-tb the same pair means red above and blue below. Switching only direction to rtl in those modes does not reverse that block-axis pair.

This color shorthand does not make a missing border appear. Its width and style are separate, and a side whose style is none has no visible line even if its computed color is red. Conversely, changing these colors leaves existing solid widths intact. transparent retains the space of an otherwise visible border; it is not equivalent to removing the border style. With currentColor, the chosen side follows the element’s color. Use the individual start/end color properties if a later declaration should change only one end.

The test starts with an 80×40 content box, four 4px solid borders and vertical-rl. It reads the right and left colors as red and blue, then gets the same pair after direction becomes rtl. Assigning one green color changes both sides to green without changing their 4px widths or the 88×48 border box. A separate box with only border-block-color: red blue stays 80×40: its end style is none and its resolved width is 0px.

Examples

const el=document.createElement('div');el.style.cssText='writing-mode:vertical-rl;direction:ltr;width:80px;height:40px;box-sizing:content-box;padding:0;border:4px solid black;border-block-color:rgb(255,0,0) rgb(0,0,255)';document.body.append(el);
const read=label=>{const s=getComputedStyle(el),r=el.getBoundingClientRect();console.log(label+'='+[s.borderRightColor,s.borderLeftColor].join('|')+'; widths='+s.borderRightWidth+','+s.borderLeftWidth+'; box='+r.width+'x'+r.height)};
read('pair');el.style.direction='rtl';read('rtl');el.style.borderBlockColor='rgb(0,128,0)';read('single');
const bare=document.createElement('div');bare.style.cssText='width:80px;height:40px;border-block-color:red blue';document.body.append(bare);const s=getComputedStyle(bare),r=bare.getBoundingClientRect();console.log('color-only='+s.borderBlockEndStyle+','+s.borderBlockEndWidth+'; box='+r.width+'x'+r.height);

Result

pair=rgb(255, 0, 0)|rgb(0, 0, 255); widths=4px,4px; box=88x48
rtl=rgb(255, 0, 0)|rgb(0, 0, 255); widths=4px,4px; box=88x48
single=rgb(0, 128, 0)|rgb(0, 128, 0); widths=4px,4px; box=88x48
color-only=none,0px; box=80x40

The color-value cases were executed in Chromium 157.0.8103.51. CSS Borders Level 4 also specifies newer border-color value extensions; this example does not establish support for those extensions, border images or forced-colors rendering.

Sources