CKTIS / CSS
box-sizing — how box dimensions are calculated
The box-sizing property determines whether a specified dimension covers only the content or also includes padding and borders. It makes box dimensions predictable without including margins.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
box-sizing: content-box | border-box;box-sizing determines which box edge dimensions expressed as lengths or percentages refer to. Its initial value is content-box, and it is not inherited. It applies to elements that accept width or height.
With content-box, specified width and height describe the content area; padding and borders enlarge the box. With border-box, they include padding and borders, leaving less room for content. Margins are excluded in both cases.
This rule also covers minimum and maximum dimensions and flex-basis. Non-quantitative values such as auto and min-content generally do not change meaning because of box-sizing. The content size cannot fall below zero: if padding and borders alone exceed the specified dimension, the box will be larger than that dimension. Therefore, border-box does not guarantee freedom from overflow.
In the example, both elements have width: 200px, padding: 10px, and a 10px border on every side. Their widths including borders are 240px and 200px, respectively. The current definition in CSS Box Sizing Module Level 3 supersedes the earlier definition in CSS UI Level 3.
Examples
<!doctype html>
<meta charset="utf-8">
<title>box-sizing</title>
<style>
.box {
width: 200px;
height: 60px;
padding: 10px;
border: 10px solid black;
margin: 0;
}
#content { box-sizing: content-box; }
#border { box-sizing: border-box; }
</style>
<div id="content" class="box">content-box</div>
<div id="border" class="box">border-box</div>Result
content-box: content 200 × 60 CSS px; border box 240 × 100 CSS px. border-box: content 160 × 20 CSS px; border box 200 × 60 CSS px.
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.