About CSS Specificity Calculator
When two CSS rules set the same property on the same element, the one with the more specific selector wins, however late the other one comes. Paste the selectors that are fighting, one per line, and this tool shows each one’s specificity as IDs, classes and types, ranked so the winner is on top.
It follows the current Selectors specification: :is(), :not() and :has() take the weight of their most specific argument, :where() adds nothing, :nth-child(… of S) counts its selector list, and pseudo-elements count as types, including the old single-colon forms such as :before.
How it works
- Each selector is read character by character: IDs add to A; classes, attribute selectors and pseudo-classes add to B; type selectors and pseudo-elements add to C. The universal selector * and combinators add nothing.
- :is(), :not(), :has() and :nth-child(… of S) take the weight of the most specific selector in their list; :where() always counts as zero. :host() and ::slotted() add their argument to their own weight.
- Comparison is column by column: A first, then B, then C. A single ID beats any number of classes.
- A line that is not a valid selector is listed with the reason and the position of the problem, and the others are still compared.
Questions
Why does .a.b.c.d.e.f.g.h.i.j.k not beat #id?
Specificity is not a base-10 number. The three counts are compared in order, so any selector with an ID beats every selector without one, however many classes it has.
Where do inline styles and !important fit?
Above every selector. A style attribute beats any selector, and an !important declaration beats both, so they are outside what this tool measures. Cascade layers and the order of the rules come into play only when specificity ties.
How is the & nesting selector counted?
In nested CSS, & takes the specificity of its parent rule’s selector. A line pasted here has no parent, so & is counted as zero and the result says so.
Is there a limit?
Up to 200 selectors and 20,000 characters at a time, which is plenty for comparing the rules that clash on an element.
Everything you enter here is processed in this browser tab. Nothing is uploaded, logged or shared. How privacy works here.