CSSMay 8, 2026 · 2 min read

How to Use the CSS :has() Selector (2026 Guide)

The parent selector CSS always needed. Select elements based on children, siblings, and descendants.

🎯
Try the CSS Specificity Calculator
Free, no signup
→
DG
Derek Giordano
Designer & Developer
In this guide
01What :has() Does02Practical Use Cases03Performance Considerations04Browser Support

What :has() Does

The :has() selector lets you select an element based on what it contains. For decades, CSS could only select downward (parent → child) and sideways (siblings). There was no way to style a parent based on children without JavaScript. :has() changes that. div:has(> img) matches any div containing a direct child image. form:has(:invalid) matches forms with invalid inputs. h2:has(+ p) matches h2 followed by a paragraph.

Practical Use Cases

Practical examples: style cards based on content — .card:has(img) gets different layout. Highlight form groups with errors — .form-group:has(:invalid) gets red border. Show chevrons on nav items with dropdowns. Toggle panels based on checkbox state — .panel:has(#toggle:checked) expands. Quantity-based layouts — ul:has(li:nth-child(4)) switches to grid at 4+ items. These eliminate JavaScript previously needed for parent-aware styling.

Performance Considerations

Keep :has() selectors specific — use direct child (>) over descendant (space) when possible. Browser engines have optimized significantly and performance issues are rare except in extreme cases. Profile if you suspect problems, but don’t avoid :has() preemptively — it’s fast for virtually all real-world use.

Browser Support

Supported in Chrome 105+, Safari 15.4+, Firefox 121+, Edge 105+. Global support exceeds 93%. Unsupported browsers simply ignore :has() rules — elements display without conditional styling. Safe for progressive enhancement. For critical layouts, provide a baseline without :has() and enhance with it.

Frequently Asked Questions

Is :has() really a parent selector?+
Yes, among other things. It selects parents based on children, but also siblings and distant descendants. More accurately, a ‘relational pseudo-class.’
Can I use :has() with any combinator?+
Yes. Direct child (>), descendant (space), adjacent (+), general sibling (~) all work. Combine conditions: :has(.a):has(.b) matches elements containing both.
Does :has() work with pseudo-classes?+
:has(:hover), :has(:focus), :has(:checked), :has(:invalid), :has(:empty) all work. Enables reactive styling without JavaScript.
Try it yourself

Use the CSS Specificity Calculator — free, no signup required.

⚡ Open CSS Specificity Calculator
DG
Derek Giordano
Written by the creator of Ultimate Design Tools. BA in Business Marketing.