Developer Tools
CSS Specificity Calculator
Calculate CSS specificity for any selector. See ID, class, attribute, pseudo-class, and pseudo-element counts. Compare selectors and find the winner.
Try a sample
Selector
#header .nav a:hovera (IDs)
1
b (Classes, attributes, pseudo-classes)
2
c (Types, pseudo-elements)
1
Token breakdown
#headerID (+1 a)(1, 0, 0)(descendant)Combinator (0)(0, 0, 0).navClass (+1 b)(0, 1, 0)(descendant)Combinator (0)(0, 0, 0)aType (+1 c)(0, 0, 1):hoverPseudo-class (+1 b)(0, 1, 0)
How specificity is counted
- aID
One per ID selector (#header).
- bClass / attr / pseudo-class
One per class (.nav), attribute selector ([type='text']), or pseudo-class (:hover, :focus, :nth-child).
- cType / pseudo-element
One per type selector (div, p, h1) or pseudo-element (::before, ::placeholder).
- 0Universal and combinators
The universal selector (*) and combinators (descendant space, >, +, ~, ||) contribute nothing.
- max:is, :has, :not
Take the highest specificity of any selector in the parentheses.
- 0:where
Always counts as zero, regardless of what is inside.
- 1 b + max:nth-child(of S)
The pseudo-class adds 1 to b, plus the highest specificity of any selector after of.
- noteInline and !important
Inline style attribute counts above selector specificity. !important wins over both, declaration order being equal.
How to use
- Paste a single selector or a comma-separated list into the input box. Try a sample like '#header .nav a:hover' or ':is(h1, h2, h3) .title' to see the breakdown.
- Read the (a, b, c) score on each selector card, where a counts IDs, b counts classes, attributes, and pseudo-classes, and c counts type selectors and pseudo-elements.
- Open the token breakdown to see which exact part of the selector contributes each point, with color-coded badges for the three buckets.
- When you enter two or more selectors, the ranking panel highlights which one wins. Tied selectors fall through to source order, which the panel notes.
- Use the Copy button next to any score to grab the (a, b, c) value, or click Clear to reset the input and try another selector.
About this tool
CSS Specificity Calculator parses any CSS selector or comma-separated selector list and reports the (a, b, c) specificity triple defined by CSS Selectors Level 4. The a value counts ID selectors (#header), b counts class selectors (.nav), attribute selectors ([type='email']), and pseudo-classes (:hover, :focus-visible, :nth-child), and c counts type selectors (div, p, h1) and pseudo-elements (::before, ::placeholder, ::first-line). The universal selector (*) and the descendant, child (>), adjacent sibling (+), general sibling (~), and column (||) combinators correctly contribute zero. Functional pseudo-classes follow the modern spec rules: :is(), :has(), and :not() take the highest specificity of any selector inside their parentheses, :where() always counts as zero so you can use it as a low-specificity wrapper, and :nth-child() and friends add 1 to b plus the highest specificity of any selector after the of keyword. Each selector card shows a per-token breakdown so you can see which exact part of the selector contributes which point, with color-coded badges for IDs, classes/attributes/pseudo-classes, and types/pseudo-elements. When you paste more than one selector the tool ranks them and highlights the winner, with an explicit note when two selectors tie (in which case the cascade falls through to source order). Common use cases include debugging why a CSS rule does not apply, comparing a refactor before and after, choosing between :is() and :where() to control specificity, understanding why utility classes lose to a more specific component selector, and teaching the cascade to junior developers without making them memorize rules. Parsing happens entirely in your browser so the selectors and stylesheets you analyze never leave your device.
Free to use. Works in your browser. No signup, no login.
Related tools
You may also like
CSS Minifier
Compress CSS with comment, whitespace, hex, and zero-unit optimizations and a live byte-savings readout.
Open tool
GeneratorCSS Gradient Generator
Linear, radial, and conic gradients with multi-stop editor and live preview.
Open tool
DeveloperRegex Tester
Live regex testing with highlights, capture groups, and replacement preview.
Open tool
SEOColor Contrast Checker
Check WCAG AA, AAA, and UI contrast ratios with live preview and pass or fail badges.
Open tool
DeveloperHTML Formatter
Pretty-print and minify HTML with indent, wrap, and quote controls.
Open tool