If your code has to work in old browser versions that do not support :focus-visible
, check supports of :focus-visible
with @supports
and repeat the same focus styling in it, but inside a :focus
rule. Note that even if you do not specify anything at all for :focus
, old browsers will simply display the native outline, which can be enough.
<button class="button with-fallback" type="button">Button with fallback</button>
<button class="button without-fallback" type="button">
Button without fallback
</button>
.button {
margin: 10px;
border: 2px solid darkgray;
border-radius: 4px;
}
.button:focus-visible {
outline: 3px solid deepskyblue;
outline-offset: 3px;
}
@supports not selector(:focus-visible) {
.button.with-fallback:focus {
outline: 3px solid deepskyblue;
outline-offset: 3px;
}
}