Start a project

Tool 66 of 100 · CSS

CSS Selector & XPath Tester

Test a CSS selector or XPath against real HTML and see exactly what it matches, with a unique path for each element, for scrapers, tests and stylesheets.

CSS Selector & XPath Tester at a glanceIllustration: 1, HTML + a selector; 2, processed in your browser; 3, Matched elements.CSS Selector & XPath Tester</>1HTML + a selector3Matched elements2In yourbrowser
1 HTML + a selector 2 processed on your device 3 Matched elements

CSS Selector & XPath Tester

HTML

Selector

SelectorSpecificity (id, class, type)

Same selector as XPath

XPath equivalent

Matches

#ElementUnique path

01

What it does

Runs CSS selectors or XPath on pasted HTML, lists matches with unique paths, scores specificity and converts CSS to XPath.

  • CSS selectors including :has() and :is()
  • XPath 1.0 queries
  • Each match with a unique CSS path
  • Specificity of the selector

02

Private by design

Everything happens in your browser. Nothing you type, paste or upload is sent anywhere, and it keeps working offline once the page has loaded.

03

What you get

Matches, paths and an XPath version, with a Copy and a Download button on every result.

  • CSS
  • XPath
  • Testing
  • Scraping

Why it matters

End-to-end tests, scrapers and analytics tags all depend on selectors that pick exactly the right elements. A selector that matches one element today can match three after a redesign, and finding out in production is painful.

This tester runs your selector or XPath against pasted HTML in an inert document, so no scripts run and nothing loads, and lists every match. It also gives a unique path for each element and translates CSS into XPath for tools that only accept XPath.

How it works

  1. InputHTML and a CSS selector or XPath
  2. In your browserRun by the browser's own selector engine
  3. OutputMatches, specificity and the XPath version

Where it fits in a designer's workflow

  1. Plan
  2. Design
  3. Build
  4. Test
  5. Launch
Writing selectors for CSS, tests and scrapers.

By the numbers

Specificity of the example selectorsnav li.item:not(.active) > a: (0, 2, 3); a[href^='https']: (0, 1, 1); article[data-sku$='220'] h2: (0, 1, 2); h2 + p: (0, 0, 2)nav li.item:not(.active) > a(0, 2, 3)a[href^='https'](0, 1, 1)article[data-sku$='220'] h2(0, 1, 2)h2 + p(0, 0, 2)
Scored by this tool's own function. :not() takes the specificity of its argument, attribute selectors count like classes, and combinators like > and + add nothing. Source: Selectors Level 4: specificity.
Show the numbers as a table
SelectorIDsClassesElements
nav li.item:not(.active) > a023
a[href^='https']011
article[data-sku$='220'] h2012
h2 + p002

How to use it

  1. Paste the HTML of the page or component.
  2. Type a CSS selector or XPath, or pick an example.
  3. Read the matches and their paths.
  4. Copy the XPath version if your tool needs it.

FAQ

Does it run page scripts?

No. HTML is parsed into an inert document, so scripts don't run and images, styles and frames don't load.

Why does the live page match differently?

Scripts often add or change elements after loading. Paste the HTML from your browser's Elements panel to test the final page.

Can every CSS selector become XPath?

Most can. Pseudo-classes that depend on state (:hover, :checked) have no XPath equivalent and are flagged.

Which selectors are best for tests?

Ones based on roles, labels or data-testid attributes, which survive redesigns better than classes.

Work with me

Want a site that gets these right?

I build fast, accessible websites and web apps that pass these checks from day one. Tell me about your project and I'll reply personally with honest next steps.

All developer tools · Back to leej.uk