Sub topic 7
Readable text and tappable targets on small screens
This chapter assumes you can write basic HTML and CSS, know how the box model works, and have built the table-based layout and media-query stacking covered in earlier chapters. Here you will set type sizes and spacing that read well on a phone, and size links so a thumb can hit them.
Why small screens need different type
A phone is held close, but the screen is narrow and the text is small. Desktop-sized body text often looks fine in a 600px column, yet it can feel cramped once the layout shrinks. Mobile clients also sometimes inflate text on their own. This can break your design in unpredictable ways, so set sizes deliberately.
Three rules cover most cases:
- Body text should be at least 16px. Smaller text makes readers pinch and zoom.
- Line height should be about 1.4 to 1.5 times the font size. For 16px text, use 24px.
- Use a font stack with a safe fallback, such as
Arial,Helvetica,sans-serif, because custom web fonts are not supported in many clients.
Set type inline, in pixels
As earlier chapters showed, many clients drop or limit embedded styles, so put type rules inline on each cell. Use pixel values for font-size and line-height. Relative units such as rem and em are inconsistent across clients.
<td style="padding:24px;font-family:Arial,Helvetica,sans-serif;font-size:16px;line-height:24px;color:#222222;">
Your order has shipped and should arrive on Friday.
</td>Set the font on the td, not on a wrapper. Table cells in some clients do not inherit font settings from parents, so a style on body or table may not reach your text.
Headings and hierarchy
Headings need to stand out without overflowing a narrow screen. A 28px to 32px heading usually works. Long words at that size can force horizontal scrolling on a 320px screen, so keep headline copy short.
You can use a media query to shrink headings on phones where embedded styles are supported:
<style>
@media screen and (max-width: 600px) {
.h1 { font-size: 24px !important; line-height: 30px !important; }
}
</style>The !important flag is needed because the inline style would otherwise win. Because some clients ignore the query, the inline size must still be acceptable on its own.
Controlling automatic text resizing
Some mobile clients, notably iOS Mail, enlarge small text automatically. If your text is already 16px or larger, this is rarely a problem. If you have small legal text, you can switch off the adjustment:
<style>
body { -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; }
</style>Do not rely on this to rescue text that is too small to begin with.
Tappable targets
A finger is much less precise than a mouse pointer. A common guideline is a touch target of at least 44 by 44 pixels, and links smaller than that cause missed taps and accidental taps on neighbors.
A bare text link is often only as tall as its line of text, which is around 20px. To make it larger, put the padding on the a element and set display:inline-block. That way the whole padded area is clickable, not just the words.
<a href="https://example.com/order" style="display:inline-block;padding:14px 20px;font-family:Arial,Helvetica,sans-serif;font-size:16px;line-height:20px;color:#0b5fff;text-decoration:underline;">Track your package</a>This link is 48px tall (14 + 20 + 14), which clears the guideline.
Space between targets
Size is not enough. If two links sit directly above each other, a tap can land on the wrong one. Keep at least 8px of space between targets, or put each in its own padded table row.
Contrast and color
Small text needs enough contrast against its background. Aim for a ratio of at least 4.5:1 for body text. Light gray on white may look elegant on a monitor, but it is hard to read outdoors on a phone. Links should also be distinguishable from surrounding text, so keep the underline or use a clearly different color.
Common errors
| Problem | Cause | Fix |
|---|---|---|
| Text looks tiny on phones | Font size of 12px or 13px | Use 16px for body text |
| Lines feel crowded | No `line-height`, or a value below 1.2 | Set a pixel line height near 1.5 times the size |
| Link is hard to tap | Padding is on the surrounding cell, not the `a` | Add padding to the `a` with `display:inline-block` |
| Font ignored in a cell | Style set only on a parent | Repeat the font settings on each `td` |
| Heading overflows | Long word at a large size | Shorten the copy or reduce the size in a media query |
Exercise
A link has padding:0 and font-size:16px;line-height:20px, so it is about 20px tall. Rewrite its style so the tap area is at least 44px tall, and explain why the padding must go on the a element rather than the cell around it.
Show answer
Use display:inline-block;padding:12px 16px;line-height:20px;font-size:16px, which gives a height of 12 + 20 + 12 = 44px. Padding on the a element is part of the link's own box, so the whole padded area responds to a tap. Padding on the surrounding cell adds empty space that is not clickable.