×

css · level 1 · unit 5 · lesson 4

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

adds space outside the box.

A margin is space outside the border. It pushes the box away from its neighbours. The background does not fill it, so a margin always looks empty.

Padding is room inside the box, margin is room outside it. Think of a picture on a wall: padding is the card round the picture, inside the frame, and margin is the wall round the frame.

Browsers add some margins of their own. Paragraphs and headings get some above and below, and body gets 8px all round. margin: 0 takes them away.

<div class="card">First card</div>
<div class="card">Second card</div>
.card {
  background-color: lavender;
  padding: 16px;
  margin: 24px;
}

Press show my page to see it here.

Change margin to 0 and watch the two cards touch.