Specificity

Calculating Specificity

Specificity is a score with three parts (a, b, c). Compare left to right; the first bigger number wins.

SelectorCounts asExample score
inline stylebeats all selectors—
IDa#nav → (1, 0, 0)
class, attribute, pseudo-classb.btn:hover → (0, 2, 0)
element, pseudo-elementcul li::marker → (0, 0, 3)
*, combinators, :where()nothing(0, 0, 0)

Example

Example

The paragraph is green: the ID selector (1,0,0) beats the class (0,1,0) and the element (0,0,1), even though the element rule comes last:

<!DOCTYPE html>
<html>
<head>
  <title>Page Title</title>
  <style>
    #intro { color: #04AA6D; }
    .lead { color: tomato; }
    p { color: #1971c2; }
  </style>
</head>
<body>

<p id="intro" class="lead">Which color am I?</p>

</body>
</html>

Result