Keyboard focus and target size
Definition and purpose
Keyboard focus identifies the control that receives keyboard input. A useful focus indicator is visible and not hidden beneath sticky overlays; a sufficiently large target also helps pointer users.
Keyboard indicator
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } #a:focus-visible { outline: 3px solid navy; outline-offset: 3px; } </style> </head> <body> <button id="a" type="button">Save</button> </body></html>Press Tab to see the outline separated from the button.
Syntax and mental model
Use :focus-visible for an indicator when the browser determines it is needed, especially for keyboard navigation. WCAG 2.2 AA requires focused components not to be entirely obscured by author content, and targets generally at least 24 by 24 CSS pixels, with exceptions including spacing. Choose 44px controls where practical. Scroll padding can reserve room for a sticky header, but verify real focus navigation.
Larger target
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } #a { min-width: 44px; min-height: 44px; } </style> </head> <body> <button id="a" type="button">Save</button> </body></html>The minimum height makes the control easier to hit.
Common mistakes
Do not remove outlines merely for appearance; a pointer-only hover effect does not replace keyboard focus. One fixture cannot certify WCAG compliance.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: Accessible registration project, Adaptive layout project, Reduced motion and motion paths, Design system and theme project. Next lesson: Reflow, zoom and text spacing.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Keyboard focus and target size — knowledge check
Five questions on keyboard focus and target size.
Which pseudo-class is useful for keyboard focus indicators?
Why prefer minimum height?
What is the general WCAG AA minimum target size, subject to exceptions?
What can obscure focused controls?
What must follow adding an outline?