Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 3.2 — Relative Units
CSS · Example 4 of 4

Readable lines with ch

Change the font-size of .measure to 1.5rem: the box gets wider too, because ch grows with the font.

Relative units measure against something else: em against the font size, rem against the root font size, % against a property-specific reference, and ch/ex against the font's own letters; choosing the right reference makes designs scale with the reader.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 5 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Write a type scale in rem for h1 (40px), h2 (28px), p (16px) and .caption (13px) at the default root size.

02

Make an .icon span sit next to text and always be the same height as that text, whatever the text size.

03

Make a paragraph never wider than 60 characters and center it on the page.

Explain it without notes

01

Explain the difference between em and rem, including what em refers to on font-size versus on padding.

02

Why are rem font sizes better for accessibility than px font sizes?

03

What does a percentage refer to for width, height, padding-top and font-size?

04

When would you choose em over rem on purpose?

Readable lines with ch

Preview

Press Run to see the page.

Console

Nothing logged yet.