CSS Specificity Calculator
Calculate and compare the specificity of CSS selectors to understand which styles will win in the cascade.
specificity = (a, b, c): ID, Class/Attr/Pseudo-class, Type/Pseudo-element
How CSS specificity works
CSS specificity determines which rule wins when multiple declarations target the same element and property. It is expressed as three components (a, b, c):
- a: count of ID selectors (
#id) - b: count of class selectors (
.class), attribute selectors ([attr]), and pseudo-classes (:hover) - c: count of type selectors (
div,p) and pseudo-elements (::before)
Comparison is left-to-right: a higher a value always beats a lower one regardless of b or c. The universal selector (*) and combinators have no specificity.
Special cases
:where(): always zero specificity, regardless of its arguments:is(),:not(),:has(): take the specificity of their most specific argument!important: overrides specificity entirely; not calculated here- Inline styles always win over stylesheet rules (treated as a=1000 conceptually)
Tiebreaker rule
When two selectors have identical specificity, the rule that appears later in the stylesheet wins. This is the cascade order. This calculator highlights ties so you know to rely on source order.
Guides & Tutorials
- CSS specificity explained
When several CSS rules target one element, specificity decides which wins. See how it is calculated, how the cascade works, and why !important causes problems.
Related tools
- JSON Formatter & ValidatorValidate, format and minify JSON, with syntax error highlighting.Open tool
- JWT DecoderDecode and inspect JWT token headers, payloads and signatures.Open tool
- Regex TesterTest regular expressions live with match and group highlighting.Open tool
- HTML Entity EncoderEncode and decode HTML entities for safe use in markup.Open tool