- 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
styleattribute, 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 with1,0,0,0for astyleattribute, or0,0,2,1for a selector likediv.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.)
This term is sponsored by: your name/company?
- Previous term: Specification
- Next term: Spectre
- Random term: Prisma (webglossary.info/random 🎲)