This document is in beta. Help us by reporting issues via Github or email
On this page:
Make sure that keyboard-only users can clearly see which interactive control is focused when they tab through them.
It should be easy to tell which element has keyboard focus.
2.4.7 Focus Visible: Any keyboard operable user interface has a mode of operation where the keyboard focus indicator is visible. (Level AA)
See the W3C’s detailed explanation of this guideline with techniques and examples.
This section needs more content. Contribute via Github or email.
This section needs more content. Contribute via Github or email.
This section needs more content. Contribute via Github or email.
By default, native HTML elements have a visual focus indicator provided by the browser. Therefore, links and focusable elements must not have their outline suppressed via CSS, unless a custom focus indicator is provided.
// Never do this, // unless you’ve already replaced the default focus outline
with better custom focus styles!
<style>
a {
outline: none; /* or outline: 0;*/
}
</style>
<!-- -->
<a href="..."> Next </a>
:focus-visible
polyfillBrowsers’ default focus styles don’t appear when people click or tap buttons or links.
However, if you define your own enhanced styles using the CSS :focus
pseu-do class, those styles will appear on click/tap as well.
Sometimes clients or designers don’t like to see a focus ring appear on a custom button or element when it gets clicked. They might say to a developer: “Get rid of that focus ring”.
But if you got rid of focus rings entirely, the interface would become unusable for keyboard users.
:focus-visible
CSS selector solves that problemUsing the :focus-visible
CSS selector allows you to …
In itself, :focus-visible
doesn’t have any accessibility benefit. Just keeping the focus visible for all users is fine from an accessibility perspective.
But it’s a good way to handle clients or designers’ requests for the focus ring to be removed for mouse or touch users, which would disable keyboard users.
:focus-visible
As of Feb 2020 :focus-visible
is only supported by default in Firefox.
But the :focus-visible
polyfill is small and robust.
:focus-visible
and backwards compatibility by The Paciello GroupThis document is in beta. Help us by reporting issues via Github or email