- Count 1 if the styles are applied from the (X)HTML style attribute, and 0 otherwise; this becomes variable a.
- Count the number of ID attributes in the selector; the sum is variable b.
- Count number of attributes, pseudo-classes, and class names in a selector; the sum is variable c.
- Count the number of element names in the selector; this is variable d.
- Ignore pseudo-elements.
SELECTOR |
SELECTOR TYPE |
SPECIFICITY |
* |
Universal Selector |
0,0,0,0, (a = 0, b = 0,c = 0, d = 0) |
li |
Element Name |
0,0,0,1, (a = 0, b = 0,c = 0, d = 1) |
ul li |
Element Name |
0,0,0,2, (a = 0, b = 0,c = 0, d = 2) |
div h1 + p |
Element Name |
0,0,0,3, (a = 0, b = 0,c = 0, d = 3) |
input[type=’text’] |
Element Name + Attribute |
0,0,1,1, (a = 0, b = 0, c = 1, d = 1) |
.someclass |
Class Name |
0,0,1,0, (a = 0, b = 0,c = 1, d = 0) |
div.someclass |
Element Name + Class Name |
0,0,1,1, (a = 0, b = 0,c = 1, d = 1) |
div.someclass.someother |
Element Name + Class Name +Class Name |
0,0,2,1, (a = 0, b = 0,c = 2, d = 1) |
#someid |
ID Name |
0,1,0,0, (a = 0, b = 1,c = 0, d = 0) |
div#someid |
Element Name + ID Name |
0,1,0,1, (a = 0, b = 1,c = 0, d = 1) |
style (attribute) |
style (attribute) |
1,0,0,0, (a = 1, b = 0,c = 0, d = 0) |
background: none;
}
p.top {
background: #666;
}