HTML & CSS Foundations · 20 min · 150 XP

Focus, contrast and motion

Keep keyboard focus visible, make controls readable and forgiving, and respect reduced-motion preferences.

A keyboard user moves through links and controls with Tab. The visible focus indicator is their cursor. Never write outline: none unless you replace it with something at least as obvious. :focus-visible normally shows the custom ring for keyboard navigation without adding it to every pointer click.

css
.action:focus-visible {
  outline: 0.2rem solid #ffbf47;
  outline-offset: 0.2rem;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

Text needs enough contrast against its background, including placeholder text and disabled states. A practical target is at least 4.5:1 for ordinary text and 3:1 for large text or meaningful interface boundaries. Do not use colour as the only signal: an error should have an icon or message as well as a red border.

Controls also need room. Aim for a target around 44 by 44 CSS pixels, but size it with relative units so it follows text. min-height: 2.75rem, comfortable padding and space between neighbouring actions prevent missed taps. Links in paragraphs should remain visibly distinguishable instead of relying on colour alone.

Loading your workspace…