Lesson 2 · Web Explorer
Padding, margins and boxes.
Here's the idea that makes CSS layout click: every single element on a page is a rectangle. Headings, paragraphs, images, buttons — all boxes, even when they don't look like it.
Each box has four layers, from the inside out:
This is called the box model, and once you see it you can't unsee it.
These two get confused constantly, so here's the way to keep them straight:
A coloured box with padding shows the colour in the padded area — it's part of the box. Margin is always invisible, because it's outside the box entirely.
Inside is padding. Between is margin.
6 more parts in this lesson
Walkthroughs, code labs, mini-games and the checkpoint quiz unlock when you buy the course.