The box model

Knowledge Videos

Short animated explainers, organised by subject.

The box model

Every element is a box with four layers: content, padding, border and margin. How each one is set with CSS, and what changes when you change a number.

Try it

Transcript

Every element on a page is a box. A box has four layers, from the inside out: content, padding, border and margin.

The content is the text or picture itself. The padding is empty space inside the box, between the content and the border.

The border is the line around the box. The margin is empty space outside the border, and it pushes other boxes away.

You set each layer with C S S. Padding twenty pixels, border four pixels, margin thirty pixels. Change a number, and the box changes.

Remember: every element is a box with content, padding, border and margin. Padding is inside, margin is outside.

More in this series