Skip to content
Skillpedia
Websites & UI (frontend)75k · #2865

has-selector

What it does

This skill looks for code that uses JavaScript to change a parent's style based on what its children contain. It is for developers who want simpler, CSS-based styling.

When to use it

  • ✓When your script adds a class to a container whenever an input inside it changes.
  • ✓When you write JavaScript only to style a parent based on its content.
  • ✓When you want to cut down on styling code that is hard to keep in sync.

Skill link

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/has-selector/SKILL.md

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

Use this skill to help me: https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/has-selector/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute →

Example of what to ask your AI

“Can I use CSS instead of JavaScript to style a parent when its child changes?”

5 new skills a week. 1 minute to read.

How it works

The agent finds JavaScript that toggles parent classes and suggests a :has selector that targets the parent when the child condition is met. It also explains how :has differs from :is and :not.

Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

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

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/rules/css/has-selector

FAQ

What does :has do?

It selects an element when a matching child or descendant exists inside it, which CSS could not do before.

Is it widely supported?

The skill says :has has baseline support in all major browsers since late 2023.

Can it slow the page down?

The skill warns against complex :has selectors in frequently recalculated layout areas.

Details

Original description by the author

Use 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.

repo: thedaviddias/Front-End-Checklist

Popularity

GitHub stars
75k
Ranking position
#2865
License
MIT
Updated
10/31/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills