Skip to content
ToolsOnDuty - free online tools

Search tools

Loading tool search...

CSS & Design

CSS Specificity Calculator

Calculate the specificity of a CSS selector.

Free browser toolRuns in your browserNo sign-up
1
IDs
2
Classes / attrs / pseudo-classes
3
Elements / pseudo-elements
Specificity
1,2,3

Specificity is compared left to right (IDs, then classes, then elements). A higher group wins regardless of the lower ones. Inline styles and !important are separate and beat these.

About the CSS Specificity Calculator

When competing declarations reach the specificity stage of the CSS cascade, selector weight is compared in three groups: IDs; classes, attributes and pseudo-classes; then elements and pseudo-elements.

This calculator shows a useful breakdown for simple selectors using pattern-based counting. It is not a complete CSS selector parser and can miscount advanced syntax.

It runs in your browser.

Key features

  • Counts IDs, classes and elements
  • Shows the a,b,c score
  • Handles pseudo-classes and attributes
  • Runs in your browser

How to use

  1. 1Paste a CSS selector.
  2. 2Read the specificity breakdown.
  3. 3Compare it against another rule.
  4. 4Enter one simple selector at a time rather than a comma-separated selector list. Compare the three numbers left to right, not as an ordinary decimal total.
  5. 5Do not rely on this counter for :is(), :not(), :has(), :where(), nesting, escaped identifiers or selector-like text inside attribute values. Check those cases in browser developer tools or a full CSS-aware parser.
  6. 6When debugging a declaration that still loses, inspect cascade origin, importance, layers and source order too; specificity alone is not the whole cascade.

Examples

Nested selector
Input: #nav ul li a.active
Output: 1,1,3

One ID, one class and three element names give a specificity of 1,1,3.

Frequently asked questions

How is specificity compared?
Within the same relevant cascade context, compare IDs first, then the class group, then the element group. A difference in an earlier group outweighs every later group. Source order can break remaining ties, but cascade layers and other cascade rules may decide a winner before specificity.
What about !important and inline styles?
Importance and inline styling are outside this tool's three selector counters. !important changes cascade priority rather than adding selector weight; inline declarations also need separate consideration. Use the browser's computed-style inspection to see which declaration actually wins.
Do pseudo-elements count?
The helper counts double-colon pseudo-elements such as ::before in the element group and simple pseudo-classes such as :hover in the class group. It does not fully implement the special specificity rules for functional pseudo-classes or legacy single-colon pseudo-elements.

Open a related tool to prepare your files or refine the finished result.