The :focus pseudo-class matches an element that currently has focus—for example after a click, tap, or Tab key press on an input or button.
It applies only to the focused element itself. To style a parent that contains focus, use :focus-within. For keyboard-oriented rings, prefer :focus-visible when you can.
Baseline · Widely available.
Not deprecated. A core interactive pseudo-class from Selectors / HTML.
Accessibility warning:
Never set outline: none on :focus without a visible replacement that meets contrast needs (WCAG non-text contrast).
Keep a ring. A thick blue outline stays visible on focus.
Offset.outline-offset adds space outside the button edge.
Tab to test. Keyboard focus should still be obvious.
Safe pattern. You customized focus without removing it entirely.
Edge Cases & Pitfalls
Accessibility mistakes around focus are the most common issues.
a11y
Do not remove outline alone
outline: none without a replacement hides keyboard focus. Always provide another clear indicator.
scope
Only the focused element
:focus does not style parents. Use :focus-within for a container that holds focus.
mouse
:focus vs :focus-visible
:focus also matches mouse clicks. Prefer :focus-visible when you want rings mainly for keyboard users.
tabindex
Divs are not focusable by default
A plain div will not match :focus unless you add tabindex="0" (and usually a role/keyboard handler).
hover
Not the same as :hover
Hover is pointer-over. Focus is keyboard/programmatic activation. Style both when needed: see :hover.
Compatibility
Browser Support
:focus is a browser CSS selector. Node.js, Deno, and Bun do not evaluate it.
✓ Baseline · Widely available
:focus
Supported in all major browsers for many years (Chrome 1+, Firefox 1+, Safari 1+, Edge 12+, IE 8+).
98%Global support
Google Chrome1+
Full support
Mozilla Firefox1+
Full support
Apple Safari1+
Full support
Microsoft Edge12+
Full support
Opera7+
Full support
Samsung Internet1+
Full support
Internet Explorer8+
Full support
:focusWidely supported
Bottom line: Safe for production focus styling. Related selectors like :focus-visible are also widely supported in modern browsers. It is not a JavaScript runtime API.
Remember
Key Takeaways
Role: style the element that currently has focus.
Form:input:focus, button:focus, a:focus, …
A11y: never remove the focus ring without a visible replacement.
Related::focus-visible for keyboard rings; :focus-within for parents.
One line::focus styles the control that currently has keyboard or pointer focus—keep that state visible.
Frequently Asked Questions
It matches the element that currently has focus—usually after a click/tap or Tab key navigation on an interactive control.
Interactive elements such as input, textarea, select, button, and a[href], plus any element given a tabindex of 0 or higher.
Do not remove the focus indicator without a clear replacement. Keyboard users need a visible ring. Replace outline with another high-contrast style if you customize it.
:focus matches whenever the element is focused, including mouse clicks. :focus-visible is for when the browser shows a focus ring—typically keyboard focus.
:focus matches only the focused element. :focus-within matches an ancestor that contains a focused descendant—useful for styling a whole form field group.
No. It is a CSS selector evaluated by the browser layout engine, not a Node.js or server runtime feature.