Copy the Browser's Native Focus Styles

Need to restore a focus indicator you removed, or apply one to an element that isn't actually focused? Remy documented a technique the other day that gets you the browser's own default rather than an imitation.

The trick rests on vendor keywords: Firefox exposes Highlight, while Chrome and Safari both accept -webkit-focus-ring-color.

Putting one to use looks like this:

button:focus + span {
  outline: 5px auto Highlight;
  outline: 5px auto -webkit-focus-ring-color;
}

Chris Coyier tried it and found the results looked good to him. He notes it is especially handy for Chrome's somewhat odd new double-outline style, which would be a bit tricky to reproduce by hand otherwise.

Chrome 84
Safari 13.1
Firefox 80
CSS-Tricks star logo