: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'.

/* Usage Example */
/* Style a card only if it contains an image */
.card:has(img) {
  padding: 0;
  border: 2px solid var(--accent);
}

This comparison shows how :has() works in a real project. View snippet →

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+
Kinsta

Your first month is free

Managed WordPress hosting for faster sites.

Learn more

New CSS drops.

Join 600+ readers who've survived clearfix hacks.

ESC