- A part of the CSS cascade and the mechanism how declarations are applied, as specificity can be the deciding factor. As per CSS 2.2, a selector’s specificity is calculated by counting 1) whether it comes from a
style attribute, 2) how many ID attributes it contains, 3) how many other attributes and pseudo-classes it contains, and 4) the number of elements and pseudo-elements involved. The four resulting numbers yield the specificity, as with 1,0,0,0 for a style attribute, or 0,0,2,1 for a selector like div.message.error. If specificity decides on whether a declaration is applied, the declaration wins whose selector’s specificity is higher, that is, the individual numbers are compared, from left to right, and whichever selector hits a higher number wins. (Otherwise, per the cascade, order will have the final say.)
- More about this term (beta): Web search, articles and videos, books
- Previous term: Specification
- Next term: Spectre
- Random term: Compression