A button gets a clear :focus-visible outline for keyboard focus without showing the same ring for pointer focus.

Program

Keyboard users need a visible focus cue. :focus-visible lets the button show a strong outline when focus came from the keyboard.

focus_visible_button.html
Visuals: captured from real browser rendering
<button class="save-button">Save changes</button>
<style>
  .save-button { border: 1px solid #64748b; padding: 10px 14px; }
  .save-button:focus:not(:focus-visible) { outline: none; }
  .save-button:focus-visible { outline: 3px solid #2563eb; outline-offset: 3px; }
</style>
  1. Create the button.

    The page starts with one reachable button.
    The page starts with one reachable button.
  2. Give the button a visible shape.

    The button has a clear resting shape before focus.
    The button has a clear resting shape before focus.
  3. Separate pointer focus.

    Pointer focus can avoid the keyboard-specific outline.
    Pointer focus can avoid the keyboard-specific outline.
  4. Target keyboard focus.

    Keyboard focus matches the focus-visible selector.
    Keyboard focus matches the focus-visible selector.
  5. Render the focus outline.

    The focused button gets a strong visible outline.
    The focused button gets a strong visible outline.
  6. Check the outline offset.

    The offset keeps the focus ring from crowding the button edge.
    The offset keeps the focus ring from crowding the button edge.
focus-visible :focus-visible targets focus that should have a visible keyboard cue.
outline An outline makes focus visible without changing the button size.
outline offset outline-offset moves the ring away from the button edge.