Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Fonts and Text Styling  ›  Lesson

Font Size and Weight

Font Size 12 minText sized in rem follows the root font size and the user's settings, em follows the parent and compounds, and font-weight runs from 100 to 900 with 400 normal and 700 bold.

Font Size and Weight

A customer raises the default text size in their browser settings because small print is hard for them to read. On a site sized in rem, every heading and paragraph grows with that setting. On a site that fixes text in pixels, the setting is ignored. Size units are an accessibility decision, not just a matter of taste.

The rule

Size text in rem; weight it with numbers from 100 to 900.

font-size accepts several units:

  • px: a fixed size. Predictable, but it does not grow when the user raises the browser's default text size.
  • rem: relative to the root (html) font size, which is 16px by default and follows the user's setting. 1.5rem is 24px at the default.
  • em: relative to the parent's font size. Useful for things that should scale with their surroundings, but it compounds when nested.
  • %: for font-size, relative to the parent, like em (150% = 1.5em).
body { font-size: 1rem; }        /* 16px by default */
h1   { font-size: 2.5rem; }      /* 40px */
.dish h3 { font-size: 1.25rem; } /* 20px */
.price   { font-size: 0.875rem; }/* 14px */

font-weight takes numbers in steps of 100 from 100 (thin) to 900 (black). normal is 400 and bold is 700. The keywords bolder and lighter step relative to the parent.

A weight only looks right if the font has it. If you load Lora at 400 and 700 only, asking for 600 gives you the nearest available weight, and asking for bold from a font with no bold file makes the browser fake one by smearing the glyphs.

The shortcut

Think in multiples of 16. At the default root, rem × 16 = pixels. For em, multiply by the parent's size, not the root's.

Sizing a nested noteStep 1 of 4
  1. The setup

    .dish has font-size: 1.25rem (20px). Inside it, a small note has font-size: 0.8em.

The em trap: nest three lists each set to 0.8em and the innermost text is 0.8 × 0.8 × 0.8 of the outer size, about half. rem never compounds.

Drills

Answer fast — trust the rule.

quick drill

The root font size is the default 16px. What is 2.5rem in pixels?

quick drill

A parent has font-size: 20px. Its child has font-size: 1.5em. How big is the child's text?

quick drill

Which value is the same as font-weight: bold?

quick drill

Why is rem usually a better choice than px for body text?

Remember

  • rem follows the root (16px by default); em follows the parent.
  • Weights run 100 to 900; normal is 400, bold is 700, if the font has them.
  • em compounds when nested; rem never does.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

Explainrem or em?

A nested list sets each level's text to font-size: 0.85em, and the third level has become tiny. Explain why, calculate its size if the page text is 16px, and suggest a fix.