Back to CSS Universe

foundation

Selectors & Specificity

Understand how selectors target elements and how specificity resolves conflicts.

selectorsspecificitycascade

Learning checklist

  • Pseudo-classes & pseudo-elements
  • Specificity math and the cascade
  • :is(), :where(), and :has()

Definition

Understand how selectors target elements and how specificity resolves conflicts.

Syntax

Pseudo-classes & pseudo-elements

Example

Use the visualizer below to apply these properties and see the result live.

Deep dive

Why this matters

Principles, mental models, and debugging clues tailored to the topic.

Visual intuition

Each property is paired with motion or color feedback so you build muscle memory, not just recall syntax.

Copy-ready CSS

Controls emit exact CSS you can copy. Use it as a starter token or paste into DevTools for instant validation.

Performance notes

Learn where reflow, repaint, or compositing occurs so you avoid jank and choose GPU-friendly paths.

Accessibility first

Focus-visible, reduced-motion, and contrast tips are woven into every lab to keep experiences inclusive.

Practice

Try recreating a UI card using this topic. Toggle between dark and light modes to validate token contrast and responsiveness.

Tip: use DevTools overlays (grid/flex) plus the copy CSS button.

Interactive Lab

Selectors & Specificity

Pick a selector to highlight matched nodes and see its specificity tuple.

Specificity: (0, 2, 2) — ids, classes/pseudo-classes, elements.

Hero title

A subtitle under the hero.

badge

This is a card title

  • Item one
  • Item two
  • Item three
HTML
<section class="hero">
  <h3 class="title">Hero title</h3>
  <p class="subtitle">A subtitle under the hero.</p>
  <button id="cta" class="btn">Call to action</button>
</section>
<section class="card">
  <div class="badge">badge</div>
  <p class="title">This is a card title</p>
  <ul class="list">
    <li>Item one</li>
    <li>Item two</li>
    <li>Item three</li>
  </ul>
  <nav class="nav">
    <a href="#">Link A</a>
    <a href="#">Link B</a>
  </nav>
</section>
.card .title { outline: 2px solid #f59e0b; background: #fef3c7; color: #0f172a; }

Related topics

Keep exploring adjacent concepts.

foundation

Cascade & Inheritance

Dive deep into the cascade layers, inheritance rules, and how importance is calculated.

View page