toolqik

197 · CSS

CSS Selector Tester

Test a CSS selector against your HTML: see which elements match and its specificity.

Runs in your browser

About this tool

Type a selector and paste some HTML to see exactly which elements it matches, highlighted in a tree of the document. The specificity of each selector in the list is shown and explained, so you can see why one rule beats another.

Specificity in one minute

When two rules set the same property on an element, the one with the higher specificity wins (if they tie, the later one wins). Specificity is three numbers, compared left to right:

  • A, IDs: #header.
  • B, classes, attributes and pseudo-classes: .btn, [type="text"], :hover.
  • C, elements and pseudo-elements: div, ::before.

So #nav a (1,0,1) beats .menu .item a (0,2,1), however many classes there are. The universal selector * and combinators add nothing. :is(), :not() and :has() take the specificity of their most specific argument, while :where() always counts zero, which makes it perfect for easily overridden defaults. Inline styles and !important sit above all of this, and cascade layers (@layer) are compared before specificity.

Testing safely

The HTML is parsed into an inert document: scripts don’t run and images don’t load. Matching uses your browser’s own querySelectorAll, so results are exactly what your CSS and JavaScript will get.

FAQ

How do I test a CSS selector?

Type the selector, paste your HTML, and matching elements are highlighted in the tree with a count. Invalid selectors are reported.

How is specificity calculated?

Count IDs (A), then classes, attributes and pseudo-classes (B), then elements and pseudo-elements (C). Compare A first, then B, then C.

What is the specificity of :where()?

Zero. Whatever is inside :where() adds nothing, so rules using it are easy to override.

Does it support :has()?

Yes, if your browser does. All current browsers support :has().

Why don’t pseudo-elements match anything?

Pseudo-elements like ::before aren’t elements in the DOM, so querySelectorAll can’t return them. Their specificity is still shown.

esc
↑↓ navigate↵ open