Show contents
Chapter 4 of 7 · 20 min
Designing for touch
By the end of this chapter, you'll be able to
- Size and space comfortable touch targets
- Place important actions within thumb reach
- Replace hover interactions with touch interactions
- Use links that open calls, text messages or WhatsApp
Touch targets that are big enough
A fingertip covers about 8 to 10 millimetres. The guidelines of the major mobile systems ask for touch targets of at least 48 × 48 CSS pixels on Android and 44 × 44 points on iOS, which roughly matches that size on screen. The touch target can be larger than the button's drawing: padding is what enlarges it.
.button {
display: inline-block;
min-height: 48px;
min-width: 48px;
padding: 0.75rem 1.25rem;
font-size: 1rem;
}
.actions {
display: flex;
gap: 0.75rem;
}
Spacing matters as much as size: with gap: 0.75rem (12 pixels), two neighbouring buttons do not touch, and the thumb does not trigger the wrong one. Here is a small check in JavaScript:
function checkTarget(name, width, height, gap) {
const problems = [];
if (width < 48 || height < 48) problems.push(`too small (${width} × ${height})`);
if (gap < 8) problems.push(`too close to its neighbour (${gap} px)`);
return `${name}: ${problems.length ? problems.join(", ") : "comfortable"}`;
}
console.log(checkTarget("Call", 120, 48, 12));
console.log(checkTarget("Close ✕", 24, 24, 4));
console.log(checkTarget("Menu link", 200, 32, 16));
Call: comfortable
Close ✕: too small (24 × 24), too close to its neighbour (4 px)
Menu link: too small (200 × 32)
Within thumb reach
People often hold their phone in one hand, and the thumb easily reaches the bottom and the middle of the screen, less easily the top corners. That is why many apps put their navigation bar and their main button at the bottom.
The opposite corner is hard to reach: a good place for a rare or dangerous action.
Text description of the animation
- The bottom of the screen, in the centre, is the most comfortable zone: the main action goes there.
- The middle is easy to reach: it is the place for content you scroll through.
- The top requires stretching the thumb: put what is used less often there.
- The opposite corner is hard to reach: a good place for a rare or dangerous action.
No hover on a touch screen
On a computer, the mouse can hover over an element without clicking: many menus and tooltips appear that way (:hover in CSS). On a touch screen, there is no hover: the finger touches or it does not. Anything that only appears on hover is therefore unreachable. The rule: every action goes through a tap (a click, which also works with a finger), and :hover is only for decoration.
Links that open the phone
Some links open a phone app directly. They are plain <a> tags, but very useful for a business:
<a class="button" href="tel:+22370000000">Call</a>
<a class="button" href="sms:+22370000000">Send a text</a>
<a class="button" href="https://wa.me/22370000000?text=Hello%2C%20I%20would%20like%20an%20appointment">WhatsApp</a>
tel:opens the call screen with the number already filled in;sms:opens the messaging app;https://wa.me/followed by the number in international format (no+or spaces) opens a WhatsApp chat, with a pre-filled message (text=, encoded for a web address).
The numbers in this chapter are examples, not real numbers.
Mini-lab: buttons for the thumbHTML · CSS
Preview
The preview is isolated from the page and runs no scripts · Ctrl/⌘ + Enter to run · Esc then Tab to leave the editor
Your turn
Worked exercise
Worked exercise: the WhatsApp link generator
A dressmaker wants a button that opens WhatsApp with a ready message. Write whatsappLink(number, message) that accepts a number written with spaces or a + (like +223 70 00 00 00), keeps only the digits, and returns the full link with the message encoded.
Hint 1
number.replace(/\D/g, "") removes everything that is not a digit (\D means "not a digit").Hint 2
"https://wa.me/" + digits + "?text=" + encodeURIComponent(message).Show the solution and common mistakes
function whatsappLink(number, message) {
const digits = number.replace(/\D/g, "");
return `https://wa.me/${digits}?text=${encodeURIComponent(message)}`;
}
console.log(whatsappLink("+223 70 00 00 00", "Hello, is an alteration possible on Saturday?"));
https://wa.me/22370000000?text=Hello%2C%20is%20an%20alteration%20possible%20on%20Saturday%3F
Common mistakes:
- Keeping the
+or the spaces in the number: thewa.melink expects digits only, country code included. - Forgetting the country code (223 for Mali, for example): WhatsApp would not know which country to look in.
- Using
encodeURIinstead ofencodeURIComponent: it lets?,&and,through, which have a special meaning in an address.
Summary
- 1A touch target is at least 48 × 48 CSS pixels, with space between two neighbouring targets.
- 2The main action goes at the bottom of the screen, within thumb reach.
- 3There is no hover on a touch screen: every action must go through a tap.
- 4tel:, sms: and wa.me links open calls, messages or WhatsApp directly.
- 5Text placed in an address is encoded with encodeURIComponent.
Your progress is saved on this device. Create a free account to keep your progress on all your devices.