Sub topic 3
Touch Targets and Spacing
Assume you know semantic HTML, basic CSS, and browser developer tools. A mobile-first interface must remain usable when a user taps with one finger, holds the device in one hand, or has limited precision.
Touch targets and spacing
A touch target is the interactive area that responds to a tap. Give links and buttons a minimum size of about 44 CSS pixels, and leave space between adjacent targets so users do not tap the wrong control.
.site-nav a,
.button {
display: inline-flex;
align-items: center;
min-block-size: 44px;
min-inline-size: 44px;
padding-inline: 1rem;
}
.site-nav {
display: flex;
flex-wrap: wrap;
gap: 0.5rem;
}Do not make a small icon the only clickable area. Put it inside a larger button, and use visible focus styles for keyboard users.
Progressive disclosure
Progressive disclosure keeps secondary information available without showing everything at once. The native details element provides a keyboard- and touch-friendly disclosure control:
<details>
<summary>Shipping and returns</summary>
<p>Orders ship within two working days. Unused items can be returned within 30 days.</p>
</details>Use it for supporting details, not essential instructions or actions. The summary should explain what appears when it opens.
Serving the right image size
Large images consume data and delay rendering. Use srcset to offer multiple files and sizes to describe the rendered width. Set dimensions to reserve layout space.
<img
src="team-800.jpg"
srcset="team-400.jpg 400w, team-800.jpg 800w, team-1600.jpg 1600w"
sizes="(min-width: 64em) 50vw, 100vw"
width="800"
height="450"
alt="The support team standing in front of the office"
loading="lazy">Keeping pages light
Compress images, remove unused scripts, and lazy-load content below the first screen. Measure page weight on a throttled mobile connection rather than relying only on a fast development network.
Testing on devices
Use browser device emulation to check narrow widths, zoom, orientation, and simulated network speed. Then test on real phones. Check that targets are easy to tap, disclosures open correctly, text remains readable, and images do not cause layout shifts.
Exercise
Why should an image include both width and height attributes?
Show answer
They reserve its layout space before the file loads, reducing cumulative layout shift.