CSS Specificity Calculator — Free Online Tool

Calculate CSS selector specificity locally and compare ID, class, attribute, pseudo-class, and type selector weight.

Use this free online CSS Specificity Calculator directly in your browser. No signup required, no data leaves your device. Part of Utilier — a collection of 133+ developer utilities.

What is CSS Specificity Calculator?

CSS specificity is the tuple browsers use to compare competing declarations after origin and importance are considered. It counts ID selectors first, then classes, attributes, and pseudo-classes, and finally type selectors and pseudo-elements. This calculator displays that tuple for each pasted selector, making selector weight visible when debugging a cascade conflict.

Specificity is compared lexicographically, not by adding the numbers together: one ID selector outranks any number of class or type selectors. It is also not the first cascade decision, because origin, importance, and cascade layers are considered earlier. When possible, solve conflicts with intentional layering and component scope instead of increasingly specific selectors.

Why use specificity calculator?

A declaration may fail to apply because another rule has greater specificity or appears later with equal specificity. Calculating tuples removes guesswork and helps developers choose a simpler, maintainable override instead of escalating with !important.

When to use specificity calculator

Use it while debugging CSS conflicts, reviewing component styles, or teaching the cascade. Specificity is only one part of the cascade: importance, origin, cascade layers, scope, and source order can still decide the winner.

How to use specificity calculator

Enter one selector per line and compare the resulting tuples from left to right.

  1. Paste competing selectors: Use the exact selectors from rules that target the same element.
  2. Read the tuple: Values represent IDs, classes, attributes, pseudo-classes, types, and pseudo-elements.
  3. Compare in order: The first differing component wins; an ID beats any number of classes.
  4. Inspect the full cascade: When tuples tie, use DevTools to check layers, importance, scope, and source order.

Key features

  • Selector comparison: Calculates a three-part specificity tuple for each non-empty selector.
  • Local calculation: Keeps selectors in the browser rather than sending style code to a service.
  • Copyable result: Lets debugging notes preserve selectors and their weights.

Common use cases

  • Component overrides: Understand why an application rule loses to a component selector.
  • CSS review: Spot unnecessary IDs and long chained selectors before they create an override burden.
  • Cascade education: Demonstrate why 0, 3, 0 does not beat 1, 0, 0.

Examples

Class selector

.card .title
0, 2, 0

ID selector

#app .card
1, 1, 0

Attribute and pseudo-class

button[data-state=active]:hover
0, 2, 1

Technical reference

Specificity is an ordered tuple, not a single total score.

ID component
Each #id selector increases the first value.
Class component
Each class, attribute selector, and pseudo-class increases the second value.
Type component
Each type selector and pseudo-element increases the third value.
Universal selector
The universal selector contributes no specificity.
Importance
!important is considered before specificity and is not part of the tuple.
Source order
Later declarations decide only after earlier cascade stages and specificity tie.

Common mistakes to avoid

Adding selector values as one number

Why it happens: Specificity is lexicographic: 1, 0, 0 beats 0, 100, 100.

How to avoid it: Compare from IDs through type selectors and stop at the first difference.

Using !important as a routine override

Why it happens: It changes the importance stage and makes later changes harder.

How to avoid it: Prefer intentional layers, component boundaries, or a selector with the real scope.

Ignoring source order after a tie

Why it happens: Identical tuples can still produce different results based on declaration order.

How to avoid it: Use browser DevTools to inspect the complete cascade when tuples are equal.

Frequently asked questions

Does !important change specificity?

No. It changes the importance stage that is considered before specificity.

Does source order matter?

Yes, when earlier cascade criteria and specificity are tied.

Are pseudo-elements included?

They count in the type-selector component.

Does an inline style have a tuple?

Inline declarations have higher author specificity than ordinary selector rules, subject to importance and other cascade stages.

Does :where() add specificity?

No. :where() has zero specificity, while other functional pseudo-classes have rules based on their arguments.

Does this decide the final winning rule?

No. It compares selector tuples; the browser cascade also considers origin, importance, layers, scope, and source order.

References

Privacy and availability

  • Runs entirely in your browser — zero server processing
  • No signup or account required
  • Works offline once loaded
  • Fast, lightweight, no external dependencies
  • Available as a browser extension for Chrome and Firefox