Focus Within
Pseudo-class:focus-withinSelects an element that itself has focus or contains an element that has focus.
Example
form:focus-within {
box-shadow: 0 0 0 3px rgba(59,130,246,0.3);
}
.search:focus-within .icon {
color: blue;
}Specificity
0-1-0
Browser Support
All browsers
About the Focus Within
The :focus-within CSS selector belongs to the Pseudo-class category.Selects an element that itself has focus or contains an element that has focus. Understanding CSS selector specificity and combinators is essential for writing maintainable stylesheets that behave predictably.
The specificity of this selector is 0-1-0. CSS specificity determines which styles are applied when multiple rules target the same element. Higher specificity values take precedence. The specificity hierarchy from lowest to highest is: universal (*) → type/element → class/attribute/pseudo-class → ID → inline styles → !important.
Browser support for Focus Within is: All browsers. When using newer CSS selectors like :has(), :is(), or CSS nesting, consider providing fallback styles for older browsers. Use @supports to progressively enhance your stylesheets with modern features while maintaining backward compatibility.