Description & Usage

The box-sizing property controls the sizing calculation algorithm used for CSS boxes.

Under content-box (the browser default), width applies only to content. Adding 20px padding and a 2px border to a width: 200px box results in a rendered width of 244px, causing unexpected horizontal scrollbars or broken grid columns.

Applying box-sizing: border-box forces width and height to include content, padding, and border, keeping final element dimensions fixed and predictable.

Property Specifications

Property FeatureSpecification
CategoryBox Model
Initial Valuecontent-box
InheritedNo (not inherited)
Applies ToAll elements that accept width or height
Box Model Explorer
box-sizing:
margin: 20px
border: 4px
padding: 20px
Content (180px × 90px)
Rendered Element Size:180px × 90px
Fixed total width of 180px (Content auto-shrinks inside border)

Syntax

box-sizing: content-box | border-box;

Property Values

ValueDescription
content-boxDefault. Width and height apply only to content. Padding and border add to final rendered width.
border-boxRecommended. Width and height include content, padding, and border. Prevents layout overflow.

Code Examples

Global Box-Sizing Reset
*, *::before, *::after { box-sizing: border-box; }
Ensures predictable box sizing calculations across entire stylesheet.