Dev Encyclopedia
ArticlesToolsContactAbout

Get notified when new content drops

No spam. Just new articles, tools, and updates straight to your inbox.

Dev Encyclopedia

A reference for builders

Content

  • Articles
  • Tools
  • About
  • Contact

Connect

  • support@devencyclopedia.com
  • RSS Feed

Legal

  • Privacy Policy
  • Terms of Service
  • Disclaimer

© 2026 Dev Encyclopedia

Back to top ↑
  1. Home
  2. /
  3. Tools
  4. /
  5. CSS :has() Playground
Free · Live · No account

CSS :has() Playground

Pick a real-world HTML scene, type a :has() selector, and see exactly which elements match, live in your browser. No CodePen, no setup.

Zeeshan Tofiq

Zeeshan Tofiq

Full Stack Developer

Try these patterns

Paste any selector from this table directly into the tool above.

SelectorWhat it selects
.form-group:has(input:invalid)Form row when its input is invalid
li:has(a.active)Nav item containing the active link
.card:has(img)Card containing an image
.grid:has(.card:hover) .card:not(:hover)Sibling cards (dimming on hover)
label:has(input:checked)Label whose checkbox is checked
.grid:has(:nth-child(3))Grid with 3+ items

What works vs. what doesn't in this playground

  • ✓Persistent states: :has(img), :has(.active), :has(input:invalid), :has(input:checked)
  • ✗Transient states: :has(:hover), :has(:focus) — evaluated at call time, not during hover. Click “Show Answer” to see the CSS effect directly.

Frequently Asked Questions

How does the element highlighting work?
  1. When you type a selector, the tool runs document.querySelectorAll(selector) inside the preview pane.
  2. It adds a .pg-match CSS class to every matched element, which applies a pulsing yellow outline.
  3. The query runs 150ms after each keystroke so the preview stays responsive while you type.
Why doesn't the hover-based selector highlight any elements?

querySelectorAll evaluates the selector at the exact moment it's called. Since nothing is hovered when the query runs, .grid:has(.card:hover) matches zero elements.

💡 Tip

The CSS itself still works: click Show Answer to apply the styles directly, then hover over the cards to see the effect live.

Why does :has(input:checked) work but :has(input:hover) doesn't?
:has(input:checked) ✓:has(input:hover) ✗
State typePersistent (DOM tracks it)Transient (only exists during hover)
querySelectorAllEvaluates real DOM stateHover is gone by call time
Works in playground?YesNo, use Show Answer instead
Is CSS :has() safe to use in production?

Yes. :has() is Baseline Widely Available since 2024. Chrome, Firefox, Safari, and Edge all support it fully. Global coverage exceeds 95% in 2026. Use it without fallbacks for any modern project.

How is this different from CodePen or JSFiddle?
This playgroundCodePen / JSFiddle
Starting point6 preloaded real-world scenesBlank canvas (build HTML yourself)
PurposeTest :has() specificallyGeneral CSS/JS sandbox
Account needed?NoOptional but needed to save

Related reading

Guide

8 CSS :has() Patterns You'll Actually Use

Form states, sibling dimming, modal scroll-lock, and five more real-world :has() patterns with copy-paste CSS and HTML.

Tool

CSS Specificity Calculator

Paste any CSS selector and see its (a, b, c) score. Understand how :has() affects specificity when you combine it with IDs and classes.

Zeeshan Tofiq

Zeeshan Tofiq

Full Stack Developer

Full stack developer with over 6 years of experience building production applications. Writes practical guides on JavaScript, TypeScript, React, Node.js, and cloud infrastructure. Focused on helping developers solve real problems with clean, maintainable code.

Enjoyed this article?

Get practical dev guides, tool updates, and new articles delivered straight to your inbox. No spam, unsubscribe anytime.

CSS Selector

:has()

💡 Tip

This form has three .form-group containers. Two of the inputs are invalid — a required empty field and an invalid URL. Try the starter selector, then explore variants.

Preview