We're looking for a person or people to help audit MDN to find places we could speed up. Is this you or someone you know? Check out the RFP: https://mzl.la/2IHcMiE

The :focus-within CSS pseudo-class represents an element that has received focus or contains an element that has received focus. In other words, it represents an element that is itself matched by the :focus pseudo-class or has a descendant that is matched by :focus. (This includes descendants in shadow trees.)

/* Selects a <div> when one of its descendants is focused */
div:focus-within {
  background: cyan;

This selector is useful, to take a common example, for highlighting an entire <form> container when the user focuses on one of its <input> fields.




In this example, the form will receive special coloring styles when either text input receives focus.


<p>Try typing into this form.</p>

  <label for="given_name">Given Name:</label>
  <input id="given_name" type="text">
  <label for="family_name">Family Name:</label>
  <input id="family_name" type="text">


form {
  border: 1px solid;
  color: gray;
  padding: 4px;

form:focus-within {
  background: #ff8;
  color: black;

input {
  margin: 4px;



Specification Status Comment
Selectors Level 4
The definition of ':focus-within' in that specification.
Working Draft Initial definition.

Browser compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support60 No152 No4710.1
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support6060 No1524710.3 ?

1. This feature is not implemented. See the enhancement request.

See also

Document Tags and Contributors

 Last updated by: fscholz,