Text Spacing and Readability
How line-height, line length, letter-spacing and paragraph spacing decide whether a block of text is comfortable to read, with values that are safe defaults.
Text Spacing and Readability
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- Set `line-height` unitless. `1.5` is a sensible body default, around `1.1` to `1.3` suits large headings, and a unitless value scales with each element's own font size.
- Keep line length near 45 to 75 characters. `max-width: 65ch` gives a measure that follows the font.
- `letter-spacing` is best in `em` so it scales with the text. Add a little to small caps and all-uppercase text, and leave lowercase body text alone.
- Spacing between paragraphs comes from margin, and it should be tied to the text size, for example `margin-block: 1em` or `1lh`.
- WCAG 1.4.12 expects content to survive a user overriding line height to 1.5, paragraph spacing to 2 times the font size, letter spacing to 0.12em and word spacing to 0.16em. Fixed-height text boxes break under that.
Reading is eye movement
An eye reads a line left to right, then jumps back to the start of the next line. If the lines are too long, it loses its place on the return. If they are too close, descenders of one line crowd the ascenders of the next. If the letters are packed or loose, words stop forming recognisable shapes. Typography here is mostly about making that return trip easy, and four properties do almost all of it.
line-height: space between lines
line-height sets the height of each line box. Text sits vertically centered in it, so extra line height adds space above and below each line.
body { line-height: 1.5; }
h1, h2, h3 { line-height: 1.2; }
Write it without a unit. A number is a multiplier of the element’s own font size, and children inherit the multiplier. A length such as 24px or a percentage is resolved once and passed down as a fixed length, which gives cramped or loose text in any child with a different font size, as inheritance and computed values demonstrated. I measured line-height: 1.6 on a 20px element as 32px.
Reasonable defaults: about 1.4 to 1.6 for body text, lower for larger text, since a big heading with body-sized spacing looks loose. Longer lines and smaller type want more leading, shorter lines and larger type want less.
The lh unit, equal to the element’s line height, makes vertical rhythm simple: margin-block: 1lh is one line of space.
Line length: the measure
The most comfortable range for sustained reading is about 45 to 75 characters per line. The CSS unit built for that is ch:
article p { max-width: 65ch; }
ch is the width of the 0 glyph in the element’s font and size, so the line holds about the same number of characters whatever font you pick, and it grows if a reader scales the text. Put the limit on the text, not the whole page, so that images, code blocks and figures can still run wider.
letter-spacing and word-spacing
Body text is already spaced by the type designer; leave letter-spacing at normal for lowercase paragraphs. Where it helps:
- All-caps and small-caps text, which is cramped by default. A little extra, like
0.05emto0.1em, helps. - Large display text, which often looks better slightly tighter (a negative value such as
-0.02em).
Use em, not px, so the spacing scales. At 20px, letter-spacing: 0.05em computed to 1px in my test, and it will be 2px at 40px. Don’t add spacing to text in cursive scripts such as Arabic, where letters join and breaking the connections damages the writing.
Paragraph spacing and alignment
Space between paragraphs comes from margin, preferably in a unit tied to the text:
p + p { margin-block-start: 1em; }
Left-aligned text (text-align: start, which follows the language’s direction) gives each line a predictable start, and the uneven right edge is easy on the eye. text-align: justify stretches word spaces to make a flat right edge; on narrow columns this leaves rivers of white space, so use it only with wide columns and with hyphenation enabled (hyphens: auto and a lang attribute on the page). The wrapping options for that are in text wrapping and truncation.
Space above and below letters
A font has built-in space above its capital letters and below its baseline, so a heading with padding: 1rem looks like it has more space on top than the CSS says. The text-box shorthand and text-box-trim trim that, aligning boxes to the cap height and baseline. They are in Chrome 133, Safari 18.2 and Firefox 154, per MDN’s compatibility data, so check support first.
Spacing must survive user overrides
Some readers, including many with dyslexia or low vision, apply their own text spacing through a stylesheet or extension. WCAG 2.1’s success criterion 1.4.12 requires that nothing is lost when a user sets line height to at least 1.5 times the font size, paragraph spacing to 2 times, letter spacing to 0.12 times and word spacing to 0.16 times. A box with a fixed height, or text clipped with overflow: hidden, fails that. Let containers grow with min-height or no height at all, and test with those values applied. More in accessible CSS.
What the video covers
Kevin Powell’s “HTML & CSS for Absolute Beginners: Line height and spacing” is under eight minutes and is a clip from his free beginner course. By its title it covers line-height and spacing basics. I could not read a transcript, so the ch measure, letter-spacing, text-box and WCAG material above are this lesson’s own, with the computed values from tests in Chromium. The runner-up is a 26-minute beginner guide to styling text, from September 2023.
Where this fits
Spacing is the third piece of text setup after choosing and loading fonts: font families and web fonts and variable fonts and font loading. Next, fluid typography with clamp makes the sizes themselves respond to the screen. For the broader accessibility context, see the frontend roadmap’s accessible HTML and ARIA lesson.
Check yourself
A paragraph in a 20px font has `line-height: 1.6`. What is the line height in pixels, and what does a nested 30px `span` inside it get?
32px for the paragraph (20 × 1.6). The span inherits the number 1.6, not the 32px, so its own line box is computed from its own size: 30 × 1.6 = 48px. A length or percentage would pass down a fixed 32px instead.
Why is `max-width: 65ch` better than `max-width: 600px` for body copy?
`ch` is the width of a `0` in the element's font, so 65ch holds roughly the same number of characters whatever the font and size, and it scales if the reader enlarges their text. 600px can give 40 characters in a large font and 90 in a small one.
Why write `letter-spacing: 0.05em` instead of `1px`?
`em` is relative to the element's font size, so the spacing stays in proportion if the size changes. At 20px, `0.05em` computes to 1px, and at 40px it computes to 2px, whereas `1px` would be too tight on large text. I confirmed that 0.05em at 20px computes to 1px.
A card clips its text with a fixed `height: 120px`. What accessibility problem can that cause under WCAG 1.4.12 text spacing?
If a user increases line height, letter spacing or paragraph spacing, the text needs more room and the fixed height cuts it off. Use `min-height` or let the box grow with its content, so adjusted spacing never hides text.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.