edubun
English
1 / 10

5 / 9 · Basic

Typography

WCAG suggests lines no longer than 80 characters and line spacing of at least 1.5 inside paragraphs. Two CSS properties handle both.

Jump to the 10 practice questions

You will learn

  • Write a font stack that ends in a generic family
  • Set size, weight and a unitless line height
  • Keep lines readable and finish with text-transform and letter-spacing

Before this: The box model

1Explore

Choosing fonts

font-family takes a list of fonts separated by commas. The browser uses the first one that is available on the reader's device and moves down the list if it is missing. Always end the list with a generic family, serif, sans-serif, monospace or system-ui, so that something sensible appears no matter what is installed. Font names that contain spaces go in quotes, as in "Noto Sans KR".

A font that is not on the device is skipped. The generic family at the end of the list is the safety net.

Tap a choice: the code and the preview change together.

font-family
<p style="font-family: Georgia, serif; font-size: 20px">Soda bread needs no yeast.</p>
Preview

2Problem

Why end with a generic family

Why end a font-family list with a generic family?

Hint

What happens when no listed font is installed?

Solution

Answer: So a suitable font appears even if none of the named ones is installed

The browser tries fonts in order, and a generic family supplies a fallback when the specifically named fonts are unavailable.

3Explore

Size, weight and line height

line-height sets the distance between lines. Give it a plain number with no unit, such as 1.6: it then means 1.6 times the font size of each element, so headings and small print each get spacing that fits them. A value with a unit, such as 24px, is calculated once and inherited as a fixed length, which is too tight for large headings.

Change the weight and the line height and compare how easy the lines are to follow.

Tap a choice: the code and the preview change together.

font-weight
line-height
<p style="font-size: 18px; font-weight: 400; line-height: 1.6; max-width: 30ch">Soda bread needs no yeast and no waiting. Mix, shape, cut a cross and bake.</p>
Preview

4Problem

bold as a number

What does font-weight: bold equal?

Hint

Normal is 400.

Solution

Answer: 700

bold is the keyword for font weight 700. That value sets the thickness of the letters.

5Problem

Height of a line

font-size is 20px and line-height is 1.5. How tall is each line?

px

Hint

Multiply the font size by the line height.

Solution

Answer: 30 px

A unitless line-height multiplies the element’s font size, so the line height is 1.5 times 20 = 30 pixels.

6Explain

Line length and alignment

Very long lines are tiring: the eye loses its place when it jumps back to the start of the next line. WCAG 1.4.8 suggests no more than 80 characters per line (40 for Chinese, Japanese and Korean). The easy way to enforce this is max-width in ch units on paragraphs, for example max-width: 65ch. text-align sets alignment: left (or start) is easiest to read for long text in left-to-right languages, center suits short headings, and justify can open up uneven gaps between words.

Your code
<p style="max-width: 40ch">This paragraph stops at about 40 characters per line, so the eye finds the start of the next line easily.</p>
<p>This one runs as wide as its box allows, which is fine in a narrow preview and tiring on a wide screen.</p>
Preview

7Problem

letter-spacing in em

text-transform: uppercase shows text in capitals without changing the HTML, so the source keeps its normal spelling and the style can be changed later in one place. MDN notes that long runs of capitals are harder to read for some people, including people with dyslexia, so keep it for short labels, and add a little letter-spacing, such as 0.08em.

font-size is 16px. How much is letter-spacing: 0.1em?

px

Hint

em multiplies the font size.

Solution

Answer: 1.6 px

em uses the element’s font size here, so multiply that size by the spacing factor: 0.1 times 16 = 1.6.

8Practice

A recipe card in type

Set body to font-family: Georgia, serif and line-height: 1.6. Make the h1 2.5rem (browsers already draw it at 2em, so the default does not count). Make .label uppercase with letter-spacing: 0.1em.

Checks
  • font stack on body
  • line-height 1.6 inherited
  • h1 2.5rem
  • uppercase label
  • letter-spacing 0.1em
Your code
<style>
  /* write your rules here */
</style>

<h1>Weekend Baking</h1>
<p class="label">Recipe of the week</p>
<p>Soda bread needs no yeast and no waiting. Mix flour, baking soda, salt and buttermilk, shape a round, cut a deep cross on top and bake it for about 40 minutes.</p>
Preview
Hint

Three rules: body, h1 and .label. line-height takes a plain number.

A solution
<style>
  body { font-family: Georgia, serif; line-height: 1.6; }
  h1 { font-size: 2.5rem; }
  .label { text-transform: uppercase; letter-spacing: 0.1em; }
</style>

<h1>Weekend Baking</h1>
<p class="label">Recipe of the week</p>
<p>Soda bread needs no yeast and no waiting. Mix flour, baking soda, salt and buttermilk, shape a round, cut a deep cross on top and bake it for about 40 minutes.</p>

9Explain

Common mistakes

Mistake
<style>
  body { line-height: 20px; }
</style>
<h1>Weekend baking at the Corner Bakery</h1>
<p>Soda bread needs no yeast.</p>
Fixed
<style>
  body { line-height: 1.4; }
