b2KIT

CSS Specificity Calculator

Calculate and compare CSS selector specificity scores with visual breakdown of ID, class, and element weights.

Tested tool guide Tested browser tools Checked August 16, 2026

What CSS Specificity Calculator does, with a checked example

A selector can look long and still lose to a shorter one. This calculator turns each CSS selector into the three-part specificity tuple used for selector comparison: ID components, class-like components, and type-like components. Its visual breakdown makes competing selectors easier to compare column by column. The common surprise is that these values are not added as a decimal score; the first unequal column decides. Spaces and combinators affect matching structure but add no specificity.

Worked example

A concrete input and expected output from the current implementation.

Input

#menu .item a

Expected output

Specificity: (1, 1, 1). IDs: 1; classes, attributes, and pseudo-classes: 1; elements and pseudo-elements: 1.

#menu contributes one ID, .item contributes one class, and a contributes one type selector. The two descendant combinators contribute nothing.

How the result is produced

1

Three-column comparison

The ID column counts ID selectors. The middle column counts class selectors, attribute selectors, and pseudo-classes. The final column counts type selectors and pseudo-elements. Comparison proceeds from IDs to the middle column to the type column, stopping at the first difference. Universal selectors and combinators contribute zero, and counts never carry between columns.

2

Functional pseudo-classes

Functional pseudo-classes have selector-specific rules. :where() contributes zero specificity, including its arguments. For :is(), :not(), and :has(), the pseudo-class itself adds no weight; the most specific selector in its argument list supplies the argument specificity. Ordinary pseudo-classes such as :hover count in the middle column. Selector components outside these functions are counted normally.

Good uses

  • Compare two selectors when an expected CSS override is losing.
  • Check whether removing an ID or repeated class lowers a selector's specificity.
  • Audit selectors generated by a framework, component library, or nested stylesheet.

Limits and checks

  • Specificity does not decide the entire cascade. Origin, importance, cascade layers, scoping proximity, and order can also affect the winning declaration.
  • Do not read (1, 0, 0) as 100 or compare tuples by adding their components. Specificity columns are compared from left to right.
  • A comma-separated selector list has separate specificity values for its branches; it does not have one combined tuple.

Common questions

Does the selector with the higher total always win?

No. The tuple is compared left to right, not summed, so (1, 0, 0) outranks (0, 20, 0). Specificity is also only one cascade step. A declaration with lower selector specificity can win because of origin, importance, layer order, or other cascade rules. If all preceding cascade criteria and specificity tie, order of appearance can decide.

Can I calculate a comma-separated selector list as one score?

No. Each branch participates independently, so .a, #b contains specificities (0, 1, 0) and (1, 0, 0). The list does not become (1, 1, 0). Calculate each branch separately. Selector lists inside :is(), :not(), and :has() are different because those functional pseudo-classes use the most specific argument.

References and verification

The example and behavioral notes were checked against the browser implementation. Standards and primary references below define the relevant format, formula, or platform behavior.

Related Tools