---
source: https://iinventedlight.com/library/notes/css-has-selector.md
title: "The :has() pseudo-class: style an element from what it contains"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "CC-BY-4.0 (web.dev); CC-BY-4.0 (web.dev); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: web.dev, Pseudo-classes; web.dev, 5 CSS snippets every front-end developer should know in 2024. CC-BY-4.0 (https://web.dev/learn/css/flexbox). Copyright Google LLC. web.dev text is CC BY 4.0."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-23
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-23
as_of: 2026-11-23
confidence: medium
untested: "Not reproduced (2026-11-23). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-web: css-has-selector"
tags: [css, has, selectors, pseudo-classes, web]
client: Librarian
sources:
  - id: S1
    title: "Pseudo-classes"
    publisher: web.dev
    url: https://web.dev/learn/css/pseudo-classes
    accessed: 2026-11-23
    license: "CC-BY-4.0"
  - id: S2
    title: "5 CSS snippets every front-end developer should know in 2024"
    publisher: web.dev
    url: https://web.dev/articles/5-css-snippets-every-front-end-developer-should-know-in-2024
    accessed: 2026-11-23
    license: "CC-BY-4.0"
---
# The :has() pseudo-class: style an element from what it contains
**Answer:** The :has() pseudo-class styles an element from what it contains. In a simple case it acts as a parent selector. It can be combined with other selectors. Nesting :has() inside :has() is not allowed.

## A parent selector, and more

Style an element from the content it contains by using :has().

button:has(svg) targets buttons that include icons.

In its most basic configuration, you can think of :has() as a parent selector.

Use the matching parent selector combined with other selectors to target other elements.

The :has() pseudo-class cannot be nested inside another :has(), but it can be combined with other pseudo-classes.

A selector list is unforgiving: one invalid entry means every rule in that list is ignored.

Do not put a pseudo-element in the :has() list.

## The subject can sit at the front

:has() is more than a parent selector.

Major browsers all shipped it at the end of 2023.

Usually the subject of a selector is at the end, like ul li.

With :has(), the first part of the selector can be the subject instead.

It can keep the container as the subject while querying the number of children.

Some uses check for something based on a common ancestor, then pivot the subject to a child.

## See also

- [css-specificity](https://iinventedlight.com/library/notes/css-specificity/)
- [css-cascade](https://iinventedlight.com/library/notes/css-cascade/)
- [css-media-queries](https://iinventedlight.com/library/notes/css-media-queries/)

## Claims

- id: C1
  claim: Use :has() to style elements based on what they contain.
  source: S1
  evidence: "style elements based on what is contained"

- id: C2
  claim: :has() cannot be nested inside another :has().
  source: S1
  evidence: "cannot be nested inside of another"

- id: C3
  claim: It can be combined with other pseudo-classes.
  source: S1
  evidence: "combined with other pseudo-classes"

- id: C4
  claim: :has() is more than a parent selector.
  source: S2
  evidence: "more than a \"parent selector\""

- id: C5
  claim: With :has(), the first element in the selector can be the subject.
  source: S2
  evidence: "element at the beginning of the selector can become"

- id: C6
  claim: The selector became available in all major browsers at the end of 2023.
  source: S2
  evidence: "landed across all major browsers at the end 2023"

## Sources

- [S1] Pseudo-classes. web.dev. https://web.dev/learn/css/pseudo-classes . License: CC-BY-4.0. Accessed 2026-11-23.

- [S2] 5 CSS snippets every front-end developer should know in 2024. web.dev. https://web.dev/articles/5-css-snippets-every-front-end-developer-should-know-in-2024 . License: CC-BY-4.0. Accessed 2026-11-23.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: web.dev, Pseudo-classes; web.dev, 5 CSS snippets every front-end developer should know in 2024. CC-BY-4.0 (https://web.dev/learn/css/flexbox). Copyright Google LLC. web.dev text is CC BY 4.0. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
