CSS Specificity Calculator
Paste a CSS selector to see its specificity as the standard (a, b, c) triple and a single score. The breakdown shows exactly which IDs, classes, attributes, pseudo-classes and elements counted, so you can tell which rule wins.
How to calculate CSS specificity
- Type or paste a CSS selector such as #main .btn:hover.
- Read the (a, b, c) values: a counts IDs, b counts classes, attributes and pseudo-classes, c counts elements and pseudo-elements.
- Turn on compare mode to pit two selectors against each other and see which one would win.
Examples
ID, class and element
#id .class p
a=1, b=1, c=1, score 111
:not() counts its argument
p:not(.active)
a=0, b=1, c=1, score 11
Frequently asked questions
How is CSS specificity calculated?
Specificity is three numbers (a, b, c). a counts ID selectors like #id. b counts classes, attribute selectors like [type=text] and pseudo-classes like :hover. c counts element types and pseudo-elements like ::before. Compare a first, then b, then c; the higher value wins.
What does the score number mean?
The score is a flattened value, a times 100 plus b times 10 plus c, so a single selector is easy to compare at a glance. For everyday selectors it preserves the same order as the real cascade. When two selectors tie, the one declared later in the stylesheet wins.
How are :not(), :is() and :has() handled?
These functional pseudo-classes add no specificity themselves, but their argument does. The calculator adds the specificity of the most specific selector inside them. So :not(.x) counts as one class, and :is(#a, p) counts as one ID. :where() always adds nothing.
What about the universal selector and combinators?
The universal selector * and the combinators >, +, ~ and the descendant space add nothing to specificity. They affect what a selector matches but never how strongly it wins, so the calculator ignores them.
Where do inline styles fit in?
An inline style attribute, like style="color:red", beats any selector in a stylesheet. It is sometimes written as the (1,0,0,0) column ahead of IDs. Only !important or another inline style can override it, so this tool focuses on selector specificity, not inline styles.
Is my selector sent to a server?
No. The whole calculation runs in your browser with JavaScript. Nothing you type is uploaded or stored.
Related tools
CSS Formatter
Beautify and format messy or minified CSS online. Indent rules, put one declaration per line and tidy spacing. Runs in your browser.
Color Contrast Checker
Check the WCAG contrast ratio between two colors. See AA and AAA pass or fail for normal and large text, with a live preview. Runs in your browser.
CSS Gradient Generator
Build linear and radial CSS gradients with a live preview. Pick colors, set the angle and copy ready-to-paste background code for your site.
.env to JSON
Convert a .env file to JSON, or JSON back to .env. Parses KEY=value lines, comments, quotes and export. Runs entirely in your browser.
Aspect Ratio Calculator
Calculate aspect ratios fast. Enter a ratio like 16:9 and one dimension to get the other, or enter width and height to simplify the ratio.
Base58 Encoder
Encode and decode Base58 online with the Bitcoin alphabet. Convert text to Base58 or back, UTF-8 safe, no confusing 0 O I l. Runs in your browser.