Sub topic 3
Measure in CSS: `max-width` in `ch`
Assume you know basic CSS selectors, font sizes, and the relationship between a paragraph’s measure and its line spacing. This chapter uses ch and unitless line-height.
Measure in CSS: `max-width` in `ch`
The CSS ch unit approximates the width of the 0 character in the current font. It is useful for limiting paragraph width to a readable measure. A value such as 65ch usually produces about 65 characters per line, but the exact count varies with the typeface and text.
body {
font-size: 1rem;
line-height: 1.5;
}
p {
max-width: 65ch;
}A common body-text range is about 45–75 characters per line. Narrow measures can make text feel choppy. Very wide measures make it harder to track the next line.
Adapting to small and large screens
A fixed 65ch maximum prevents excessive width on large screens. On narrow screens, the paragraph must also fit its container. Use a fluid width with a maximum:
.article p {
width: min(100%, 65ch);
line-height: 1.5;
}The paragraph uses the available space on a phone, then stops growing near 65 characters on a larger viewport. If a wider measure is necessary, increase leading slightly. A narrow caption may need less leading than body text.
Accessibility: WCAG text spacing
Check that text remains readable when users increase spacing. WCAG 2.1 Success Criterion 1.4.12 describes these test values:
- Line height: at least 1.5 times the font size
- Paragraph spacing: at least 2 times the font size
- Letter spacing: at least 0.12em
- Word spacing: at least 0.16em
Content should not be clipped, overlapped, or made unusable when these values are applied.
Vertical rhythm and paragraph spacing
Paragraph spacing should relate to line height. With 1rem text and 1.5 line-height, a 1.5rem bottom margin equals one line of vertical space.
p {
font-size: 1rem;
line-height: 1.5;
margin-block: 0 1.5rem;
}Checking a paragraph by eye and fixing it
Read several lines at normal zoom.
- If your eyes lose the next line, reduce
max-widthor increaseline-height. - If the paragraph looks fragmented, increase the measure slightly.
- If lines overlap after spacing changes, inspect fixed heights and overflow rules.
- If paragraphs form a dense wall, increase paragraph spacing.
Exercise
A paragraph is 90 characters wide and feels difficult to track. What should you try first?
Show answer
Reduce its max-width toward roughly 45–75ch, then adjust line-height if the new measure still feels cramped.