Every Element Is a Box
The browser draws every element as a rectangular box with four layers. From inside to outside:
| Layer | Property | Meaning |
|---|---|---|
| Content | width, height | Text, image or children |
| Padding | padding | Space inside the border, around the content |
| Border | border | A line around the padding |
| Margin | margin | Space outside the border, between boxes |
box-sizing: The Most Useful Reset
By default width sets only the content width. Padding and border are added on top. That makes sizes hard to predict.
content-box total width: 350 border-box total width: 300
With border-box, the 300px includes padding and border. Most developers start every stylesheet with:
Rounded Corners and Shadows
box-shadow values are: x offset, y offset, blur, optional spread, then color. Add inset for an inner shadow. Unlike a border, a shadow and an outline do not change the box size.
Margin Collapse
When the vertical margins of two blocks touch, they do not add. The larger one wins.
gap between the two boxes: 30
Centering and Auto Margins
A block with a set width and margin-inline: auto is centered horizontally.
Overflow
| Value | Result |
|---|---|
visible | Content spills out (default) |
hidden | Extra content is cut |
auto | Scrollbars only when needed |
scroll | Always show scrollbars |
Practice
- Make a card with padding, border, radius and a soft shadow
- Compare
content-boxandborder-boxwith a 300px width - Center a page container using max-width and auto margins
Conclusion
Content, padding, border and margin make every box. Use border-box so widths stay predictable, and remember vertical margins can collapse.

