Home › Developer Tools › CSS Selector Tester

CSS Selector Tester

Paste some HTML, type any CSS selector and instantly see which elements it matches, highlighted in the rendered page and in the source tree, plus the match count and the selector's specificity.

Last updated:

0matches
HTML

Scripts never run and external images/styles are not loaded. Your HTML stays in your browser.

Matched elements

    Advertisement
    Advertisement

    How to use the CSS Selector Tester

    1. Paste your HTML into the HTML box or upload an .html file. The sample page loads by default.
    2. Type a CSS selector, for example .card > h3 or li:nth-child(odd), or click one of the example chips.
    3. Check the result: the counter shows how many elements match and matched elements get an orange outline in the preview.
    4. Switch to Source to see the parsed DOM tree with each match numbered, and click any match in the list to jump to it.
    5. Read the specificity boxes (ID, class, type) to understand which rule wins in your stylesheet.

    CSS selector quick reference

    SelectorMatchesSpecificity
    pEvery <p> element0, 0, 1
    .priceElements with class="price"0, 1, 0
    #main-navThe element with id="main-nav"1, 0, 0
    [data-price], a[href^="https"]Has the attribute / attribute starts with0, 1, 0 / 0, 1, 1
    nav aAny <a> inside <nav> (descendant)0, 0, 2
    ul > li<li> that are direct children of <ul>0, 0, 2
    h2 + pThe <p> right after an <h2>0, 0, 2
    h2 ~ pAll <p> siblings after an <h2>0, 0, 2
    li:nth-child(2n+1)Odd list items (1st, 3rd, 5th…)0, 1, 1
    p:not(.intro)Paragraphs without class "intro"0, 1, 1
    .card:has(img)Cards that contain an image0, 1, 1
    :where(h2, h3)Any h2 or h3, with zero specificity0, 0, 0
    p::first-linePseudo-element (not selectable by querySelectorAll)0, 0, 2

    How specificity decides which rule wins

    When two rules set the same property on the same element, the browser compares their specificity from left to right: the selector with more IDs wins; if tied, the one with more classes, attributes and pseudo-classes wins; if still tied, the one with more type selectors and pseudo-elements wins. If the specificity is identical, the rule that appears later in the CSS wins. Inline style attributes beat any selector, and !important overrides normal declarations regardless of specificity.

    A practical tip: keep specificity low and flat (mostly single classes) so components are easy to override, and use :where() for defaults that should be trivial to replace.

    Why the source can differ from what you pasted

    The Source tab shows the DOM the browser actually built, not your raw text. HTML parsers add missing <html>, <head>, <body> and <tbody> elements, close unclosed tags and move invalid nesting (a block element inside a <p> ends the paragraph). Selectors run against that DOM, so this view explains most "why doesn't it match" surprises.

    Frequently asked questions

    How does the CSS selector tester work?

    Your HTML is parsed by the browser into a sandboxed preview, and the selector is run with document.querySelectorAll, the same engine your stylesheets and JavaScript use. Every matching element is outlined and listed.

    How is CSS specificity calculated?

    Specificity is three numbers (A, B, C). A counts ID selectors, B counts classes, attribute selectors and pseudo-classes, and C counts type selectors and pseudo-elements. The universal selector * and combinators add nothing. :is(), :not() and :has() take the specificity of their most specific argument, and :where() always counts as zero. Higher A wins, then B, then C.

    Why does my selector match nothing?

    Common causes are a typo in a class name, a missing combinator (a space means descendant, > means direct child), or HTML that the parser rewrites: for example a <div> inside a <p> closes the paragraph, and tables get an automatic <tbody>. Open the Source tab to see the DOM exactly as the browser built it.

    Do :hover and :focus work here?

    State pseudo-classes such as :hover, :focus and :active only match while the user interacts with the element, so in a static test they normally match nothing. Structural and attribute-based pseudo-classes like :checked, :disabled, :required, :empty and :nth-child() work fully.

    Is :has() supported?

    Yes, if your browser supports it (Chrome, Edge, Safari and Firefox 121 or newer). The tester uses your browser's native engine, so an unsupported selector shows an invalid selector message.

    Is my HTML sent anywhere?

    No. Everything runs in your browser. The preview is a sandboxed frame that blocks scripts, forms and external images or stylesheets, so pasting untrusted HTML is safe.

    Are all the tools on FreeToolCabin tested for quality and accuracy?

    Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.

    Related tools

    CSS Specificity CalculatorCalculate CSS selector specificity (a, b, c), including :is(), :not(), :has() and :where(), and compare.HTML FormatterBeautify and indent HTML code with a live preview.HTML Editor (Live Preview)Write HTML, CSS and JavaScript and see a live, sandboxed preview as you type.Regex TesterTest and debug regular expressions live.Online Python CompilerRun Python 3 in your browser with input(), numpy, pandas, charts and share links.JSON EditorEdit JSON in a tree and as code side by side: add, rename, drag, change types, undo and download.Unzip FilesOpen and extract ZIP files online.RAR & 7z ExtractorOpen RAR, 7z and other archives online and extract files.File Info ViewerCheck file size, type, date and MD5/SHA hashes.SQLite ViewerOpen .db and .sqlite files in your browser, browse tables and run SQL queries.DOCX ViewerOpen and read Word .docx files in your browser, then print or save them as HTML.EPUB ReaderOpen and read EPUB e-books in your browser with pages, a table of contents and font controls.What Is My BrowserSee your browser, version, OS, engine, screen and which web features it supports.Font ViewerPreview TTF, OTF, WOFF and WOFF2 fonts with sample text, waterfall, glyphs and metadata.Markdown EditorWrite Markdown with a toolbar, live split preview, autosave and .md or HTML export.Regex Cheat Sheet75+ ready-to-use regex patterns for emails, URLs, IPs and dates, each with a live test box.JavaScript Keycode FinderPress any key to see its JavaScript key, code, keyCode, which, location and modifiers.QR Code ScannerScan QR codes with your camera or from an image and safely read the link or text.RAID CalculatorUsable capacity, efficiency and fault tolerance for RAID 0, 1, 5, 6, 10, 50 and 60 arrays.JSONPath TesterTest JSONPath expressions live: filters, slices, wildcards and recursive search, with matches highlighted.Mermaid Diagram EditorWrite Mermaid code and see flowcharts, sequence, Gantt and ER diagrams live. Export SVG or PNG.Country Codes ListSearch ISO 3166 alpha-2, alpha-3 and numeric country codes with calling codes and TLDs.Git Cheat SheetSearchable Git command reference by task, with copy buttons and an undo/rename/fix wizard.HAR File ViewerOpen a .har file to see a waterfall timeline, headers, bodies, timings and size totals.jq PlaygroundRun jq filters on JSON in your browser with live output, flags and an example library.Markdown Cheat SheetInteractive Markdown syntax reference: edit every example and see the live rendered preview.Regex ExplainerPaste a regular expression and get a plain-English breakdown, railroad diagram and flag notes.XPath TesterTest XPath expressions on XML or HTML: highlighted matches, node paths, values and examples.EML File ViewerOpen .eml email files to read the message, headers and raw source and save attachments.Graphviz Online ViewerWrite Graphviz DOT code and render graphs live; switch layout engines, export SVG or PNG.JavaScript Online CompilerWrite and run JavaScript in your browser with a console, timing, error lines and share links.Jupyter Notebook ViewerOpen .ipynb files and read code, Markdown, math, tables, plots and errors without Python.LaTeX Table GeneratorEdit a table like a spreadsheet or paste from Excel and get LaTeX tabular or booktabs code.Log File ViewerOpen huge log files with level colors, regex and time filters, JSON pretty-print and tail -f.Logic Gate SimulatorBuild logic circuits with AND, OR, NOT, XOR gates and flip-flops; see live outputs and truth tables.MSG File ViewerOpen Outlook .msg emails in your browser: sender, recipients, body, headers and attachments.Online Code EditorVS Code-style editor in your browser: tabs, 50+ languages, find/replace, autosave.Online Hex EditorOpen any file as hex and ASCII, edit bytes, search, inspect values and save the result.XSLT TesterRun an XSLT 1.0 stylesheet on XML in your browser and see the output as HTML, XML or text.ASCII Diagram EditorDraw boxes, arrows and text on a character grid and copy plain-text diagrams for code and READMEs.DBF File ViewerOpen dBase .dbf files and shapefile tables, search and sort records, export CSV or XLSX.MBOX File ViewerOpen .mbox mail archives: list and search messages, read them, save attachments, export EML.MDB File ViewerOpen Access .mdb and .accdb databases in your browser: list tables, view rows, export CSV.Shapefile ViewerView zipped shapefiles on a map with the attribute table, then export to GeoJSON or CSV.PHP Online CompilerRun PHP 8 code in your browser with output, HTML preview, error lines and share links.PlantUML EditorWrite PlantUML and see sequence, class, activity and more diagrams live. Export SVG or PNG.Sorting Algorithm VisualizerWatch bubble, insertion, merge, quick, heap and radix sort step by step with live counters.Lottie ViewerOpen Lottie JSON or .lottie files to play, pause, scrub frames, change speed and see details.Diff ViewerPaste a git diff or .patch file and view it side by side or inline, with file navigation.EditorConfig GeneratorBuild an .editorconfig with indent, charset, line endings and trim rules per file pattern.Folder Compare ToolCompare two folders by file list, size and SHA-256 hash, then open a text diff of changed files.Glob Pattern TesterTest glob patterns like **/*.js, {a,b} and !exclusions against a list of file paths.JMESPath TesterEvaluate JMESPath expressions against JSON live, the query language used by the AWS CLI.MongoDB Query TesterTest MongoDB find filters, projections and aggregation pipelines on sample JSON documents.Semantic Version CalculatorBump, compare, sort and test SemVer versions against npm ^, ~ and x ranges.
    See all 53 Code Playgrounds & Testers →