Sub topic 2
Designing for keyboard use
Prerequisites: you know basic wireframing, common UI components such as forms and menus, and the basics of HTML and CSS.
Designing for keyboard use
Some users cannot use a mouse. They move through a page with the Tab key and activate controls with Enter or Space. Each wireframe should show:
- Every interactive element: links, buttons, form fields and menus.
- A focus order that matches the visual reading order, numbered on the wireframe.
- The keys each control responds to: Enter activates links and buttons, Space toggles checkboxes, and Escape closes dialogs.
A common error is a styled div that acts as a button. It receives no keyboard focus and ignores Enter. Specify a native <button> instead.
Choosing colors that meet contrast ratios
WCAG requires a contrast ratio of at least 4.5:1 for normal text and 3:1 for large text and UI components. Check every text and control color pair during wireframing.
function channel(value) {
const s = value / 255;
return s <= 0.03928 ? s / 12.92 : Math.pow((s + 0.055) / 1.055, 2.4);
}
function luminance([r, g, b]) {
return 0.2126 * channel(r) + 0.7152 * channel(g) + 0.0722 * channel(b);
}
function contrastRatio(rgbA, rgbB) {
const [light, dark] = [luminance(rgbA), luminance(rgbB)].sort((a, b) => b - a);
return (light + 0.05) / (dark + 0.05);
}
console.log(contrastRatio([0, 0, 0], [255, 255, 255])); // 21Adding cues beyond color
Users with color blindness may miss a color-only signal. Pair color with an icon or text.
| State | Color only (fails) | Color plus cue (passes) |
|---|---|---|
| Error | Red border | Red border, error icon and "Enter a valid email" text |
Making focus visible
Browsers draw a default focus ring, but designs often remove it. Specify a replacement indicator.
:focus-visible {
outline: 3px solid #005fcc;
outline-offset: 2px;
}Sizing and spacing interactive targets
WCAG 2.2 Target Size (Minimum) requires targets of at least 24 by 24 CSS pixels, or enough clear space around smaller targets. Annotate each target with its minimum size.
Exercise
Exercise
A wireframe shows a 16 by 16 pixel close icon with no extra spacing, and the nearest other target is 4 pixels away. Does it meet the target size criterion?
Show answer
No. Enlarge the icon to at least 24 by 24 pixels, or keep a 24-pixel circle centered on the icon free of other targets.