</style>
<h1>Weekend baking at the Corner Bakery</h1>
<p>Soda bread needs no yeast.</p>

A line height in px is passed down as that length, so the big heading gets 20px lines and its lines overlap. A plain number scales with each font size.

10

Summary

  • font-family is a fallback list ending in a generic family.
  • Unitless line-height around 1.5 for body text; tighter for big headings.
  • Limit line length with max-width in ch; uppercase needs a little letter-spacing.

Next unitFlexbox
Full text · The whole lesson as one text

Choosing fonts

font-family takes a list of fonts separated by commas. The browser uses the first one that is available on the reader's device and moves down the list if it is missing. Always end the list with a generic family, serif, sans-serif, monospace or system-ui, so that something sensible appears no matter what is installed. Font names that contain spaces go in quotes, as in "Noto Sans KR". system-ui uses the interface font of the operating system, which is well designed, already on the device, and covers many writing systems.

body {
  font-family: system-ui, sans-serif;
  font-size: 1rem;          /* 16px unless the reader changed it */
  line-height: 1.6;         /* unitless: 1.6 times the font size */
  color: #222;
}
h1 { font-size: 2rem; font-weight: 700; line-height: 1.2; }
p  { max-width: 65ch; }     /* keeps lines a readable length */
.label { text-transform: uppercase; letter-spacing: 0.08em; }
A small but complete set of text styles.

You can also load a font file from your own server with an @font-face rule, or from a font service. Web fonts give a page its own character, but each one is a download that delays the text, and Korean, Chinese and Japanese fonts can run to several megabytes because they hold thousands of glyphs. Load as few weights as you need, and keep a good fallback in the list.

Size, weight and line height

font-size sets the size; as the colour and units unit explained, rem keeps text in step with the reader's settings. font-weight accepts numbers from 1 to 1000. Common examples are 100 for thin, 400 for normal, 700 for bold, and 900 for very heavy text. The keywords normal and bold mean 400 and 700. A font only has the weights its designer made, so asking for 300 in a font that has only 400 and 700 gives you the nearest one.

line-height sets the distance between lines. Give it a plain number with no unit, such as 1.6: it then means 1.6 times the font size of each element, so headings and small print each get spacing that fits them. A value with a unit, such as 24px, is calculated once and inherited as a fixed length, which is too tight for large headings. Body text usually reads well between 1.4 and 1.7; WCAG success criterion 1.4.8 suggests at least 1.5 within paragraphs. Large headings look better tighter, around 1.1 to 1.3.

Line length and alignment

Very long lines are tiring: the eye loses its place when it jumps back to the start of the next line. WCAG 1.4.8 suggests no more than 80 characters per line (40 for Chinese, Japanese and Korean). The easy way to enforce this is max-width in ch units on paragraphs, for example max-width: 65ch. text-align sets alignment: left (or start) is easiest to read for long text in left-to-right languages, center suits short headings, and justify can open up uneven gaps between words.

Small finishing touches

text-transform: uppercase shows text in capitals without changing the HTML, so the source keeps its normal spelling and the style can be changed later in one place. MDN notes that long runs of capitals are harder to read for some people, including people with dyslexia, so keep it for short labels, and add a little letter-spacing, such as 0.08em. text-decoration draws lines: underline, line-through, or none to remove a link's underline (keep some other sign that it is a link). Readers who need more space may override your spacing. WCAG 1.4.12 asks that pages still work when line height is 1.5, letter spacing 0.12em, word spacing 0.16em and paragraph spacing 2em. So avoid boxes with fixed heights that would cut off text.

Key points
  • font-family is a fallback list ending in a generic family.
  • Unitless line-height around 1.5 for body text; tighter for big headings.
  • Limit line length with max-width in ch; uppercase needs a little letter-spacing.

Practice questions from Typography on edubun

Embed this quiz

Free to embed. Please keep the credit line.

Sources for this course (5)
  • W3C CSS Working Group specifications: CSS Snapshot 2025, Selectors Level 4, CSS Cascading and Inheritance Level 5, CSS Color Level 4, CSS Values and Units Level 4, CSS Box Model Level 3, CSS Box Sizing Level 3, CSS Fonts Level 4, CSS Flexible Box Layout Level 1, CSS Grid Layout Level 2, Media Queries Level 4 and Level 5 (w3.org/TR/, checked 2026-10-17)
  • MDN Web Docs, Learn web development: CSS styling basics and CSS layout, and the CSS reference (developer.mozilla.org/en-US/docs/Learn_web_development/Core/Styling_basics, .../Core/CSS_layout, developer.mozilla.org/en-US/docs/Web/CSS, checked 2026-10-17)
  • W3C, CSS history and CSS1 Recommendation of 17 December 1996 (w3.org/Style/CSS20/history.html, w3.org/press-releases/1996/css1-rec, checked 2026-10-17)
  • W3C WCAG 2.2, success criteria 1.4.3 Contrast (Minimum)
  • 1.4.8 Visual Presentation, 1.4.10 Reflow, 1.4.12 Text Spacing (w3.org/TR/WCAG22/, checked 2026-10-17).

Checked: 2026-10-17