BeginnerLesson 3 of 126 min read

Typography: Scale, Line Length and Rhythm, Measured on a Real Font

Choose a modular type scale, set a comfortable line length by measuring a real font file, and snap line heights to a baseline grid, with the measurements checked by two independent methods.

In this lesson you will

  • Build a modular type scale
  • Set a comfortable line length
  • Understand why 66ch is not 66 characters
  • Keep vertical rhythm with a baseline grid

About 28 minutes

Ninety percent of a page is text

Most of what Still Water Yoga’s visitors do is read: class descriptions, prices, the cancellation policy. Good typography makes reading effortless, and poor typography makes people leave. Three decisions do most of the work. First, a type scale: a small set of sizes related by a ratio, such as 1.25 (a major third), so that headings, subheadings and body text look related instead of random. Each size is the previous one times the ratio, so with a 16 pixel base the sizes are 16, 20, 25, 31.25 and so on.

Second, line length. Lines that are too short break the reading into jerks, and lines that are too long make it hard to find the start of the next line. A common guideline, from long experience in print and screens, is about 45 to 75 characters per line, with 66 as a good target for single-column text. In CSS the ch unit looks made for this, since it is the width of the digit zero in the current font, but a zero is wider than the average letter, so a max-width of 66ch holds more than 66 average characters. Measuring a real font shows by how much. Third, vertical rhythm: line heights and spacing that are multiples of a base unit, such as 4 or 8 pixels, so that text lines up on an invisible baseline grid. Body text usually needs a line height of 1.4 to 1.6 times the size.

Step Size (px) with base 16 and ratio 1.25 Use
-1 12.8 Small print
0 16 Body
1 20 Lead paragraph
2 25 Heading 3
3 31.25 Heading 2
4 39.06 Heading 1
const base = 16, ratio = 1.25;
const steps = [-1, 0, 1, 2, 3, 4, 5].map(n => ({ n, px: base * Math.pow(ratio, n) }));
steps.forEach(s => console.log('step', String(s.n).padStart(2), '=', s.px.toFixed(3), 'px =', (s.px / 16).toFixed(4), 'rem'));
const snap = (px, unit) => Math.round(px / unit) * unit;
const lines = steps.slice(1, 5).map(s => ({ px: s.px, lh: Math.round(s.px * 1.5 * 100) / 100, snapped: snap(s.px * 1.5, 4) }));
lines.forEach(l => console.log('font', l.px.toFixed(2), 'px -> line-height 1.5 =', l.lh, 'px -> on a 4px grid:', l.snapped, 'px'));
console.log('DATA ' + JSON.stringify({ steps, lines }));
step -1 = 12.800 px = 0.8000 rem
step  0 = 16.000 px = 1.0000 rem
step  1 = 20.000 px = 1.2500 rem
step  2 = 25.000 px = 1.5625 rem
step  3 = 31.250 px = 1.9531 rem
step  4 = 39.063 px = 2.4414 rem
step  5 = 48.828 px = 3.0518 rem
font 16.00 px -> line-height 1.5 = 24 px -> on a 4px grid: 24 px
font 20.00 px -> line-height 1.5 = 30 px -> on a 4px grid: 32 px
font 25.00 px -> line-height 1.5 = 37.5 px -> on a 4px grid: 36 px
font 31.25 px -> line-height 1.5 = 46.88 px -> on a 4px grid: 48 px
from PIL import ImageFont
import json
FONT = "/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf"
SAMPLE = "Gentle classes for every body. Come as you are, bring a mat, and leave feeling calmer than when you arrived."
big = ImageFont.truetype(FONT, 1000)
per_char_em = big.getlength(SAMPLE) / 1000 / len(SAMPLE)
zero_em = big.getlength("0") / 1000
print("average character width:", round(per_char_em, 4), "em | width of the digit 0 (the ch unit):", round(zero_em, 4), "em")
for chars in (45, 66, 75):
    em = chars * per_char_em
    print(chars, "characters need about", round(em, 1), "em = ", round(em * 16), "px at 16px, or", round(em / zero_em, 1), "ch")
print("max-width: 66ch holds about", round(66 * zero_em / per_char_em, 1), "average characters")
print("DATA " + json.dumps({"avg": per_char_em, "zero": zero_em, "n": len(SAMPLE)}))
average character width: 0.4502 em | width of the digit 0 (the ch unit): 0.5562 em
45 characters need about 20.3 em =  324 px at 16px, or 36.4 ch
66 characters need about 29.7 em =  475 px at 16px, or 53.4 ch
75 characters need about 33.8 em =  540 px at 16px, or 60.7 ch
max-width: 66ch holds about 81.5 average characters

