Skip to content

Instantly share code, notes, and snippets.

@kelsS
Forked from jamiewilson/html-focus.md
Created October 29, 2025 18:36
Show Gist options
  • Save kelsS/80bb2dbf4e56eceb3761a9c062f475d6 to your computer and use it in GitHub Desktop.
Save kelsS/80bb2dbf4e56eceb3761a9c062f475d6 to your computer and use it in GitHub Desktop.
Focusable HTML Elements

CSS :focus Selector

The :focus selector is used to select the element that has focus. It is allowed on elements that accept keyboard events or other user inputs.

  • HTMLInputElement
  • HTMLSelectElement
  • HTMLTextAreaElement
  • HTMLAnchorElement
  • HTMLButtonElement
  • HTMLAreaElement

More information at https://www.w3.org/TR/html5/editing.html#focusable

An element is focusable if all of the following conditions are met:

In addition, each shape that is generated for an area element, any user-agent-provided interface components of media elements (e.g. a play button), and distinct user interface components of form controls (e.g. "up" and "down" buttons on an <input type=number> spin control), should be focusable, unless platform conventions dictate otherwise or unless their corresponding element is disabled. (A single area element can correspond to multiple shapes, since image maps can be reused with multiple images on a page.)

Notwithstanding the above, user agents may make any element or part of an element focusable, especially to aid with accessibility or to better match platform conventions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment