Margin, online

Six activities your students do on their own devices. See who's finished, and their scores.

Margin in one minute

What students need to know

margin: 20px adds 20px of space outside the paragraph's border on all four sides, pushing surrounding elements away. margin-top and margin-bottom set only their respective sides. The left and right margins remain at their default value.

auto splits the remaining horizontal space equally on both sides, centering the element. The element must have a fixed width. The margin shorthand accepts 1, 2, 3 or 4 values. Five values is invalid and will be ignored by the browser.

Mistakes students make

  • CSS declarations require a colon. It should be margin: 10px; not margin 10px;.
  • The margin shorthand accepts 1, 2, 3 or 4 values — not 5. Five values is invalid CSS.
  • CSS declarations require a colon. It should be margin-top: 15px; not margin-top 15px;.
  • 'margin: top 10px' is invalid. To set only the top margin, use margin-top: 10px;.

Discover other journeys with this module

What students will learn in this module

Every question in Module 48

Quick questions

  1. What does margin: 10px 20px; set?A10px top/bottom and 20px left/rightB10px left and 20px top
  2. What does margin: 0 auto; do to a block element with a fixed width?AHorizontally centres the elementBRemoves all margin
  3. True or false: margin adds space inside the element's border.ATrueBFalse
  4. Which property sets only the bottom margin?Amargin-topBmargin-bottom
  5. True or false: margin: 10px 20px 30px 40px 50px is valid CSS.AFalseBTrue

Key terms

Students type the meaning of:

  • margin

Match the pairs

p { margin: 10px 20px; }Match it to what it does
div {
  width: 800px;
  margin: 0 auto;
}
Match it to what it does
Margin adds space outside the border — it separates elements from each otherMatch it to what it does
Individual side properties let you set margin on one side without affecting othersMatch it to what it does
p { margin 10px; }Match it to what it does
div { margin: 10px, 20px; }Match it to what it does

Fill in the blanks

  1. p { ______: 10px; }

    Hint: Type the CSS property name that sets space outside an element's border

  2. div { __________: 20px; }

    Hint: Type the CSS longhand property name that sets only the top outside spacing

  3. div { margin: 0 ____; }

    Hint: Type the CSS value that lets the browser split the remaining space equally to centre an element

  4. a { ___________: 12px; }

    Hint: Type the CSS longhand property name that sets only the left outside spacing

  5. p { margin: 10px ____; }

    Hint: Type the CSS value that sets the left and right margin to 20 pixels

Spot the error

Question 1

Ap { margin 10px; }Bh1 { margin: 20px; }Cdiv { margin: 0 auto; }

Question 2

Ap { margin: 10px; }Bdiv { margin: 10px 20px 30px 40px 50px; }Ch1 { margin: 0; }

Question 3

Ap { margin: 10px; }Bh1 { margin: 0 auto; }Cdiv { margin-top 15px; }

Question 4

Ap { margin: 0; }Bdiv { margin: 0 auto; }Ch2 { margin: 10px 0; }Da { margin: top 10px; }

Question 5

Ap { margin: 10px; }Bh1 { margin: 20px 0; }Cdiv { margin: 5px 10px 15px; }Dspan { margin: 8px; }Ea { margin-left 12px; }