The scale gives 16 pixels for body text, then 20, 25, 31.25 and 39.06 for the larger levels, each 25 percent bigger than the one before, and 12.8 for small print. Because the sizes are related, a heading and a paragraph look as if they belong together. The line heights come from a ratio of 1.5, and then they are snapped to a 4 pixel baseline grid: for the 20 pixel size 1.5 gives 30, which is not a multiple of 4, so it becomes 32, and for 25 pixels the 37.5 becomes 36. Snapping makes lines of different sizes line up with the same rhythm down the page.

The second program measured a real font, Liberation Sans, by reading the width of each letter from the font file. A typical sentence of 108 characters has an average character width of 0.4502 em, including spaces and punctuation, while the digit 0, the width that the ch unit uses, is 0.5562 em, about 1.24 times wider. So 66 average characters need about 29.7 em, which is 475 pixels at 16 pixels of text, and that equals 53.4 ch. The consequence is the surprise: max-width: 66ch allows about 82 average characters per line, not 66. For a target of 66 characters, use about 54ch, or set the width in em.

Independent check: the font file was also parsed by hand, reading the character map and the advance widths directly from the font tables with the struct module, and the two methods agree: the digit 0 matches to four decimals, and the average character width differs by 0.15 percent, because the library applies kerning between pairs of letters and the table reading does not. The modular scale was recomputed with exact fractions, 16 x (5/4) to the power n, and all seven sizes agree. Average widths depend on the font and the text, and the guideline of 45 to 75 characters is for reading comfort, so confirm on real devices.

Check by hand: 16 x 1.25 = 20, 20 x 1.25 = 25 and 25 x 1.25 = 31.25. A line height of 1.5 on 20 pixels is 30 pixels, and the nearest multiple of 4 is 28 or 32, with 30 exactly in between. Rounding of exact halves goes up, so 32. The output above shows the real result for each size.

Do not set body text small

Body text below 16 pixels is hard to read on many screens and for many people. Use at least 16 pixels, and size in rem, so that people can scale the text in their browser settings.

Limit yourself to two typefaces

One for headings and one for text, or even one family with several weights, is enough. A larger palette of fonts slows the page and usually looks messier.

About this course

Every calculation in this lesson was run while the course was written, in JavaScript (Node.js 22) and checked independently in Python 3.13 (and, where it says so, with real font files). Design guidelines are rules of thumb and tools change, so check current documentation, and test your own designs with real people. Font measurements depend on the font file. The figures here are for Liberation Sans, and your chosen font will differ, so measure it in the same way.

Practice

Measure the average character width of your favourite text font on a paragraph from your own site, and compute the max-width in em for 66 characters. Make a scale with the ratio 1.333 and compare the sizes. Set body line-height to 1.6 and snap it to an 8 pixel grid.

Check what you learned

Five quick questions. Pick an answer and you will see straight away whether it is right and why.

What is a modular scale?

  1. A kind of font
  2. A grid with modules
  3. A zoom level
  4. Sizes related by a constant ratio

Each step is the previous one times the ratio.

Why does 66ch hold more than 66 average characters?

  1. CSS has a bug
  2. ch counts words
  3. The digit 0 is wider than the average character
  4. Fonts change

About 1.2 times wider in this font.

What line length is a common guideline?

  1. About 20 characters
  2. About 150 characters
  3. About 45 to 75 characters
  4. Any length

66 is a good target.

What does snapping line heights to a grid give?

  1. Larger text
  2. Consistent vertical rhythm
  3. Faster pages
  4. More colours

Lines align across columns and sizes.

Why were two methods used to measure the font?

  1. To make it slower
  2. To check each against the other
  3. The library is broken
  4. It was required

Independent measurement.

Summary

  • A modular scale relates sizes with a ratio such as 1.25.
  • Aim for roughly 45 to 75 characters per line.
  • The ch unit is the width of a zero, wider than an average character.
  • Snap line heights to a baseline grid and measure real fonts.

Next lesson

Lesson 4 covers colour.

Questions

Which font should I use?

One that is readable at small sizes and available in the weights you need. System fonts are fast and familiar, and web fonts give a distinct voice at a cost in loading time. Check the licence of any font you use.

Is the 45 to 75 guideline strict?

No. It is a comfortable range for continuous text. Short lines suit captions and long lines suit wide, high-resolution layouts if the line height is generous.

Should I use all caps?

Sparingly, for short labels. Long text in capitals is hard to read, since the letter shapes are less distinct.

Progress is saved in this browser.