:has()
Matches an element if it contains at least one descendant or preceding element that matches the selector provided in the arguments. It is often referred to as the 'parent selector'.
Quick example
/* Style a card only if it contains an image */
.card:has(img) {
padding: 0;
border: 2px solid var(--accent);
} :has() Browser Support
Newly available Since 2023 94% global usage
Since 2023 this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
Works in all modern browsers. May need a fallback for older browsers.
105+
121+
15.4+
105+