: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'.
Syntax
/* Usage 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.
105+
121+
15.4+
105+