← All Exercises

Create a High-Contrast :focus-visible Ring

basiccss~15min

Background

:focus-visible matches keyboard-driven focus, which lets you drop mouse-click outlines without harming keyboard users.

Problem

Style links, buttons, and text inputs so keyboard focus shows a 3px high-contrast ring with a 2px offset, while a pointer click does not draw the ring.

Input

A page with links, buttons, and a text input.

Output

CSS focus styles keyed to :focus-visible.

Sample tests

Sample 1

Input: User tabs to a button
Expected: a 3px solid outline with outline-offset 2px appears through :focus-visible

Sample 2

Input: User clicks the same button with a mouse
Expected: no ring is drawn because :focus-visible does not match pointer focus on a button

Your solution

Learning objective

Use :focus-visible to provide a strong keyboard focus indicator without changing pointer behavior.