Box model playground
Slide padding, border and margin and watch a box and its total width change.
Every element is a box with four layers, from the inside out: content, padding, border and margin. Padding is space inside the border, and margin is space outside it.
Each layer adds its size on both sides of the content, so the box takes up the content width plus twice the padding, the border and the margin.
Things to try
- Set the padding to 0 and then to 60. Which colour area grows?
- Raise the margin. Does the border box itself get bigger?
- Set the border to 20. What happens to the total width?
- Can you make a box that is exactly 300 px wide in total?