DevTools Logo

CSS :has() Selector Playground

CSS :has() Selector Playground

Edit HTML and CSS side by side, insert working :has() patterns and catch rules the browser drops.

Runs in your browser

Editors

2 top-level rule(s)

The parent form reacts to an invalid descendant without a class toggle.

:has(:invalid) contributes the specificity of :invalid (0,1,0).

The sandbox has no script access and a restrictive CSP: pasted HTML cannot run code or fetch remote resources.

Live sandbox

desktop width · 0 warning(s)
Checking :has() support…
Minimum browser versions supporting :has()
BrowserVersionReleased
Chrome / Edge105+2022-08
Safari15.4+2022-03
Firefox121+2023-12

:has() itself adds no specificity; the most specific argument inside it does. Negative arguments in :not() follow the same rule.

Examples

Invalid form

Input
.card:has(:invalid) .banner { display: block }
Output
Banner appears while the email field is invalid

No JavaScript class toggling is needed.

Previous sibling

Input
label:has(+ input:focus)
Output
Focused field label turns blue

Relative selectors inside :has() read backwards from the target.

Broken rule

Input
div:has( { color: red }
Output
Possibly dropped rule: div:has(

The detector names the selector so you can fix the missing parenthesis.

About this tool

The CSS :has() Selector Playground pairs editable HTML and CSS with a live sandbox so you can see how the parent selector behaves instead of guessing from documentation. Ten curated patterns cover the tricky cases: invalid form fields, cards that contain images, nested lists, labels before focused inputs, checked table rows, grid reflow around video, empty states, sibling tooltips, data-theme switches and open disclosures.

Because invalid :has() rules are silently discarded by browsers, the playground includes a rule-integrity check: it splits your stylesheet into top-level rules, reads back the stylesheet the sandbox kept, and names the rules that were likely dropped. A support matrix and a live CSS.supports probe put browser compatibility next to the code, while per-pattern notes explain the specificity contributed by the argument inside :has().

The sandbox iframe runs without script permission and with a restrictive content security policy, so pasted markup cannot execute code or fetch remote resources. Everything happens in the browser; the share action encodes the two panes into the URL fragment without sending a request.

What this tool does not do

  • Rule detection compares counts and reports possibilities; it does not reconstruct the browser's full parser error log.
  • The sandbox deliberately disables scripts, so patterns that depend on JavaScript state cannot be demonstrated.
  • Shared snippets are limited to 16 KB in the URL fragment; longer drafts stay local.

How to use this tool

  1. Pick a pattern

    Choose one of ten :has() demos from the gallery and insert it into the editors. Use Append to keep earlier demos with scoped selectors.

  2. Edit HTML and CSS

    Change markup or selectors in the panes. The sandbox rebuilds after a short debounce so you can type continuously.

  3. Read the diagnostics

    Check the support probe, browser matrix and specificity note. If a rule disappears from the rendered result, the dropped-rule panel names it.

  4. Share or copy

    Copy the standalone CSS or HTML, or write both panes into a shareable URL fragment.

Use cases

Learning :has()

See a parent react to descendants and siblings while reading the specificity note for each pattern.

Replacing class toggles

Prototype validation, selection and accordion states in pure CSS before changing application code.

Verifying blog examples

Paste a snippet from an article and check whether the browser actually keeps the rule.

What the playground reports

PanelInformation
EditorsRaw HTML and CSS with :has() rules; changes rebuild the sandbox after 300 ms
SandboxIframe with allow-same-origin only, no scripts and a default-src 'none' CSP
Rule integrityTop-level rule count versus cssRules, naming possibly dropped selectors
SupportChrome/Edge 105+, Safari 15.4+, Firefox 121+ and a live CSS.supports probe
SpecificityThe most specific argument inside :has() contributes the weight

Warnings are phrased as possibilities: browser CSSOM implementations can discard invalid rules at different stages.

Common mistakes

Mistake:Expecting :has() to add specificity of its own.

Fix:Only the most specific argument counts; the per-pattern note shows the resulting weight.

Mistake:Using a relative selector without a combinator.

Fix:Prefix >, + or ~ when you mean a direct child or a sibling; the gallery includes working examples.

Mistake:Assuming a missing style means a browser bug.

Fix:An invalid :has() rule is dropped silently — check the integrity panel first.

Mistake:Pasting content with remote images and expecting privacy.

Fix:The sandbox CSP blocks remote subresources; data URLs still work.

Frequently asked questions

Which browsers support :has()?

Chrome and Edge since 105 (August 2022), Safari since 15.4 (March 2022) and Firefox since 121 (December 2023). The playground shows this matrix and runs a live CSS.supports('selector(:has(a))') probe in your current browser.

What specificity does :has() contribute?

:has() itself has zero weight; the most specific argument inside it contributes. For example, .card:has(:invalid) has the specificity of .card plus a pseudo-class, while .card:has(img) adds only an element selector. Each gallery pattern includes the exact rule.

Why is my :has() rule ignored?

Browsers silently discard invalid selectors — an unclosed parenthesis or an invalid argument leaves no console error. Split your CSS into rules and compare with the stylesheet the browser kept; the playground's integrity panel names likely dropped selectors.

Can :has() check previous siblings?

Yes, with a relative selector: label:has(+ input:focus) matches a label immediately followed by a focused input. The gallery includes sibling-label and tooltip patterns using + inside :has().

Does :has() work inside @supports?

Yes. @supports selector(:has(*)) is the standard feature query, and :has() rules also work inside @media. The rule splitter in the playground is brace-aware so nested rules are counted correctly.

Can pasted HTML run scripts in the sandbox?

No. The iframe omits allow-scripts and sets a default-src 'none' CSP, so script tags and remote subresources cannot run or load. Inline styles and data URLs still render, which is enough for every pattern.

References & standards