1. Home
  2. Developer tools
  3. CSS Specificity Calculator

CSS Specificity Calculator

Find out why a style is not applying: compare the selectors fighting over the same element and see which one the browser picks.

Free, no sign-up. Runs in your browser: nothing is uploaded.

How to use CSS Specificity Calculator

  1. Paste selectors, one per line or comma-separated.
  2. Read each score and the colour-coded parts.
  3. See which one wins and why.

Features

  • A (IDs), B (classes, attributes, pseudo-classes), C (types, pseudo-elements)
  • :is(), :not() and :has() take their most specific argument
  • :where() counts zero; :nth-child(… of S) handled
  • Ties resolved by source order, as in the cascade
  • Colour-coded breakdown of every selector

Supported formats

Input

  • Typed or pasted text

You get

  • Screen view

Private by design

Everything you enter is processed by your browser on this device. Nothing is sent to openWorkstand or anyone else, so the CSS Specificity Calculator is safe for private and work data. After you have used it once while online, it also works without an internet connection. How local processing works

Good to know

  • Cascade layers, !important and inline styles are outside specificity and are not compared.

Guide

Calculating CSS specificity, including :is(), :not() and :where()

When two CSS rules set the same property on the same element, the browser has to pick one. After origin, importance and cascade layers, the deciding factor is specificity: a score computed from the selector. Most “why is my style not applying?” bugs come down to it. This calculator scores selectors the way browsers do, shows which parts count and tells you which selector wins.

The three-part score

Specificity is written as three numbers, (a, b, c). The first counts ID selectors such as #nav. The second counts class selectors such as .item, attribute selectors such as [type="text"] and pseudo-classes such as :hover or :first-child. The third counts type selectors such as a or li and pseudo-elements such as ::before. The universal selector * and combinators such as >, +, ~ and the space count nothing.

Comparing scores

Scores are compared column by column, not added up. The selector with more IDs wins outright; only if the IDs are equal do the classes matter, and only then the types. One ID, (1,0,0), therefore beats ninety-nine classes, (0,99,0). When two selectors have exactly the same score, the rule that appears later in the stylesheet wins, which is why the calculator reports ties by source order.

The functional pseudo-classes

Selectors Level 4 added pseudo-classes that take selector lists, each with its own rule. :is(), :not() and :has() count as their most specific argument, so a:not(.external, #home) scores (1,0,1) because of the ID inside. :where() always counts zero, which makes it ideal for base styles that should be easy to override. :nth-child(2 of .done) counts one pseudo-class plus the most specific selector after of.

Where specificity sits in the cascade

Specificity is not the first test. The cascade first compares origin and importance, so an !important declaration beats a normal one whatever the selectors, and user-agent, user and author styles have their own order. Cascade layers come next: rules in a later layer win over earlier layers. Inline style attributes beat any selector. Only after all that does specificity decide, followed by source order.

A worked example

The Sample lists eight selectors. #nav .item > a:hover scores (1,2,1), nav ul li a (0,0,4) and .btn.btn-primary (0,2,0). a:not(.external, #home) scores (1,0,1) because of the ID in its argument, while :where(.card) h2 is only (0,0,1). :is(header, footer) a[href^="https"] scores (0,1,2), li:nth-child(2 of .done) (0,2,1) and button::after (0,0,2). The winner is #nav .item > a:hover: it ties with the :not() selector on IDs and wins on classes.

Getting out of specificity wars

Rising specificity, IDs in stylesheets, chains of classes and !important, makes CSS hard to change. Keep selectors short and class-based, wrap reusable base styles in :where() so components can override them with a single class, and use cascade layers to order frameworks, components and utilities explicitly instead of fighting with selector weight.

Debugging a style that will not apply

Open the element in the browser’s developer tools and look at the Styles panel: overridden declarations are struck through, and the rule above them is the one that won. Paste both selectors here to see the scores side by side. If the winning rule has a higher score, either raise the losing selector’s specificity by one class or, better, lower the winner’s, for example by replacing an ID with a class. If the scores are equal, the problem is order: the winning rule is simply loaded later, often from another stylesheet or a framework.

Checked against the current version of the CSS Specificity Calculator on .

Frequently asked questions

How do cascade layers change who wins?

Layers are compared before specificity. A rule in a later @layer beats a rule in an earlier one regardless of specificity, and normal rules outside any layer beat all layered rules. Within the same layer, specificity decides as usual.

Is a :hover rule more specific than the same selector without it?

Yes, by one in the b column: a:hover is (0,1,1) while a is (0,0,1). That is why a hover style written as a:hover still applies on top of a plain a rule, even if the plain rule comes later in the stylesheet.

Does one ID beat ten classes?

Yes. Specificity is compared column by column, not added up: (1,0,0) beats (0,10,0) and even (0,99,0). Classes never “carry over” into the ID column.

Where do !important and inline styles fit?

Outside specificity. The cascade compares origin and importance first, then cascade layers, then specificity, then order. An inline style attribute beats any selector, and !important declarations beat normal ones.

Keep working with the result

openWorkstand also includes a free workspace with documents, spreadsheets, tasks, projects and a calendar that save to a folder on your computer.