box-sizing: content-box, the default, means width and height apply only to the content area, with padding and border added on top, expanding the element's total rendered size beyond the specified dimensions. box-sizing: border-box instead makes width and height represent the element's complete final size, including padding and border, automatically shrinking the content area to accommodate them rather than growing the total box — this is widely considered the more intuitive, predictable model, which is exactly why applying a universal box-sizing: border-box rule near the top of a stylesheet is one of the most common, near-universal CSS reset conventions in modern web development.
1Understanding Box-sizing
box-sizing: content-box, the default, means width and height apply only to the content area, with padding and border added on top, expanding the element's total rendered size beyond the specified dimensions. box-sizing: border-box instead makes width and height represent the element's complete final size, including padding and border, automatically shrinking the content area to accommodate them rather than growing the total box — this is widely considered the more intuitive, predictable model, which is exactly why applying a universal box-sizing: border-box rule near the top of a stylesheet is one of the most common, near-universal CSS reset conventions in modern web development.
Apply box-sizing: border-box on the universal selector as one of the first rules in nearly any project's stylesheet — it makes width/height calculations far more predictable, since padding and border no longer silently expand an element beyond its specified dimensions.
* {
box-sizing: border-box;
}
.box {
width: 200px;
padding: 20px;
border: 5px solid black;
}2Practical Example
Here is a real-world application of Box-sizing showing how it is used in production CSS code.
.box {
width: 200px;
padding: 20px;
border: 5px solid black;
box-sizing: content-box;
}3Best Practices
Follow these guidelines when working with Box-sizing:
1. Apply box-sizing: border-box globally via the universal selector near the top of a stylesheet, as one of the most common, widely-adopted CSS reset conventions
2. Remember that under border-box, adding padding or border shrinks the available content area rather than growing the element's total size
3. Be aware some third-party components or older code might assume content-box's default behavior, so test carefully when introducing a global border-box reset into an existing, previously content-box-based codebase
Tip: Apply box-sizing: border-box on the universal selector as one of the first rules in nearly any project's stylesheet — it makes width/height calculations far more predictable, since padding and border no longer silently expand an element beyond its specified dimensions.
* {
box-sizing: border-box;
}
.box {
width: 200px;
padding: 20px;
border: 5px solid black;
}