Pseudo-Classes & Elements
Bring your interfaces to life without JavaScript! Style dynamic user states (hover, focus, active), target structural positions (:nth-child), and inject decorative virtual sub-elements (::before, ::after).
Moods vs Accessories
The difference between a pseudo-class and a pseudo-element is simple:
:pseudo-class (Single Colon) = The Mood/State
Describes the temporary condition or structural role of an existing element. The element didn't change; its mood changed!
::pseudo-element (Double Colon) = The Accessory
Creates or targets an invisible virtual sub-element. Like putting a hat (::before) or backpack (::after) on an element without writing extra HTML tags!
Why Does Link Hover Sometimes Fail? (The LVHA Order)
All link pseudo-classes have identical specificity (0, 0, 1, 0). If written in the wrong source order in your stylesheet, an active or visited style can permanently block hover effects!
Unvisited links.
Already clicked in history.
Mouse cursor over link.
Mouse button pressed down.
Master the An + B Math Formula
The :nth-child(An + B) formula matches elements in cycles: A is cycle size, B is starting offset. Try typing any formula or picking a preset:
Injecting Icons & Badges Without Extra HTML
The #1 rule of ::before and ::after: They MUST have content: ""! Without the content property, browsers will not generate the pseudo-element at all.
<span class="badge">New</span>The Infamous `:first-child` Trap
Why does `p:first-child` match nothing when an `<h1>` is present?
p:first-child does NOT mean "find the first paragraph inside the div". It means "Is this element a paragraph AND is it the very first child of its parent?"
p:first-of-type! It specifically scans for the first <p> element regardless of preceding headings!4. :is(), :where(), and :has()
Modern relational parent selectors and zero-specificity baseline reset functions.