CSSCSS · Lesson 3 of 9
The Box Model
Every HTML element is a box. This sounds obvious until you try to center something, and then it sounds like a conspiracy.
The CSS box model defines how the browser calculates the size and spacing of every element. From inside out: content → padding → border → margin. Understanding this model is the key to understanding layout.
⚠ Warning
Add box-sizing: border-box to every project, globally. Without it, a box with width: 300px and padding: 20px will actually be 340px wide — a constant source of confusion. The * { box-sizing: border-box; } rule is a near-universal best practice.
Add box-sizing: border-box to every project, globally. Without it, a box with width: 300px and padding: 20px will actually be 340px wide — a constant source of confusion. The * { box-sizing: border-box; } rule is a near-universal best practice.