CSS Specificity Calculator

Compare two CSS selectors and see exactly why one wins — free, in your browser.

Processed locally — files never leave your device

Works offline once loaded Uploaded: 0 bytes

Wondering why your CSS rule is not applying? This free CSS specificity calculator scores any selector as three numbers — IDs, classes and elements — and shows you exactly which selector wins. Paste two selectors, compare them side by side, and stop guessing why a style loses. Everything runs in your browser, nothing is uploaded.

Specificity decides which rule the browser applies when two rules target the same element, and a single ID in a selector beats any number of classes. For a related job, try the Iframe Generator or the CSS Gradient Generator.

How to use

  1. Type your first CSS selector into the Selector A box above, like #header .nav a.
  2. Type the competing selector into the Selector B box, or leave it empty to score one selector.
  3. Click Calculate specificity to see the three-part score and the breakdown for each selector.
  4. Read the winner line to learn which rule the browser applies — and why the other loses.

Why use Toolsvine

A selector like #site-header .main-nav a.active scores 1, 2, 1 — one ID, two classes, one element — and beats a plain header nav a at 0, 0, 3, which is exactly why a navigation link stays the wrong color no matter how many times you restyle it. Most developers learn this by trial and error, but this calculator shows the three numbers and the rule behind them in one glance. It is free, needs no account, and it explains the answer instead of just printing a score.

How does the CSS specificity calculator work?

Yes. Type a CSS selector and the tool splits it into three counts in your browser: IDs, classes and attributes, and elements. An ID counts in the first number, a class, attribute or pseudo-class counts in the second, and an element or pseudo-element counts in the third, so the selector #header .nav a scores 1, 1, 1.

The calculator compares the three numbers left to right, like reading a three-digit number: one ID beats any number of classes, and one class beats any number of elements. It also handles the tricky cases — :not() and :is() take the score of their strongest argument, :where() counts as zero, and pseudo-elements count as elements — and it shows the breakdown so you can see which part of your selector is doing the work.

Worked example: why a navigation link stays the wrong color

Take a site header in Denver where the active navigation link should be mint green but stays gray. Selector A is #site-header .main-nav a.active, scoring 1, 2, 1 — one ID, two classes, one element, for a total score of 121. Selector B is header nav a, scoring 0, 0, 3 — three elements, for a total score of 3. Selector A wins by 118 points, so the browser applies it and the gray rule never gets a chance.

CSS specificity example comparing selector scores (1, 2, 1) versus (0, 0, 3) with the ID selector winning.
Selector A (1, 2, 1) beats selector B (0, 0, 3) by 118 points.
DetailValue in the example
Selector A#site-header .main-nav a.active
Score A(1, 2, 1) = 121
Selector Bheader nav a
Score B(0, 0, 3) = 3
WinnerSelector A, by 118 points

Try it yourself: paste the same two selectors above and the scores should match. If a rule you expect to win still loses, check for an inline style or an important flag — both beat even the highest specificity score.

What should I watch out for when comparing selectors?

The most common mistake is counting classes when the fight is really about IDs. One ID beats a hundred classes, so adding more classes to a losing selector never helps — you have to match or beat the ID, or restructure the HTML. The calculator makes this obvious by showing the three numbers side by side instead of one total.

A second mistake is forgetting that :not() and :is() carry the specificity of their strongest argument, while :where() carries none at all. A selector with :not(.active) counts the class even though it looks like plain text, and :where() can zero out an entire selector on purpose. For a related job, the CSS Gradient Generator styles the same page with a gradient.

Frequently asked questions

What is CSS specificity in plain words?

Specificity is the browser's tie-breaker. When two CSS rules target the same element, the browser applies the rule with the higher specificity score. The score has three parts: IDs, then classes and attributes, then elements. An ID beats any number of classes, and a class beats any number of elements, so the three numbers are compared left to right, never added up.

How do I read a specificity score like (1, 2, 1)?

Read it as three separate counts, not as the number 121. The first number counts ID selectors, the second counts class selectors, attribute selectors and pseudo-classes, and the third counts element selectors and pseudo-elements. A score of (1, 2, 1) means one ID, two classes and one element. Comparing scores goes left to right, so (1, 0, 0) beats (0, 9, 9).

Does :not() add to specificity?

Yes, and this surprises people. The :not() pseudo-class itself adds nothing, but its argument does: :not() with a class inside scores like a class, and :not() with an ID inside scores like an ID. The same rule applies to :is(), which takes the score of its strongest argument. :where() is the exception — it always scores zero, which is why it is handy for zero-specificity resets.

Why does my rule lose even though it comes later in the file?

Because order only breaks ties between rules with equal specificity. A later rule with a lower score still loses to an earlier rule with a higher score — the browser checks specificity first and file order second. To win, raise the selector's specificity to match or beat the other rule, or move the style into a place with a stronger selector.

Does !important beat specificity?

Yes. An important declaration beats every normal declaration, no matter how high its specificity, and inline styles beat everything except important rules. That is why important feels like a fix and then becomes a mess: it breaks the normal scoring system, so use it only for utilities and overrides, never as a regular way to win a fight.