Calcoid

CSS Specificity Calculator

Compute a CSS selector's specificity as the (a,b,c) tuple, then rank two selectors to see which one wins the cascade. Handles :is(), :not(), and :where().

Compute CSS specificity and rank two selectors

Type, ID, class, attribute, pseudo-class, and pseudo-element selectors are all supported, including :is(), :not(), :has(), and :where().

Add a second selector to see which one wins the cascade on the same element. Everything runs locally in your browser.

Cascade winner

Selector 1 wins the cascade

Selector 1 is more specific. The first column that differs is IDs (a), which is higher for the winner.

(1,2,1)vs(0,1,3)

Selector 1

(1,2,1)

#nav .item a:hover

1,2,1value 66,049
ID selectors (#id)
a1
Classes (.class)
b1
Attributes ([attr])
b0
Pseudo-classes (:hover)
b1
Type/element (div)
c1
Pseudo-elements (::before)
c0

Selector 2

(0,1,3)

ul li.active a

0,1,3value 259
ID selectors (#id)
a0
Classes (.class)
b1
Attributes ([attr])
b0
Pseudo-classes (:hover)
b0
Type/element (div)
c3
Pseudo-elements (::before)
c0

Frequently Asked Questions about the CSS Specificity Calculator

What is CSS specificity?
Specificity is how the browser decides which CSS rule wins when several rules target the same element. It is expressed as a tuple of three numbers, often written (a,b,c). Column a counts ID selectors, column b counts classes, attributes, and pseudo-classes, and column c counts type (element) selectors and pseudo-elements. The browser compares the columns left to right, so any selector with a higher a beats one with a lower a no matter how large b or c are.
How do you calculate the specificity tuple?
Count each part of the selector and put it in the right column. Add 1 to a for every ID (like #main), add 1 to b for every class (.card), attribute ([type=text]), or pseudo-class (:hover), and add 1 to c for every element name (div) or pseudo-element (::before). The universal selector (*) and combinators (>, +, ~, and the descendant space) add nothing. For example, #nav .item a:hover is (1,2,1).
How do I know which of two selectors wins?
Compare the tuples column by column, starting with a. The selector with the larger a wins outright. If a ties, the larger b wins, and if b also ties, the larger c wins. If all three columns are equal, neither selector is more specific, and the one written later in the stylesheet wins by source order. This tool ranks both selectors for you and tells you which column decided it.
Do :is(), :not(), :has(), and :where() affect specificity?
The :is(), :not(), and :has() pseudo-classes do not add anything for the function itself, but they take on the specificity of the most specific selector inside their parentheses. So :is(#id, .class) counts as a single ID. The :where() pseudo-class is special: it always contributes zero specificity, no matter what is inside it, which makes it useful for low-priority defaults.
Why do pseudo-elements count differently from pseudo-classes?
Pseudo-classes like :hover or :focus describe a state and count in column b, the same as classes. Pseudo-elements like ::before, ::after, or ::first-line target a sub-part of an element and count in column c, the same as type selectors. Legacy single-colon syntax (:before, :after, :first-line, :first-letter) still counts as a pseudo-element, so this tool treats div:before and div::before identically.
Does inline style or !important change specificity?
They sit outside the (a,b,c) tuple. An inline style attribute beats any selector in a stylesheet, and a declaration marked !important beats normal declarations regardless of specificity. This calculator scores selectors only, so use it to compare stylesheet rules, then remember that inline styles and !important override the result on top of that.

Related Calculators

More calculators in "Tech"

See all 98 calculators in "Tech"