Course offer · HLD · LLD · System Design at ₹799 until 30 Nov (not interview packs)

CSS Studio

Interactive Learning

On this tool

IDs beat classes, and classes beat elements. !important skips the cascade and makes later debugging harder — prefer higher specificity or better structure.

Selectors

CSS Selectors, Specificity & Cascade

Selectors decide which nodes your CSS touches. This playground pairs a live DOM tree with a selector input so tag, class, id, combinators, attributes, and pseudo-classes become visible instead of abstract. Type .card or article > p and watch matches light up. Then compare two competing rules in the specificity calculator — (a, b, c) shows IDs, classes, and elements so you can explain why one declaration wins. Practice :nth-child, :not, and ::before here before you debug production stylesheets.

What people get wrong

IDs beat classes, and classes beat elements. !important skips the cascade and makes later debugging harder — prefer higher specificity or better structure.

What does specificity (1, 2, 0) mean?
One ID, two classes or attributes, and zero elements. Higher left-to-right numbers win. Equal specificity means the later rule in the stylesheet wins.

Live selector

0 matches

Specificity calculator

Rule B wins with (0, 2, 1) over (0, 1, 0).

Generated CSS
From the controls
Loading editor…

Selectors lab

First paragraph.

Second paragraph with a link.

  • One
  • Two
  • Three
<article id="post" class="card featured">
  <h2 class="title">Selectors lab</h2>
  <p class="lead">First paragraph.</p>
  <p>Second paragraph with a <a href="#" class="link">link</a>.</p>
  <ul class="list">
    <li>One</li>
    <li class="active">Two</li>
    <li>Three</li>
  </ul>
  <form>
    <label>Email <input type="email" name="email" /></label>
    <label>Name <input type="text" name="name" /></label>
    <button type="submit">Save</button>
  </form>
</article>