CSS Selector Tester
See What Your Selector Matches
This css selector tester takes your markup and your selector, then shows every element the selector reaches. So you read the matches instead of guessing at them. The work happens in your browser, and we upload nothing.
- FreePrice
- FiveModes
- NoneSign-up
- NoneUploads
CSS Selector Tester
Run a selector on your own markup and see exactly what it reaches
- Elements matched
- —
Ready. Paste some markup, type a selector and the matches appear.
What A CSS Selector Tester Does
A selector is a question about your markup. This css selector tester answers it in front of you, so the guesswork goes away. Paste the markup, type the selector, and read the elements it reached.
Four questions cover most of the work. First, which elements does this selector match? Then, what does the selector actually say in plain words? After that, how strong is it against a rival rule? Finally, what is the shortest selector for one element you can point at?
This is not a stylesheet tool. Because shrinking and tidying CSS belongs to another job, the CSS minifier handles that side. Here the subject is matching, and nothing else.
Nothing to install. Therefore you paste a fragment, read the answer, and close the tab when it suits you.
How A CSS Selector Tester Works
The work splits into three passes. First, the page reads your markup into a tree of tags and attributes. Then that tree is rebuilt as real elements that never join the page. Finally, your selector runs against the rebuilt copy, and the matches come back in document order.
The matcher is the browser's own. Because the Selectors Level 4 rules are long and full of corner cases, a hand-written engine would disagree with real pages sooner or later. So this page asks the engine that already ships in your browser, since the same engine will judge your site.
The rebuilt copy stays detached. As a result it has no styles, no scripts and no layout. That is deliberate, since the question here is which elements a selector reaches, not what they would look like.
Test A Selector Against Your Own Markup
A selector that works in a tutorial can still miss your markup. Therefore the honest test is your own fragment, pasted as it is. Copy a block out of the page source and drop it in.
![Screenshot of the css selector tester in match mode: a pasted navigation fragment on the left holding three list items, the selector .list .item a[data-track] on the right, a count reading 2 of 8, and the two matched links listed underneath, each with its own path down through the tree so the pair can be told apart](/wp-content/themes/denwix/assets/img/tools/cssel-match.webp?v=3.123.4)
Each match arrives with its context. So you get the count first, then every matched element with its opening tag, and the path that leads to it from the top of the fragment.
The path is the useful part. Because two matches often look identical, the path shows which one is which. After that, a selector that catches one element too many is easy to narrow.
An empty result is still an answer. Yet it is the answer people miss, so the page says plainly that nothing matched rather than showing a blank box.
What Gets Dropped Before Matching
This tool treats your paste as text, never as a page. So the rebuild leaves out script and style tags, iframes and embeds entirely.
Event attributes go the same way. Because an onclick or an onerror only matters to a live page, the rebuild drops them with the tags that carried them. A javascript: address in an href loses its tag too.
The rest survives untouched. Therefore your classes, ids, data attributes and nesting are all still there for the selector to match on.
jQuery Selector Tester Without jQuery
Half the selectors people paste are not CSS at all. Instead they come from jQuery, which added its own shapes such as :first, :eq() and :contains(). A plain css selector tester would simply refuse them.

This one answers them anyway. Because those shapes resolve to a position or a text test over a match list, the page applies them itself after the CSS part has run. So a jquery selector tester lives here without a line of jQuery on the page.
The page shows the translation instead of hiding it. Therefore you see which part was standard CSS and which part the page handled afterwards. That way a selector you are porting to plain querySelectorAll holds no surprises.
Some shapes have no equivalent. Still, the page names them instead of pretending, which is the only useful thing to do with a selector nothing can match.
Where :first And :eq Differ From CSS
The traps are the ones that look harmless. For example :first picks one element out of the whole match list, while :first-child and :first-of-type ask about an element's position among its siblings.
That difference bites on real markup. Because a list of ten items has ten first-of-type candidates in ten different parents, yet only one of them is the list's first match. So the two forms answer different questions.
CSS Specificity Calculator
Matching is only half of a rule's story. The other half is strength, which the cascade settles by counting the parts of a selector. So this css specificity calculator reports that count as the three numbers browsers actually use.

