← Back to HTML & CSS, page 10

html-css-0187 · Easy fresher

How do line-height, letter-spacing and line length affect readable text, and how does line-height inherit?

Use a line height of about 1.5, a line length of about 65 characters with the ch unit, relative font sizes and small letter spacing only for labels. A unitless line-height is inherited as a number, while lengths and percentages are inherited as calculated lengths.

Full answer

Good body text needs enough space between lines, a sensible line length and a comfortable size.

  • line-height is the height of each line box. A value from about 1.4 to 1.6 works well for body text. Long lines and small text need more space, headings need less (for example 1.1 to 1.3).
  • letter-spacing adds space between letters. Use small values in em, so the spacing scales with the font size. A little extra space helps small upper-case labels. Do not add spacing to body text, and never use it on joined scripts such as Arabic, where it breaks the letter connections.
  • Line length, also called measure: about 45 to 75 characters per line reads well. Use max-width in ch units, for example max-width: 65ch, so the width follows the font.
  • Font size: use relative units such as rem, so users can change the size in the browser. At least 16 pixels for body text is a common base.
  • Contrast and alignment: left-aligned text is easier to read than justified text with no hyphenation, and very long paragraphs need breaks.

The important detail is how line-height inherits:

  • A unitless number, such as 1.5, is inherited as the number. Every child multiplies it by its own font size. This is the best choice.
  • A length, such as 30px, or a percentage, such as 150%, or em, is calculated once on the parent, and children inherit the final length. A small child text then gets the same large line height, which can cause uneven spacing.

WCAG text spacing rules also ask that content keeps working when users set a line height of 1.5 and extra letter and word spacing, so avoid fixed heights on text boxes.

The small text under the unitless value gets 15 pixels, which is 1.5 times its own size. Under the fixed length and the percentage, it keeps 30 pixels, which is too large for the small text. The label has 1 pixel of letter spacing at 20 pixels.

Test the text in real languages and sizes, and with the user's own zoom settings.

html
<style>
  .u, .x, .y { font-size: 20px; }
  .u { line-height: 1.5; }
  .x { line-height: 30px; }
  .y { line-height: 150%; }
  .u small, .x small, .y small { font-size: 10px; }
  .label { font-size: 20px; letter-spacing: 0.05em; text-transform: uppercase; }
  .text { max-width: 65ch; }
</style>
<p class="u">Big <small id="su">small</small></p>
<p class="x">Big <small id="sx">small</small></p>
<p class="y">Big <small id="sy">small</small></p>
<span class="label" id="l">Label</span>
<p class="text" id="t">Readable width.</p>

Run in Chrome 156 (headless) as a page; the snippet is wrapped in a minimal HTML document with doctype, charset and viewport meta tag. Two full runs gave identical results, and the measured values in the answer come from them.

Key points

  • Body text: line-height about 1.4 to 1.6.
  • Use a unitless line-height so children scale it.
  • Limit line length to about 45 to 75 characters (ch units).
  • Use letter-spacing in em, and only where needed.
  • Avoid fixed heights on text boxes.

Common mistakes

  • Using px or % line-height on a parent and getting tall lines in small children.
  • Adding letter-spacing to body text or to Arabic text.
  • Using very long lines with no max-width.

Follow-ups

  • Why is a unitless line-height better?
  • Why avoid letter-spacing in Arabic?

Tips

  • Explain the unitless line-height rule with the three examples.
  • Give numbers: 1.4 to 1.6 for body, 45 to 75 characters per line.