W3C home > Mailing lists > Public > www-style@w3.org > August 2012

[selectors4] Specificity in base 256

From: Simon Sapin <simon.sapin@kozea.fr>
Date: Thu, 16 Aug 2012 12:33:20 +0200
Message-ID: <502CCC70.2070303@kozea.fr>
To: "www-style@w3.org" <www-style@w3.org>

Selectors specificity is calculated from three integers a, b and c and:

> Concatenating the three numbers a-b-c (in a number system with a
> large base) gives the specificity.

My understanding is that "a large base" means one larger than any of a, 
b and c. In other words, the final specificity is not a single number 
but a tuple of 3 integers, compared in lexicographic order.

Apparently, "a large base" is 256 in Gecko and WebKit:


Iím not sure about other engines.

Should the spec be made more precise on this point? Is it deliberately 
vague to allow this kind of behavior? (Using a single int is probably 
more efficient.)

In my opinion, the behavior in Gecko and WebKit is incorrect but the 
approximation is good enough. I donít know if this makes a difference in 
any real stylesheet (ie. not made for the purpose of experimenting with 

To keep a single integer but be more correct (IMO), implementation could 
also clamp b and c to a maximum like 255 rather than letting them overflow.

Simon Sapin
Received on Thursday, 16 August 2012 10:33:48 UTC

This archive was generated by hypermail 2.4.0 : Friday, 25 March 2022 10:08:20 UTC