The three numbers are easy to read. First come id selectors, then classes, attributes and pseudo-classes, and finally element names and pseudo-elements. After that the comparison is a simple left to right one.
Inline styles and important sit outside the triple. However, the page says where they land, because a rule that loses on paper can still win in the browser for one of those two reasons.
The specificity rules reward short selectors. Therefore a selector that scores lower is often the better one to ship, since it stays easy to override later.
Which Of Two Selectors Wins
Paste two selectors and the answer is immediate. Because both triples appear side by side, the winner is visible without counting anything by hand.
The page calls a tie a tie. Then the rule that appears later in the stylesheet wins, and the page says so rather than leaving you to remember it.
Read A Selector In Plain English
A long selector hides its own meaning. So the page reads it back as a sentence, part by part, in the order the browser applies them.

The reading needs no markup at all. Because the explanation comes from the selector's own structure, you can check a selector from a code review before you have the page it belongs to.
Combinators are where people slip. Therefore a space, a greater-than sign, a plus and a tilde are each named in words, since descendant, child, next sibling and later sibling are four different questions.
The same habit helps with markup you did not write. After a quick read of the selector, a glance at the HTML minifier output or the page source usually explains the rest.
A Selector For One Element
Sometimes the element comes first and you need the selector for it. So you pick a node in the parsed tree, and the page offers the shortest selector that reaches only that element.
Short is the goal, not clever. Because an id alone is often enough, the page tries that first, then a class, and only then a path through the parents.
What This Page Will Not Do
It will not run your JavaScript. Since the rebuilt copy is inert on purpose, a selector that depends on a script having run will not match here.
It will not match state. However, that is a property of any detached markup: hover, focus, visited and target describe a live page, so they stay empty.
It will not style anything. A selector tester answers which elements, and the look of those elements is a separate question for the browser you ship to.
Using The CSS Selector Tester, Step By Step
Four steps turn a selector you are unsure about into a list you can read.
- 1
Paste your markup
A fragment is enough, and a whole page works too.
- 2
Type the selector
The match count updates as you type, so a typo shows at once.
- 3
Read the matches
Each matched element arrives with its opening tag and its path.
- 4
Check the strength
The specificity triple tells you how hard the rule will be to override.
What This CSS Selector Tester Does Differently
The browser's own matcher, jQuery shapes without jQuery, and nothing ever goes live.
It uses the real matcher
Your browser answers the selector, so the result matches the one your site will get.
It never runs your markup
The rebuild drops scripts, styles and event attributes before the selector runs.
It speaks jQuery too
The page resolves the :first, :eq and :contains shapes without loading a library.
It counts specificity
Every selector gets its triple, and two selectors can be compared directly.
It explains itself
The page reads a long selector back as a sentence, combinator by combinator.
It stays in your browser
Unreleased markup never leaves your machine, because nothing is uploaded.
Getting A Selector Right First Time
A few habits keep a selector short and stable.
- Test on real markup Paste the fragment from your own page, since a tidy example hides the awkward cases.
- Prefer the lowest score A selector that wins by one class is easier to override than one that wins by an id.
- Name the combinator on purpose A child selector says what a descendant selector only implies, so reach for it when you mean it.
- Check the count, not the first match A selector that reaches four elements when you wanted one still looks correct at the top.
Common Mistakes When Writing A Selector
Each of these matches something, just not the thing you meant.
Treating :first as :first-child
One picks a single match from the list, and the other asks about every parent in turn.
Leaning on an id for strength
An id wins today and blocks every override tomorrow, so a class is usually the better tool.
Forgetting that a space means descendant
A stray space between two parts turns one question into a much broader one.
Quoting an attribute value wrongly
A value with a space or a hyphen needs quotes, otherwise the selector is simply invalid.
Testing against markup you tidied first
The wrapper you removed by hand is often the one the real selector depends on.
CSS Selector Tester FAQ
What is a CSS selector tester?
It is a page that takes your markup and a selector, then shows every element the selector matches. So instead of reloading a site to see whether a rule applied, you read the answer directly.
Does my markup leave my browser?
No. The parsing, the rebuild and the matching all happen on your machine. Therefore unreleased markup stays private, and no server sees the fragment you pasted.
Which selectors are supported?
Everything your browser supports, because the browser does the matching. That covers the Selectors Level 4 set, including :is, :where, :not and :has on current browsers.
Why does :hover never match?
Because the rebuilt markup is detached, nobody can hover over it. The same goes for focus, visited and target, since all four describe a live page rather than a document structure.
Can I test jQuery selectors here?
Yes. The jQuery-only shapes such as :first, :eq() and :contains() are resolved after the CSS part has run. So the page works as a jquery selector tester without loading jQuery.
What does the specificity triple mean?
The three numbers count id selectors, then classes with attributes and pseudo-classes, then element names. A browser compares them left to right, and the first difference decides the winner.
Where do inline styles fit?
They sit above every selector in the cascade, so no triple beats them. An important declaration sits above that again, which is why the page names both instead of scoring them.
Does a longer selector always win?
No. Length does not matter, only the parts do. Therefore ten element names still lose to a single class, however long the selector looks.
Why do two rules with the same score behave differently?
Because a tie is broken by order. The rule that appears later in the stylesheet applies, so moving a block can change the page without changing a selector.
Is this a CSS validator?
No. A validator checks a whole stylesheet against the grammar. This page answers one selector at a time, although it will tell you when a selector is invalid.
Can I paste a whole page?
Yes. A full document works, and so does a single element. Still, a smaller fragment makes the match list easier to read.
What happens to script tags in my markup?
They are dropped before the rebuild, along with styles, iframes and embeds. Because nothing is ever added to the live page, a pasted script has nothing to run in.
Why does my selector match nothing?
Usually a parent is missing from the fragment. A descendant selector needs the ancestor too, so copy one level further up and try again.
Does the tester change my markup?
It leaves your text alone in the box. The rebuilt copy drops the unsafe tags, yet your classes, ids, data attributes and nesting all survive for matching.
How is this different from an XPath tester?
XPath asks questions of XML with a path language, and CSS selectors ask questions of markup with a much shorter syntax. The <a href="/xpath-tester/">XPath tester</a> covers the first job.
Can I get a selector for an element I can see?
Yes. Pick the node in the parsed tree and the page offers the shortest selector that reaches only it. So an id is tried first, then a class, then a path.
Does it handle attribute selectors?
All of them, including the prefix, suffix and substring forms. Remember that a value containing a space or a hyphen has to be quoted.
Will :has slow the page down?
Not here, because the fragment is small and detached. On a real site :has costs more than a class selector, so measure before you lean on it.
Can I use this for querySelectorAll in JavaScript?
Yes, and that is the honest match. Because querySelectorAll uses the same matcher, a selector that works here works in your script.
Why does the count update as I type?
So a typo shows itself immediately. A selector with a stray space usually drops to zero matches, which is faster feedback than a page reload.
Is there a limit on the markup size?
Only your machine. A page-sized fragment is matched in a moment, and the tree view stays usable well past that.
Do I need an account?
No. The css selector tester is free, it needs no sign-up, and it keeps nothing after you close the tab.
Handy Companions For Front End Work
One selector is a question. These three answer the neighbouring ones.
XPath Tester
Run a path expression against XML and read the nodes it returns.
Open tool →JSONPath Tester
Query a JSON document with filters, slices and functions.
Open tool →CSS Minifier
Shrink the stylesheet once the selectors inside it are right.
Open tool →
Ready To Test A Selector?
Paste your markup, type a selector, and read the elements it reaches. The css selector tester is free, needs no account, and nothing you paste ever leaves your browser.