CSS Has Selector
ELI5 — The Vibe Check
The
Real Talk
The CSS
Show Me The Code
/* Style card differently when it contains an image */
.card:has(img) {
grid-template-rows: auto 1fr;
}
/* Style label when input is invalid */
label:has(+ input:invalid) {
color: red;
}
When You'll Hear This
":has() is the most powerful CSS selector added in the last decade" / "We replaced 50 lines of JavaScript class toggling with a single
Related Terms
Container Queries
Container Queries are the CSS feature we begged for years. Instead of 'how wide is the screen?' they ask 'how wide is my parent container?
CSS Nesting
CSS Nesting finally brings the one feature everyone used Sass for directly into plain CSS.
Feature Detection
Feature Detection checks if a browser supports a feature before trying to use it.