Use :has() to style parent elements based on their descendants

SkillDev tools

has-selector is a skill that guides an AI agent through reviewing stylesheets and components to find JavaScript that toggles classes on parent elements. It checks whether the CSS :has() pseudo-class could replace that JavaScript, explains how :has() works, and compares it with related selectors like :is() and :not().

Available today. Use it from your connected AI after setup.

Have an agent that can load and use skills.

Then ask your AI: use the Use :has() to style parent elements based on their descendants skill

What your AI can do with it

  • Identify JavaScript class-toggling that the :has() pseudo-class could replace
  • Explain how :has() works and when it applies to parent-element styling
  • Compare :has() with related selectors such as :is() and :not()
  • Note browser support for :has()
  • Warn about layout-performance costs of :has() selectors

Getting started

  1. Have an agent that can load and use skills.
  2. Add the has-selector skill to the agent's available skills.
  3. Ask the agent to review a stylesheet or component that uses JavaScript to toggle classes on parent elements.
  4. The agent applies the skill to check whether :has() can replace the JavaScript and reports its findings.

What this skill tells your AI

The instructions your AI receives, as published by thedaviddias/front-end-checklist in skills/has-selector/SKILL.md and read by ahel’s review.

Before :has(), styling a parent based on its children required JavaScript: detecting state, toggling classes, and keeping DOM and styles in sync. This created coupling between styling logic and application logic. :has() moves that relationship back into CSS where it belongs, reducing JavaScript complexity, eliminating class-toggling boilerplate, and making styling intent readable in the stylesheet itself.

Quick Reference

  • :has() selects an element when a matching descendant exists inside it
  • It is the parent selector CSS has needed for decades
  • Baseline support since late 2023 — all major browsers include it
  • Avoid complex :has() selectors in hot reflow paths — they can affect layout performance

Check

Look for patterns in this code where JavaScript toggles a class on a parent element based on the state or content of a child element. These are candidates for replacement with :has().

Fix

Replace the JavaScript class-toggling logic with a CSS :has() selector. Show the selector that targets the parent element when the relevant child condition is met.

Explain

Explain how the :has() pseudo-class works, how it differs from :is() and :not(), what descendant vs child combinators mean inside :has(), and how browser support stands today.

Code Review

Review the stylesheets and component JavaScript in this file. Flag any locations where a parent element's style is controlled by toggling a class from JavaScript based on child state — and show the equivalent :has() rule.


For full implementation details, code examples, and framework-specific guidance, see references/rule.md.

Rule page: https://frontendchecklist.io/en/rules/css/has-selector

Signals

GitHub stars
74k
Forks
7k
Last commit
Aug 2026

Questions

When should this skill be used?
When reviewing stylesheets or components that use JavaScript to toggle classes on parent elements based on child state, form input values, or content presence, :has() may replace the JavaScript entirely.
Does :has() work in all browsers?
The skill covers browser support for :has(), so the agent can report which browsers support it during a review.
Are there performance concerns with :has()?
Yes. The skill warns about layout-performance costs when using :has() selectors.
Advanced
Item type
skill
Key
has-selector
Source
github.com/thedaviddias/front-end-checklist