.card:has(img) - Select cards containing images
input:has(:placeholder-shown) - Select empty inputs
li:has(a[aria-current]) - Select current nav item
.card:has(.btn:hover) - Card changes on child hover
h2:has(+ p) - Select heading directly followed by p
.container:has(.active) - Select container with .active
This card contains an img tag
This card has no img tag
Also contains an img tag
No img but has other content
Global support: 92%+ (2024)
The CSS :has() selector is a relational pseudo-class introduced in CSS Selectors Level 4, often called the "CSS parent selector." It allows you to select elements based on the content of their descendants or subsequent siblings, fundamentally changing CSS's top-down-only selection limitation.
:has(selector-list) — The :has() pseudo-class matches when the element matches any selector in the list.
:has() is a relational pseudo-class selector introduced in CSS Selectors Level 4. It allows selecting parent elements based on the existence of child elements or subsequent sibling elements. It is often called the 'parent selector' and is one of the most anticipated CSS features.
:has() is supported by all major browsers: Chrome 105+, Firefox 121+, Safari 15.4+, Edge 105+. Global browser support exceeds 92%.
Regular CSS selectors select top-down (parent to child), while :has() can select bottom-up (child to parent). For example, .card:has(img) selects .card elements that contain an img, which previously required JavaScript.
:has() performs well in simple scenarios. However, complex :has() nesting (like :has(:has())) or usage on large DOM trees may impact rendering performance. Avoid deep nesting and limit selector complexity within :has().
Absolutely safe. All CSS code parsing and preview runs locally in your browser. No data is sent to any server, and no code is stored. Data is automatically cleared when you close the page.