DevPrep
  • Interview Prep
  • Projects
  • Resources
  • Pricing
  • About Us
Submit Question
DevPrep
  • Pricing
  • About Us
Submit Question
← From Beginner to Expert in Fundamentals of Frontend
  • The Box Model
  • Specificity & The Cascade
  • CSS Units Deep Dive
  • Stacking Contexts & Z-Index
  • Flexbox Mastery
  • CSS Grid Mastery
  • Centering, Subgrid & Container Queries
  • CSS Custom Properties & Variables
  • Selectors: :has(), Pseudo-classes & Pseudo-elements
  • Responsive Functions: calc(), clamp(), min(), max()
  • Media Queries & Mobile-First Design
  • Transitions & Animations
  • Transforms, Filters & Clipping
  • CSS Methodologies: BEM, CSS-in-JS & Tailwind
  • Typography, Color Spaces & Dark Mode
  • CSS Performance & Optimization
  • CSS Interview Questions — Part 1
  • CSS Interview Questions — Part 2
← From Beginner to Expert in Fundamentals of Frontend

Selectors: :has(), Pseudo-classes & Pseudo-elements

18 min read
:has():nth-child:not():is():where()::before::after:focus-visiblePseudo-classesPseudo-elements

Advanced CSS Selectors

The :has() Revolution

:has() is the "parent selector" CSS developers waited 20 years for. It selects an element based on what it contains.

Pseudo-classes vs Pseudo-elements

TypeSyntaxWhat It DoesExamples
Pseudo-classSingle colon :Selects elements in a specific state:hover, :focus, :nth-child()
Pseudo-elementDouble colon ::Creates a virtual element::before, ::after, ::placeholder

Key Pseudo-classes

SelectorSelects
:nth-child(2n)Every even child
:nth-child(3n+1)Every 3rd, starting from 1st
:nth-of-type(2)2nd element of its type
:not(.active)Elements WITHOUT .active class
:focus-visibleFocused by keyboard (not mouse)
:focus-withinParent when any child is focused
:emptyElements with no children/text
:checkedChecked checkboxes/radios
:disabledDisabled form elements
:placeholder-shownInputs showing placeholder text

Key Pseudo-elements

SelectorCreates
::beforeVirtual element before content
::afterVirtual element after content
::placeholderStyles input placeholder text
::selectionStyles highlighted/selected text
::markerStyles list item bullets/numbers
::first-lineStyles first line of text
::first-letterStyles first letter (drop caps)

Practice

  • JavaScript
  • DSA
  • Machine Coding
  • System Design

Resources

  • Learning Tracks
  • Articles
  • Roadmaps
  • Compare Concepts
  • Glossary
  • Developer Tools
  • All Questions

Company

  • About
  • Pricing

Legal

  • Privacy Policy
  • Terms of Service
DevPrep

© 2026 DevPrep. All rights reserved.