CSS Pseudo-classes & Pseudo-elements Reference

Complete reference for special selectors and generated content

About This Reference

Pseudo-classes (with single colon :) select elements based on their state or position in the document tree. They allow you to style elements when they're being hovered, focused, checked, or based on their position among siblings.

Pseudo-elements (with double colon ::) create virtual elements or target specific parts of elements. They let you insert generated content, style the first letter or line, customize form elements, and more.

This comprehensive reference lists all standard CSS pseudo-classes and pseudo-elements with links to official W3C specifications. For hands-on tutorials with live examples, see the related lessons below.

Pseudo-classes

Pseudo-classes (single colon) select elements based on their state or position

User Action Pseudo-classes

Selector Description Links
:hover Element is being hovered by pointer
:active Element is being activated (clicked)
:focus Element has keyboard focus
:focus-within Element or descendant has focus
:focus-visible Focus should be visible (keyboard navigation)

Child Position Pseudo-classes

Selector Description Links
:first-child First child of parent
:last-child Last child of parent
:only-child Only child of parent
:nth-child(n) Nth child (1-indexed, supports An+B notation like 2n, 3n+1)
:nth-last-child(n) Nth child from end

Type Position Pseudo-classes

Selector Description Links
:first-of-type First sibling of its type
:last-of-type Last sibling of its type
:only-of-type Only sibling of its type
:nth-of-type(n) Nth sibling of its type
:nth-last-of-type(n) Nth sibling of type from end

Form State Pseudo-classes

Selector Description Links
:enabled Enabled form element
:disabled Disabled form element
:checked Checked checkbox or radio button
:indeterminate Indeterminate state checkbox
:required Required form field
:optional Optional form field
:valid Form element that passes validation
:invalid Form element that fails validation
:user-valid Valid after user interaction (avoids red borders on page load)
:user-invalid Invalid after user interaction (better UX than :invalid)
:in-range Input value is within range constraints
:out-of-range Input value is outside range constraints
:read-only Read-only input element
:read-write Editable input element
:placeholder-shown Input currently showing placeholder text
:blank Input or textarea with empty value (distinct from :empty)
:autofill Input autofilled by browser
:default Default form element in group

Structural Pseudo-classes

Selector Description Links
:root Document root element (usually <html>)
:empty Element with no children (including text nodes)

Functional Pseudo-classes

Selector Description Links
:not(selector) Elements NOT matching selector
:is(selector) Matches any of the selectors (forgiving selector list)
:where(selector) Like :is() but with 0 specificity
:has(selector) Parent/previous sibling selector (relational selector)

Language & Direction Pseudo-classes

Selector Description Links
:lang(code) Element in specified language
:dir(ltr|rtl) Element directionality (left-to-right or right-to-left)

Display State Pseudo-classes

Selector Description Links
:fullscreen Element currently in fullscreen mode
:modal Element in modal state (dialog)
:open Details or dialog element in open state
:popover-open Popover element currently in showing state
:picture-in-picture Element in picture-in-picture mode
:playing Media element that is playing (limited browser support)
:paused Media element that is paused (limited browser support)

Scoping Pseudo-classes

Selector Description Links
:scope Reference element for scoping selectors
:host Shadow DOM host element
:host(selector) Shadow host matching selector
:host-context(selector) Shadow host with ancestor matching selector

Other Pseudo-classes

Selector Description Links
:defined Custom element that has been defined
:current Currently displayed element in timed media (e.g., WebVTT captions)
:past Element occurring before current in timed media
:future Element occurring after current in timed media

Page Pseudo-classes

Selector Description Links
:first First page of a printed document
:left Left-hand pages in duplex printing
:right Right-hand pages in duplex printing

Pseudo-elements

Pseudo-elements (double colon) create virtual elements or target specific parts of elements

Generated Content

Selector Description Links
::before Insert generated content before element's actual content
::after Insert generated content after element's actual content
::marker Style list item marker or bullet

Text Fragments

Selector Description Links
::first-letter First letter of block-level element
::first-line First formatted line of block-level element

User Selection

Selector Description Links
::selection Text selected/highlighted by user
::target-text Text targeted by URL text fragment (scroll-to-text highlighting)

Form Elements

Selector Description Links
::placeholder Placeholder text in input or textarea
::file-selector-button Button in file input element

Dialog & Modal

Selector Description Links
::backdrop Backdrop for fullscreen or dialog elements
::details-content Content of details element (enables animation of disclosure widget)

Media Elements

Selector Description Links
::cue Style WebVTT video captions/subtitles

View Transitions

Selector Description Links
::view-transition Root of view transition overlay tree
::view-transition-group(name) Single view transition group container
::view-transition-image-pair(name) Container for old and new view images
::view-transition-old(name) Snapshot of old view state
::view-transition-new(name) Live representation of new view state

Shadow DOM

Selector Description Links
::slotted(selector) Elements placed into a shadow DOM slot
::part(name) Shadow DOM part exposed for styling

Resources & Tools

Demo