Sub topic 2
Start with type size
Leading and line length both depend on the size of the type. This chapter assumes you know what a font and a font size are, and that you can read basic HTML and CSS. Before you adjust either spacing value, you need a body size that works.
Why size comes first
Type size is the base unit for the other two decisions. Leading is usually written as a ratio of the font size, and line length is counted in characters. Characters take up more or less room depending on the size. Change the size afterward and both values shift.
The dependency runs in one direction:
Choosing a body size on the web
Browsers set the default text size to 16 pixels. This is a good starting point for body text on screens. Many sites go slightly larger, around 17 to 20 pixels, when the text is long and meant for sustained reading.
Two points matter more than the exact number:
- Size is not the same across typefaces. Two fonts at 16 pixels can look different because they have different x-heights. The x-height is the height of a lowercase letter such as "x", excluding ascenders and descenders. A font with a large x-height looks bigger at the same nominal size.
- Body text should not be small. Captions, footnotes, and labels can be smaller. Paragraphs people are expected to read should not be.
Use relative units
Set sizes in rem rather than fixed pixels. A rem is a unit equal to the font size of the root element, which is html and normally 16 pixels. If a reader changes their browser's default text size, rem values follow that change. Pixel values do not.
body {
font-size: 1rem;
}
.lead {
font-size: 1.25rem;
}
.caption {
font-size: 0.875rem;
}Here 1rem is 16 pixels in a default browser, 1.25rem is 20 pixels, and 0.875rem is 14 pixels. If the reader raises their default to 20 pixels, all three scale up together.
Do not set html { font-size: 62.5%; } or similar tricks without a reason. They can make the base size smaller than the reader chose, and they make rem math harder to follow.
Set the size, then test the rest
Once the size is fixed, work in this order:
- Pick the body font size, in
rem. - Set the measure, meaning the line length, as a number of characters.
- Set the leading, meaning the space between lines, as a ratio of the font size.
- Look at the result and adjust.
Later chapters cover steps 2 and 3. If you start with those and change the type size afterward, you will probably need to redo them.
Common errors
- Choosing a size for the design mockup, not the reader. A size that looks tidy in a design file can be too small on a real phone held at arm's length.
- Mixing units. Setting the body in
pxand the headings inremmeans they scale differently when the reader changes their settings. - Judging size without the real typeface. Always test with the font you will ship, not a stand-in.
- Ignoring x-height. If you swap fonts, check the size again. A change of typeface can make the same number look too large or too small.
Exercise
A page sets html { font-size: 12px; } and body { font-size: 1rem; }. A reader has set their browser default to 20 pixels. What body size does the reader get, and what is the problem with the page's approach?
Show answer
The reader gets 12 pixels. Setting a pixel size on html overrides the reader's default, so the rem units follow the 12 pixel value and not the 20 pixels the reader chose. The page should leave html unset, or use a percentage such as 100%, so that rem values follow the reader's setting.