concept

Keyboard focus — CSS reference

Keyboard focus identifies the element receiving keyboard actions. Native buttons provide focus and activation behavior without custom key handlers. Styling focus must not replace that behavior; avoid positive tabindex to force a visual ordering. Programmatic focus is checked here; the supplementary test uses Tab and Space.

Formal Syntax & Structure

css syntaxcss
button:focus-visible { outline: 3px solid navy; }

Working Example

Example Snippetcss
<!doctype html><html lang="en"><meta charset="utf-8"><title>keyboard-focus</title><style>body{margin:8px;font:16px/1.5 sans-serif;color:black;background:white}#a{box-sizing:border-box}button:focus-visible{outline:3px solid navy}</style><body><button id="a">First</button><button id="b">Second</button></body></html>
CSS Reference