Sub topic 11
Adapting to Small and Large Screens
This chapter assumes you know what leading and measure are. It also assumes you can write basic CSS, and that you have already used a unitless line-height and a max-width in ch on a paragraph. Here you will see what happens to those settings when the same page is shown on a phone, a laptop, and a wide desktop monitor, and how to adjust them without losing readability.
Why one fixed setting is not enough
A paragraph that reads well on a laptop can fail elsewhere. The screen changes two inputs to the paragraph:
- Available width. A phone gives the text column roughly 300 to 400 CSS pixels. A wide monitor gives thousands, so the line can grow far past a comfortable measure unless you stop it.
- Viewing conditions. Phones are held close and used in short bursts. Desktop monitors are farther away, so text often needs a larger size to look the same to the eye.
Each input affects the settings you learned earlier. Width changes the measure. Size changes how much leading a line needs. The goal is to keep both inside a comfortable range as the screen changes.
The two ends of the measure problem
Commonly cited guidance puts a comfortable body-text measure at about 45 to 75 characters per line, with around 65 as a target. The two ends of the screen range fail in different ways.
| Screen | What goes wrong | Typical cause | Fix |
|---|---|---|---|
| Wide desktop | Lines of 100+ characters. The eye loses its place on the return sweep. | No cap on the text column | Cap with `max-width` in `ch` |
| Narrow phone | Lines of 25 to 35 characters. Ragged edges, many short lines, awkward word breaks. | Large margins or side padding, or a large font size | Reduce padding, keep the size at 1rem or above, and accept a measure below 45 |
On a phone you cannot reach 65 characters without shrinking the text below a readable size, so you accept a shorter measure. Lines of about 35 to 45 characters are common on phones and read acceptably. Do not shrink the font to chase the desktop number.
You can estimate the measure from the layout. Suppose a phone is 360 CSS pixels wide, with 16px padding on each side. The text column is 328px. If the font is 16px and the average character is about 8px wide, a line holds roughly 41 characters. That sits at the low end of the range, which is fine. If you added another 24px of padding on each side, you would be down to about 34.
A cap that works at every width
The measure cap already adapts without a media query. A max-width is only a ceiling. On a narrow screen the column is narrower than the ceiling, so the viewport sets the width. On a wide screen the ceiling takes over.
body {
margin: 0;
padding-inline: 1rem;
font-size: 1rem;
line-height: 1.5;
}
p {
max-width: 65ch;
}The padding-inline keeps text away from the screen edge on phones. Without it, text touches the glass and becomes hard to read. The paragraph stays left-aligned inside the body. If you want the column centred on wide screens, wrap the content in a container with margin-inline: auto.
How `ch` behaves when the font size changes
The ch unit is based on the width of the "0" glyph in the element's own font and size. If the font size grows, 65ch grows with it. This is the main reason to prefer ch over px: the measure stays about the same in characters even when you scale the type.
Two gotchas follow from this:
- The cap uses the element's font, not its parent's. If you set
max-width: 65chon a wrapper with a 1rem font and the paragraphs inside use 1.25rem, the paragraph lines will be shorter than expected in characters. Put the cap on the element that holds the text, or make the fonts match. chis only an approximation of characters. The "0" is usually wider than the average lowercase letter in running text. In many fonts,65chfits somewhat more than 65 characters of prose. Check the result by eye, as described in a later chapter, and adjust the number.
Letting the type size grow with the screen
On large screens, a slightly larger font often helps. You can make it grow smoothly with clamp(), which takes a minimum, a preferred value, and a maximum.
body {
font-size: clamp(1rem, 0.9rem + 0.4vw, 1.25rem);
line-height: 1.5;
}At a 320px viewport the middle value comes to about 15.7px, so the 1rem minimum wins. At 1280px it is about 19.5px. It reaches the 1.25rem maximum (20px) at about a 1400px viewport. The text never goes below 1rem and never above 1.25rem.
The preferred value mixes rem and vw on purpose. If you used vw alone, such as font-size: 2vw, the size would not respond when a user zooms the page or raises their browser's default font size. That fails users who need larger text, and it conflicts with WCAG 1.4.4 (Resize Text). The rem part keeps the user's preference in the calculation.
Because line-height: 1.5 is unitless, the leading grows with the font automatically. At 16px a line is 24px tall. At 20px it is 30px. You get proportional leading with no extra rules.
Adjusting leading by screen size
A unitless leading keeps the same ratio. Often you also want the ratio itself to change, because the measure changes with the screen. The earlier chapter on measure and leading explained that longer lines need more leading. On a phone the lines are short, so a ratio of about 1.4 to 1.5 is comfortable. On a wide screen with a 70ch measure, a ratio near 1.6 helps the eye find the next line.
You cannot use clamp() to slide a unitless line-height with the viewport. The expression calc(1.3 + 0.2vw) is invalid, because it adds a plain number to a length. Use a small number of breakpoints instead:
body {
padding-inline: 1rem;
font-size: clamp(1rem, 0.9rem + 0.4vw, 1.25rem);
}
p {
max-width: 65ch;
line-height: 1.45;
}
@media (min-width: 48rem) {
body {
padding-inline: 2rem;
}
p {
line-height: 1.55;
}
}
@media (min-width: 80rem) {
p {
max-width: 70ch;
line-height: 1.6;
}
}The breakpoints are in rem, so they also respond to a user's larger default font size. Someone who raises their font size gets the wider layout later, which usually suits them. Keep the number of steps small. Two or three are enough, and each step should be a change you can see, not a fine adjustment.
The decision process looks like this:
Starting values to test
These values are starting points, not rules. Typefaces differ, so test them in your own font.
| Width class | Text size | Measure | Leading ratio |
|---|---|---|---|
| Phone (under about 48rem) | 1rem | Set by viewport, about 35 to 45 characters | 1.4 to 1.5 |
| Tablet and laptop | 1rem to 1.125rem | Cap near 65ch | 1.5 to 1.55 |
| Wide desktop | 1.125rem to 1.25rem | Cap 65ch to 70ch | 1.55 to 1.6 |
Common errors
- Setting the container width in pixels. A
600pxcolumn on a 320px phone forces sideways scrolling. Usemax-width, never a fixedwidth, for text. - Shrinking text to fit more characters per line. Below about 16 CSS pixels, body text becomes hard to read for many people. Accept shorter lines instead.
- Using fixed
line-heightin pixels. A value like24pxdoes not scale when the font size grows withclamp(), so lines can collide on large screens. - Measuring the page instead of the text column. If a sidebar takes half the width, the text column is what matters. Cap the measure on the paragraph, not on the page.
- Testing only at your own screen size. Check at about 320px, 768px, and a wide window of 1440px or more, and with browser zoom at 200%.
Exercise
A page sets body { font-size: clamp(1rem, 0.9rem + 0.4vw, 1.25rem); line-height: 24px; } and p { max-width: 65ch; }. On a wide desktop, the text looks cramped, and the lines nearly touch. Name the cause and give a corrected declaration.
Show answer
The cause is the fixed pixel line-height. The font grows to about 20px on wide screens, but the line height stays at 24px, which is a ratio of only 1.2. Replace it with a unitless value, such as line-height: 1.5;. Then the line box scales with the font, giving 30px at 20px type. You could also raise it to about 1.6 in a wide-screen media query.
Exercise
A phone is 360 CSS pixels wide. The body has 20px padding on each side, and the text is 16px with an average character width of about 8px. About how many characters fit on a line, and what is one change that would raise the number without shrinking the text?
Show answer
The text column is 360 minus 40, which is 320px. Divided by 8px per character, that gives about 40 characters per line. Reducing the side padding to 16px gives a 328px column and about 41 characters. A more noticeable gain comes from reducing padding to 12px, which gives about 42. The main point is that the measure on a phone stays near the low end of the range, and you should not shrink the text to compensate.