Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

border-block-start-width: measure a logical edge inside the box model

Control the first block edge’s thickness and account for whether it increases or consumes the box size.

Version: CSS Modules

Syntax

border-block-start-width: <line-width>; /* nonnegative length | thin | medium | thick */

border-block-start-width sets only the starting block border’s thickness. The edge is top in horizontal-tb, right in vertical-rl and left in vertical-lr. Valid values are nonnegative lengths and the browser-defined thin, medium and thick keywords; percentages are invalid. A visible style is required, because none and hidden make the computed width zero.

An em length uses the element’s font size. A .5em border is 10px when font-size is 20px, then becomes 5px when that font size changes to 10px. The thickness is independent of whether text is horizontal or vertical. writing-mode determines the edge, whereas box-sizing determines how its thickness participates in the specified width and height.

The example starts with width 100px, height 40px, no padding and a .5em solid start border at font-size 20px. With content-box, the outer size is 100×50 and the client area is 100×40. With border-box, the outer size stays 100×40 and the client area becomes 100×30: the 10px top border is now inside the specified height.

Switching to vertical-rl while retaining border-box moves the 10px edge to the right. The outer size remains 100×40, but the client area becomes 90×40. Reducing font-size to 10px reduces the border to 5px and increases that area to 95×40. These readings make it easier to diagnose why adding a border either grows a component or shrinks its inner area; they assume no padding or scrollbars, as in this example.

Examples

const box=document.createElement('div');
box.style.cssText='width:100px;height:40px;padding:0;font-size:20px;border:0 solid;box-sizing:content-box;border-block-start-width:.5em';
document.body.append(box);
const read=()=>{const s=getComputedStyle(box),r=box.getBoundingClientRect();return [s.borderBlockStartWidth,r.width,r.height,box.clientWidth,box.clientHeight].join(',')};
const content=read();box.style.boxSizing='border-box';const borderBox=read();
box.style.writingMode='vertical-rl';const vertical=read();box.style.fontSize='10px';const smaller=read();
console.log('contentBox='+content+'; borderBox='+borderBox+'; vertical='+vertical+'; smallerFont='+smaller+'; percent='+CSS.supports('border-block-start-width','5%'));

Result

contentBox=10px,100,50,100,40; borderBox=10px,100,40,100,30; vertical=10px,100,40,90,40; smallerFont=5px,100,40,95,40; percent=false

Executed in Chromium 157.0.8103.51 with bounding rectangles and client dimensions. General layouts must also account for padding, scrollbars and minimum sizes.

Sources