Width and height, online

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

Width and height in one minute

What students need to know

min-height: 50vh means the section is always at least half the viewport tall. It can grow taller with content but never shorter. width: 100% makes the paragraph as wide as its parent element. On a 600px parent, it becomes 600px.

max-width: 100% sets an upper limit. The image can be its natural size or smaller but never wider than the container. CSS property names are case-sensitive and must be lowercase. 'Width' is invalid — use 'width'.

Mistakes students make

  • CSS declarations require a colon. It should be width: 200px; not width 200px;.
  • CSS declarations require a colon. It should be height: 150px; not height 150px;.
  • There must be no space between the number and the unit. It should be width: 50%; not width: 50 %;.
  • There must be no space between the number and the unit. It should be height: 50vh; not height: 50 vh;.
PREVIOUS · MODULE 48Margin
YOU ARE HERE · MODULE 49Width and height
NEXT · MODULE 50box-sizing

Discover other journeys with this module

What students will learn in this module

Every question in Module 49

Quick questions

  1. What does max-width: 100% do on an image?APrevents the image from exceeding its container's widthBStretches the image to always fill its container
  2. Which property sets the minimum vertical size of an element?Amin-widthBmin-height
  3. True or false: width: 50% is relative to the viewport width.AFalseBTrue
  4. True or false: CSS property names like 'Width' with a capital letter are valid.AFalseBTrue
  5. What does min-width: 200px do?ASets the element's width to exactly 200pxBPrevents the element from being narrower than 200px

Key terms

Students type the meaning of:

  • max-width

Match the pairs

div {
  width: 800px;
  max-width: 100%;
}
Match it to what it does
img { max-width: 100%; }Match it to what it does
min-height prevents an element from being shorter than the specified valueMatch it to what it does
% widths are relative to the parent element's width, not the viewportMatch it to what it does
p { widht: 200px; }Match it to what it does
div { Width: 300px; }Match it to what it does

Fill in the blanks

  1. div { _____: 300px; }

    Hint: Type the CSS property name that sets the horizontal size of an element

  2. div { ______: 200px; }

    Hint: Type the CSS property name that sets the vertical size of an element

  3. img { _________: 100%; }

    Hint: Type the CSS property name that sets the largest size an element is allowed to reach

  4. section { __________: 50vh; }

    Hint: Type the CSS property name that sets the smallest vertical size an element must be

  5. p { _________: 200px; }

    Hint: Type the CSS property name that sets the smallest horizontal size an element must be

Spot the error

Question 1

Ap { width 200px; }Bh1 { height: 100px; }Cdiv { width: 50%; }

Question 2

Adiv { width: 300px; }Bimg { height 150px; }Cp { max-width: 600px; }

Question 3

Adiv { max-width: 800px; }Bp { width: 100%; }Cimg { width: 50 %; }

Question 4

Adiv { width: 400px; }Bp { min-height: 100px; }Cimg { max-width: 100%; }Dsection { height: 50 vh; }

Question 5

Ap { width: 100%; }Bdiv { height: 200px; }Cimg { max-width: 100%; }Dsection { min-height: 50vh; }Ea { width: 120 px; }