Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

border-block: frame both ends of the block axis

Apply the same width, line style and color to block-start and block-end without hard-coding top and bottom.

Version: CSS Modules

Syntax

border-block: 4px solid red;

border-block is a shorthand for both block-axis borders. A declaration such as 4px solid red sets the width, style and color at both ends; it does not set the inline-axis borders. In horizontal-tb these ends are top and bottom. In vertical-rl or vertical-lr they are the two vertical sides. Changing direction from ltr to rtl alone does not exchange the block edges in these writing modes. The property follows the writing mode of the element being bordered, not the orientation of your monitor.

A shorthand also resets omitted components. Setting border-block: 6px after a visible solid border does not preserve solid: the style returns to none, so the border contributes no used width. Likewise, an omitted color returns to currentColor rather than preserving a previous red. border-block cannot assign two different complete border descriptions to its ends; use border-block-start and border-block-end, or the two-value width/style/color shorthands, when the ends must differ. Physical and logical declarations affecting the same edge still compete in the cascade.

The example gives each empty content box a physical width of 80px and height of 40px, with no padding. Its inline borders are 2px and block borders 4px. Both horizontal directions produce a border box of 84×48; vertical writing produces 88×44. The printed widths are ordered top, right, bottom, left, so the rotation of the mapping is visible. Replacing the horizontal block shorthand with 6px removes those two visible edges and leaves 84×40, demonstrating the reset rather than a failure to parse the length.

Examples

const make=(mode,direction)=>{const el=document.createElement('div');el.style.cssText='width:80px;height:40px;box-sizing:content-box;padding:0;border:0;border-inline:2px solid black;border-block:4px solid red';el.style.writingMode=mode;el.style.direction=direction;document.body.append(el);return el};
const measure=el=>{const s=getComputedStyle(el),r=el.getBoundingClientRect();return [s.borderTopWidth,s.borderRightWidth,s.borderBottomWidth,s.borderLeftWidth].join(',')+'; box='+r.width+'x'+r.height};
for(const [mode,direction] of [['horizontal-tb','ltr'],['horizontal-tb','rtl'],['vertical-rl','ltr'],['vertical-lr','rtl']])console.log(mode+'/'+direction+'='+measure(make(mode,direction)));
const reset=make('horizontal-tb','ltr');reset.style.borderBlock='6px';console.log('omitted-style='+getComputedStyle(reset).borderBlockEndStyle+'; '+measure(reset));

Result

horizontal-tb/ltr=4px,2px,4px,2px; box=84x48
horizontal-tb/rtl=4px,2px,4px,2px; box=84x48
vertical-rl/ltr=2px,4px,2px,4px; box=88x44
vertical-lr/rtl=2px,4px,2px,4px; box=88x44
omitted-style=none; 0px,2px,0px,2px; box=84x40

Executed in Chromium 157.0.8103.51 with real computed styles and bounding rectangles. The measurements use content-box, empty boxes and device scale 1; they do not verify collapsed tables, fragmentation, border images or other browser engines.

Sources