Accessibility CSS Beginner

Show Clear Focus Outlines for Keyboard Users

Give links, buttons and form fields a strong, visible outline when they're reached with the keyboard, without showing it on mouse clicks.

Tested on WordPress 7.1 No plugin needed Updated
style.css 10 lines
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
	outline: 3px solid #6F58CA;
	outline-offset: 2px;
	border-radius: 2px;
}

/* Some themes remove outlines completely. Put them back for keyboard users. */
:where(a, button, input, select, textarea, summary, [tabindex]):focus:not(:focus-visible) {
	outline: none;
}

Where to add this

Recommended Additional CSS Appearance → Customize → Additional CSS, or your page builder's global CSS.
Child theme At the end of your child theme's style.css file.
A code snippets plugin As a CSS snippet set to load on the front end.

People who use a keyboard, switch device or screen magnifier need to see where they are on the page. Many themes hide the focus outline because it looks untidy after mouse clicks. This CSS brings it back only for keyboard focus.

How it works

:focus-visible matches when the browser decides focus should be shown, which is almost always keyboard navigation and not mouse clicks. The rule gives those elements a 3 px outline with a little space around it.

Wrapping the selectors in :where() keeps their specificity at zero, so your theme’s own focus styles still win if it has good ones.

Things to watch

  • Pick an outline colour with at least 3:1 contrast against your backgrounds. Change #6F58CA to suit.
  • If outlines still don’t show, your theme may use outline: none !important. Add !important to the first rule.

How to test it

Load a page and press Tab repeatedly. Each link and button should get a clear purple outline. Clicking with the mouse shouldn’t show it.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only