layout

box-sizing

Controls whether an element's declared width and height include padding and border. border-box is the modern default most stylesheets set globally.

box-sizing: content-box | border-box

Common values

Value Effect
content-box Default; width/height apply only to the content
border-box Width/height include padding and border

Examples

*, *::before, *::after { box-sizing: border-box; }

Common reset making every box predictable

.card { width: 100%; padding: 1rem; box-sizing: border-box; }

Card stays 100% wide even with padding

.legacy { box-sizing: content-box; }

Opt back into old behavior for a specific component

Gotcha

border-box does not include margin; margin still adds to the outside footprint.

Related properties

← All CSS properties · CSS selectors · Grid vs Flexbox