Module 2 · The Box Model · Lesson 4 of 4

CSS Sizing & Units

Beginner ⏱ 20 min2 sections · 1 exercise · 4-question quiz

px, %, em, rem, vw, vh — units are the vocabulary of size. Choosing the right one is the difference between a layout that adapts and one that breaks the moment someone zooms.

1. Absolute vs relative

UnitRelative toBest for
pxNothing (fixed)Borders, shadows, fine detail
%The parent's sizeFluid widths
emThe element's own font sizePadding that scales with text
remThe root font sizeType scale, consistent spacing
vw / vh1% of viewport width/heightFull-screen sections, hero type

The modern default: rem for font sizes and spacing (respects the user's browser settings), % or Flexbox/Grid for fluid widths, px only where optical precision matters.

2. min, max, and clamp

CSS — fluid but bounded
content {
  width: 90%;
  max-width: 720px;      /* never wider  */
  min-height: 60vh;      /* never shorter */
}
h1 {
  font-size: clamp(28px, 5vw, 56px);  /* fluid type with limits */
}

max-width is the single most useful responsive property: fluid below the cap, capped above it. clamp(min, preferred, max) does the same for anything in one line — the headline above scales with the viewport but never leaves its bounds.

3. Try it yourself

Make the article fluid-but-readable: width: 90% with max-width: 560px, centered with auto margins, and give the heading a fluid clamp(24px, 6vw, 48px) size. Resize the preview pane!

exercise.html — editable

4. Quiz — check your understanding

CSS Sizing & Units Quiz

4 questions · pass at 60%

Q1. 1rem is relative to…

rem = root em. It usually defaults to 16px but follows the user's browser setting.

Q2. Which guarantees an element is fluid but never exceeds 720px?

max-width caps the size while allowing anything smaller.

Q3. 50vw equals…

vw units are percentages of the viewport width — 50vw is half the window.

Q4. clamp(1rem, 2.5vw, 2rem) returns…

clamp is min/preferred/max — fluid in the middle, bounded at both ends.
🏆
Quiz passed? You're one step closer to your certificate.

Every lesson quiz you pass (60%+) is saved in your browser and counts toward the CSSmatic Certificate of Completion.

Track my progress →