The CSS Box Model
In CSS, literally everything is a rectangular box. Learn how Content, Padding, Border, and Margin fit together, and why box-sizing: border-box is the single most important reset in web development.
The Framed Painting Analogy
Think of every HTML element as an art piece hanging on a gallery wall:
The Painting Canvas. Your text, image, or video lives here. Dimensions controlled by width and height.
The Cardboard Mat. Breathing room inside the frame. Still colored by your element's background-color!
The Wooden Picture Frame. Wraps right around the padding edge with color, thickness, and style.
The Empty Wall Space. Invisible buffer pushing other paintings away. Never shows the background color!
`box-sizing: border-box` vs `content-box`
Toggle between the two box sizing models below. Notice how in content-box, adding padding makes your element expand and break responsive grids!
width set to: 200pxWhy 20px + 30px = 30px (Not 50px!)
When two vertical block elements touch each other, their top and bottom margins collapse into a single margin equal to the larger of the two values.
Interactive Box Studio
Advanced Box Model Studio
Inspect box-sizing math (content-box vs border-box), test outline-offset, and experiment with vertical margin collapsing.
7. Display Modes
block, inline, inline-block, none, and modern flow-root formatting contexts.