coderef

:focus-withinBaseline · Widely available

The :focus-within CSS pseudo-class matches an element if the element or any of its children are focused.

Supported in all major browsers for at least 30 months — safe to use without fallbacks. Baseline since Jan 15, 2020. Widely available since Jul 15, 2022.

Browser support

DesktopChrome
1–59Not supported
60+Supportedsince Jul 25, 2017
Current: 155
Edge
12–18Not supported
79+Supportedsince Jan 15, 2020
Current: 154
Firefox
1–51Not supported
52+Supportedsince Mar 7, 2017
Current: 157
Safari
1–10Not supported
10.1+Supportedsince Mar 27, 2017
Current: 27
MobileChrome Android
18–59Not supported
60+Supportedsince Aug 1, 2017
Current: 155
Firefox Android
4–51Not supported
52+Supportedsince Mar 7, 2017
Current: 157
Safari iOS
1–10Not supported
10.3+Supportedsince Mar 27, 2017
Current: 27

How to use

This feature is Baseline widely available — use it freely, no fallback needed.

Example

Full syntax and examples are on MDN: :focus-within.

Feature detection

CSS · check before using
@supports selector(:focus-within) {
  /* styles that use :focus-within */
}

/* or in JavaScript */
if (CSS.supports("selector(:focus-within)")) {
  // use it
}