The Four Layers
Every element has content (the text or child elements), padding (transparent space inside the border), border (a visible edge), and margin (transparent space outside the border). Understanding these layers is essential for CSS layout.
Content-Box vs Border-Box
The default content-box model means width and height apply only to the content area. Border-box includes padding and border in the declared width and height, which is generally more intuitive for layout work.
Margin Collapse
Adjacent vertical margins of block-level elements collapse: only the larger margin applies. This behavior surprises many developers. Padding, border, inline elements, and flexbox containers prevent collapsing.
Box Model in Flexbox and Grid
In flexbox and grid layouts, the box model still applies to each item. The flex or grid container controls item placement while each item's box model determines its internal dimensions and spacing.





