Rankite
ServicesResultsToolsTeamAboutBlogCareersContactFree SEO Audit
Free tool

CSS Specificity Calculator

Paste selectors, one per line, and see each one's ID, class and type count, ranked by which one wins.

Home / Tools / CSS Specificity Calculator
Specificity, ranked highest first

Format shown is (IDs, classes/attributes/pseudo-classes, types/pseudo-elements). The browser compares these three columns left to right, it never adds them into a single number.

Built by Rankite, the SEO team behind Swordfish AI's +400% revenue and Zluri's +45% organic growth. See the case studies

CSS specificity decides which rule wins when two or more selectors in your stylesheet target the same element with conflicting styles. Paste a few selectors into the calculator above, one per line, and it breaks each one down by ID count, class count and type count, then ranks them by which one the browser would apply.

The three columns of specificity

Specificity is not one number, it is three separate counts compared in order. The first column counts ID selectors like #header. The second column counts class selectors like .nav, attribute selectors like [type="text"], and pseudo-classes like :hover or :first-child. The third column counts type selectors like div or a, along with pseudo-elements like ::before. A browser compares two selectors by looking at the ID column first: whichever has more IDs wins outright, regardless of how many classes or types the other selector has. Only when the ID counts tie does the browser move on to compare the class column, and only when that ties too does it compare the type column.

What does not count

The universal selector * and combinators such as the child combinator >, the sibling combinators + and ~, and plain whitespace between selectors all add zero specificity. They change which elements a selector matches, not how strongly it wins against a competing rule. Two selectors can match the exact same element while having very different specificity, which is usually the actual cause of a style not applying the way you expected.

How :not(), :is(), :has() and :where() are scored

These functional pseudo-classes do not add a flat point the way :hover or :focus do. Instead, per the CSS Selectors specification, each one takes on the specificity of the single most specific selector inside its parentheses, not the sum of everything inside. The one deliberate exception is :where(), which the spec defines to always contribute zero specificity no matter what you put inside it, making it useful for writing default styles that are easy for anyone downstream to override. The calculator above applies this same logic rather than treating every pseudo-class as an equal flat 10 points. If your team is untangling a CSS codebase where specificity fights are slowing down every design change, that is exactly the kind of technical debt worth fixing before it compounds further, a free SEO audit often surfaces related front-end issues that are quietly costing you rankings too.

Related articles

FAQ

CSS Specificity Calculator: questions, answered

How is CSS specificity calculated?
CSS specificity is counted in three columns: ID selectors, then class selectors, attribute selectors and pseudo-classes together, then type selectors and pseudo-elements together. Each ID adds one point to the first column, each class, attribute or pseudo-class adds one point to the second column, and each type selector or pseudo-element adds one point to the third column. The browser compares selectors column by column, starting with IDs, never by adding the columns into one number.
Does the universal selector * count toward specificity?
No. The universal selector and combinators such as greater-than, plus, tilde and whitespace add zero specificity. They affect which elements a selector matches but do not add any weight to the cascade comparison.
What beats specificity entirely?
An inline style attribute on an element outweighs any selector in a stylesheet, and a declaration marked !important overrides normal specificity rules altogether, winning against selectors that would otherwise be stronger. Both sit outside the ID, class, type column system and should be used sparingly since they make the cascade harder to reason about.
How do :not(), :is() and :has() count?
These functional pseudo-classes do not add a flat point for themselves. Instead they take on the specificity of the single most specific selector inside their parentheses. :where() is the one exception and always contributes zero, no matter what selector is written inside it.
Why do two selectors with the same score behave differently?
When two selectors have identical specificity, the cascade falls back to source order: whichever rule appears later in the stylesheet, or was loaded later, wins. This is why reordering CSS files or moving a rule further down a file can silently change how a page looks even though no specificity changed.

More free tools

Let's grow

Ready to own page one?

Get a free, no-obligation SEO audit and a 30-minute strategy session. We'll show you exactly where the growth is hiding.

Book your free audit Explore services
Get in touch

Tell us about your project

Fill out the form and we'll get back to you within one business day. Prefer email? Write to us directly at contact@rankite.com.

Or copy our email and write to us directly: contact@rankite.com