CSS units, online

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

CSS units in one minute

What students need to know

If the paragraph's font size is 16px, padding: 1.5em = 24px. If the font size changes, the padding scales too. 2px is always 2 pixels. Unlike em or rem, px does not scale with the font size or viewport size.

em multiplies by the current font size. 2em on 20px = 2 × 20px = 40px. It is relative to the element's own font size. vh (viewport height) is relative to the browser window. 100vh = the full visible height of the viewport.

Mistakes students make

  • A number without a unit is invalid CSS (except for 0). It should be font-size: 16px; with the px unit.
  • There must be no space between the number and the unit. It should be font-size: 2em; not font-size: 2 em;.
  • Decimal numbers in CSS use a dot, not a comma. It should be font-size: 1.5rem; not 1,5rem;.
  • The declaration is missing its closing semicolon. It should be width: 50vw; with a semicolon.

Discover other journeys with this module

What students will learn in this module

Every question in Module 44

Quick questions

  1. Which CSS unit is absolute (does not scale with context)?AremBpx
  2. What is 2em on an element with a font size of 20px?A32pxB40px
  3. True or false: rem is affected by the parent element's font size.AFalseBTrue
  4. What does 100vh represent?A100% of the viewport heightB100 pixels
  5. True or false: CSS unit abbreviations must be attached to the number with no space.ATrueBFalse

Key terms

Students type the meaning of:

  • rem

Match the pairs

h1 { font-size: 2rem; }Match it to what it does
section { height: 100vh; }Match it to what it does
em multiplies the current element's font size — 1.5em on a 20px element = 30pxMatch it to what it does
px is an absolute unit — the size is fixed regardless of the user's settings or parent elementMatch it to what it does
p { font-size: 16; }Match it to what it does
h1 { font-size: 2 rem; }Match it to what it does

Fill in the blanks

  1. p { font-size: 16__; }

    Hint: Type the absolute CSS unit that represents pixels

  2. p { font-size: 1.5__; }

    Hint: Type the relative CSS unit that scales relative to the current element's font size

  3. h1 { font-size: 2___; }

    Hint: Type the relative CSS unit that scales relative to the root element's font size

  4. div { width: 50__; }

    Hint: Type the CSS unit that represents a percentage of the viewport width

  5. section { height: 100__; }

    Hint: Type the CSS unit that represents a percentage of the viewport height

Spot the error

Question 1

Ap { font-size: 16; }Bh1 { font-size: 2em; }Cdiv { width: 100%; }

Question 2

Ap { font-size: 1em; }Bh1 { font-size: 2 em; }Cdiv { padding: 10px; }

Question 3

Ap { width: 50%; }Bdiv { height: 200px; }Ca { font-size: 1,5rem; }

Question 4

Ap { margin: 10px; }Bdiv { width: 80%; }Ch1 { font-size: 2em; }Dspan { width: 50vw }

Question 5

Abody { font-size: 16px; }Bp { font-size: 1em; }Ch2 { font-size: 1.5rem; }Ddiv { padding: 10px; }Ea { font-size: 12 px; }