The CSS :has pseudo-class is a new and powerful tool that enables styling of parent elements based on their children, working in a 'bottom-up' fashion. This capability opens up numerous possibilities, such as cleaner state-based styling and global event detection without JavaScript. Although it offers compelling advantages, its current 92% browser support necessitates fallback strategies. Practical examples demonstrate :has's ability to solve complex problems effortlessly, although in some cases JavaScript may still be more suitable. The post also showcases practical applications and experiments to highlight its versatility and utility.

14m read timeFrom joshwcomeau.com
Post cover image
Table of contents
Table of ContentsLink to this heading The basicsLink to this heading Browser supportLink to this heading Styling based on statesLink to this heading Global detectionLink to this heading The missing selectorLink to this heading The best tool for the job
17 Comments

Sort: