What is the CSS box model?
Short answer
In CSS, every element is a rectangular box with four layers: the content, the padding around it, the border around that, and the margin outside. The box model defines how those layers add up to the element's total size.
The four layers
content— the text or image itself, sized by width and heightpadding— space inside the box, between content and borderborder— the line around the paddingmargin— space outside the box, separating it from neighbors
[ margin [ border [ padding [ content ] ] ] ]Why box-sizing matters
By default (content-box), width sets only the content, so padding and border are added on top and make the box wider than you asked. Setting box-sizing: border-box includes padding and border within the width, which is far more predictable for layouts.
* { box-sizing: border-box; }