CSS Specificity Calculator
Paste CSS selectors, or a whole stylesheet, to see each selector's specificity as (a, b, c) with what counted, and the list in the order the selectors win.
About this tool What it's for, how to use it and an example
What it's for
Works out which of several CSS selectors wins when they all match the same element. A selector’s specificity is three numbers, (a, b, c): ids first, then classes, attributes and pseudo-classes, then types and pseudo-elements. The browser compares them left to right, so one id outranks any number of classes.
For example, when a rule written as #nav a seems to lose to .nav a:hover, paste both to see which has the higher
specificity and which parts of each selector made it so.
How to use it
Paste selectors, one a line, or a whole stylesheet. From a stylesheet the tool takes the selectors before each { and
skips @ rules such as @media, but counts the rules inside them. A selector list such as h1, h2 gives a row for
each selector.
The table is in the order the selectors win: the highest specificity first. Of two that are equal, the later one in the source comes first, as the browser applies it last. Order is the selector’s place in what you pasted, and What counted lists the parts that made up each number. A selector the tool can’t read is listed last, with the reason.
A selector inside :not(), :is() or :has() counts as the most specific selector in its list. :where() counts
for nothing, and in :nth-child(… of S) the S counts as well as the pseudo-class.
Example
Press Try an example. The input is these six selectors:
a
.nav a
#nav a
#nav .item:hover
input[type=text]:not(#search)
ul > li::before
The table ranks them #nav .item:hover (1, 2, 0), input[type=text]:not(#search) (1, 1, 1), #nav a (1, 0, 1),
ul > li::before (0, 0, 3), .nav a (0, 1, 1) and a (0, 0, 1). The message says Ranked 6 selectors.
Good to know
Only the selector is counted. Inline style="" attributes and !important beat any selector, so they aren’t shown
here. Cascade layers, the origin of the stylesheet (browser, user or author) and the order of stylesheets all come
before specificity, so a selector with the higher numbers can still lose. The tool doesn’t check which elements a
selector matches.
A & nesting selector takes its parent’s specificity, so on its own it isn’t counted and is listed as such.
| Wins | Order | Selector | Specificity (a, b, c) | What counted |
|---|
Built with The third-party code and data this tool uses, and their licences
This tool uses no third-party code or data of its own: its code was written for this site.
Every page also uses Montserrat (SIL Open Font License 1.1).
Everything the site uses is on Credits and licences.
Private: this tool runs in your browser. Nothing you type, paste or choose leaves this page.
Saved you a few minutes? Say thanks with a coffee.
Something wrong with this tool, or missing from it? Report a bug or suggest a feature.