← Back to pseudo-classes
CSS Pseudo-class / Element
:has()
LogicalSelects an element if it contains a child matching the given selector — the CSS parent selector.
Syntax
selector:has(child) { }Example
div:has(img) { padding: 0; }Common use cases
- Styling a card that contains an image
- Highlighting a form that has an error input
- Changing layout when a specific child exists
Practical developer insight
:has() is the long-awaited parent selector in CSS. Support is now strong in modern browsers, making it practical for many production use cases.