Skip to content
Tools

CSS Selector Tester

Test CSS selectors against your own HTML and see what they match.

Local
Matches

What this tool does

This tool runs a CSS selector against the HTML you provide and lists every element it matches, with the element, its text and a snippet of its markup. It is a quick way to work out the right selector for a test before you put it in your automation code.

How it stays safe

Your HTML is parsed into an inert document. Scripts in it never run, images and other resources are never fetched, and nothing is sent anywhere. That means you can paste markup from a real page, including scripts and tracking tags, and only the structure is used to match your selector.

Selectors that make good locators

The same selector engine your browser uses powers this tool, so what matches here matches in Playwright, Cypress and Selenium. For stable tests, prefer selectors tied to meaning rather than layout: a data-testid, an id, a role or an accessible name. Long descendant chains and nth-child positions are brittle, because they break when the page is restyled or reordered.

Handy patterns

  • [data-testid="add-to-cart"] an attribute selector, the most stable choice.
  • .product:not(.out-of-stock) exclude a state with :not().
  • ul.cart > li direct children only.
  • a[href^="/products/"] match the start of an attribute value.

Frequently asked questions

Is my HTML uploaded or rendered?
No. It is parsed into an inert document in your browser. Scripts never run, no resources load, and nothing is sent anywhere.
Does this match what Playwright or Cypress will match?
Yes. It uses the same CSS engine your browser uses, which is the engine those tools rely on.

Learning resources

Testsmith also runs hands-on courses and a free practice app for the skills behind this tool.

Feedback welcome

Found a bug in this tool, or want it to do something it does not? Tell us and we will take a look.