:focus matches the focused element. :focus-visible matches it when the browser’s heuristics indicate that a visible focus indicator should be shown.
That is more precise than saying it means “keyboard focus only.” A text input can need a visible indicator even when someone clicks it.
| |
The example keeps input focus visible and only removes the link/button outline when the browser says the indicator is unnecessary. Adjust the colour for the actual surface; a colour that works on a dark background may be too faint on a light one.
After styling, move through the page with Tab and Shift+Tab. Check links, icon buttons and inputs, including elements inside clipped or scrolling containers. A correct selector does not help if the outline is hidden behind another element.
Reference: MDN on :focus-visible.