Skip to main content

CSS Selector Tester

Test CSS selectors against HTML: matches, specificity, DOM paths and a highlighted preview.

Runs with your browser's selector engine as you type.

HTML source

Size: 0 B

Results

Checking…
Paste HTML and enter a selector to find matching elements.

Matching uses your browser's selector engine on a parsed copy of the HTML; scripts in the HTML never run and nothing is uploaded.

How to use

  1. 1.Paste HTML into the HTML source editor, or load an example.
  2. 2.Type a CSS selector. Results update as you type.
  3. 3.Check the chips: valid or invalid, match count and specificity. A selector list shows the specificity of each part.
  4. 4.In Matches, copy an element's HTML or its DOM path, or select a match to highlight it in Preview.
  5. 5.Read the notes under the summary when a selector matches less than expected.

CSS Selector Tester

The selector runs with your browser's own engine (querySelectorAll) on a parsed copy of the HTML, so the result is what document.querySelectorAll returns in this browser, including :has(), :is() and :where() where supported. Specificity is calculated from the parsed selector, not from its text: IDs, then classes, attributes and pseudo-classes, then types and pseudo-elements. Each match lists a short DOM path that is checked to select exactly that element. The tool also explains common surprises: pseudo-elements and hover or focus states never match, duplicate ids, and elements the HTML parser inserts, such as tbody inside tables.

Specificity rules
  • •Specificity is written (a,b,c): a counts IDs, b counts classes, attributes and pseudo-classes, c counts type selectors and pseudo-elements. The universal selector and combinators add nothing.
  • •:where() always adds zero.
  • •:is(), :not() and :has() add the specificity of their most specific argument.
  • •:nth-child(An+B of S) adds one pseudo-class plus the most specific selector in S.
  • •For a selector list, each selector has its own specificity; the summary shows the highest.
Privacy

Everything runs in your browser. The HTML and selectors are never uploaded, logged or saved, and scripts in the HTML never run.

Frequently asked questions
Which selector engine does the tester use?
Your browser's own engine. The HTML is parsed with DOMParser and the selector runs with querySelectorAll on that parsed copy, so support for :has(), :is() and newer syntax is exactly what your browser supports.
Why does table > tr match nothing?
The HTML parser inserts a tbody element around table rows that are not already inside thead, tbody or tfoot. Use table > tbody > tr or table tr. The tester shows a note when the parser inserted tbody.
How is specificity calculated for :is(), :not(), :has() and :where()?
:where() always adds zero. :is(), :not() and :has() add the specificity of their most specific argument. For a selector list, each selector keeps its own specificity and the summary shows the highest.
Do scripts in my HTML run in the preview?
No. The preview is a sandboxed frame without script permission, built from a sanitized copy with a policy that blocks every network request. Scripts, frames, form actions, event handlers and link destinations are removed.

CodingTool is officially live on