---
title: "Using :has() as a CSS Parent Selector and much more"
description: "The CSS `:has()` pseudo-class, long requested as a \"parent selector\", lets developers style an element based on its descendants, its following siblings, or the state of elements anywhere in the DOM."
url: "https://swe.quest/articles/using-has-as-a-css-parent-selector-and-much-more-a6801a96d8b4f383"
canonical: "https://webkit.org/blog/13096/css-has-pseudo-class/"
source: "WebKit"
published: "2022-08-18"
difficulty: "medium"
kind: "How-to"
reading_minutes: 13
tags: ["css","frontend","browsers"]
---

# Using :has() as a CSS Parent Selector and much more

A post on [WebKit](https://swe.quest/sources/webkit.md), published 2022-08-18, 13 min read, How-to. Original: [https://webkit.org/blog/13096/css-has-pseudo-class/](https://webkit.org/blog/13096/css-has-pseudo-class/)

## Summary

The CSS \`:has()\` pseudo-class, long requested as a "parent selector", lets developers style an element based on its descendants, its following siblings, or the state of elements anywhere in the DOM. WebKit shipped it in Safari 15.4 using new \`:has\`-specific caching and filtering optimizations. Chrome 105 ships Igalia's implementation, and Firefox is in progress. Hands-on examples cover styling figures and grid cards by their content, the child and sibling combinators inside \`:has()\`, form-state styling such as \`:focus-visible\` and \`:invalid\` labels, and JavaScript-free theme toggles. Some pseudo-classes, including media states and certain form invalidation cases, don't yet update inside \`:has()\`, so cross-browser testing is recommended.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [CSS](https://swe.quest/tags/css.md) (Web & mobile)
- [Frontend](https://swe.quest/tags/frontend.md) (Web & mobile)
- [Browsers](https://swe.quest/tags/browsers.md) (Web & mobile)

## Prerequisites

- CSS selectors ([easy posts on CSS](https://swe.quest/tags/css.md?difficulty=easy))
- CSS combinators ([easy posts on CSS](https://swe.quest/tags/css.md?difficulty=easy))

## Keywords

:has(), Safari, WebKit, CSS Selectors Level 4, Igalia, Chrome 105, @supports selector()

## Related posts

- [WebKit Features in Safari 16.5](https://swe.quest/articles/webkit-features-in-safari-16-5-78f214007552b969.md): WebKit · 2023-05-18 · Easy · 4 min read · Browsers, CSS, Frontend
  Safari 16.5 is mainly a polish and bug-fix release that adds CSS Nesting, the :user-valid and :user-invalid pseudo-classes, Apple Pay support for pre-orders and deferred payments, and disabling of the WebCodecs API in Lockdown Mode.
- [Try out CSS Nesting today](https://swe.quest/articles/try-out-css-nesting-today-89a2bd161645dd60.md): WebKit · 2023-02-08 · Medium · 5 min read · CSS, Browsers
  CSS Nesting, using the community-chosen Option 3 syntax, shipped on by default in Safari Technology Preview 162 and is behind a flag in Chrome Dev.
- [New to the web platform in July](https://swe.quest/articles/new-to-the-web-platform-in-july-fcd36ed79801648a.md): web.dev · 2026-07-31 · Easy · 4 min read · Browsers, CSS, Frontend
  Chrome 151, Firefox 153 and Safari 26.6 reached stable in July 2026.
- [New to the web platform in August](https://swe.quest/articles/new-to-the-web-platform-in-august-d903fac59867da54.md): web.dev · 2026-08-28 · Easy · 5 min read · Browsers, CSS, JavaScript, Frontend
  Chrome 152 and Firefox 154 shipped to stable in August 2026, making several features Baseline Newly available: the text-box-trim/text-box-edge properties for trimming font leading, the sibling-count() and sibling-index() CSS functions, and the global autocorrect attribute.
- [News from WWDC26: WebKit in Safari 27 beta](https://swe.quest/articles/news-from-wwdc26-webkit-in-safari-27-beta-4f7db5fa3d901641.md): WebKit · 2026-06-08 · Medium · 57 min read · Browsers, CSS, Frontend, WebAssembly, Accessibility
  Safari 27 beta ships 58 new features, 525 fixes and 4 deprecations, with most of the work going into correctness, edge cases, cross-feature interactions and alignment with web standards and other browsers.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
