I know there is an official CSS3 :checked
pseudo-class, but is there an :unchecked
pseudo-class, and do they have the same browser support?
Sitepoint's reference doesn't mention one, however this whatwg spec (whatever that is) does.
I know the same result can be achieved when the :checked
and :not()
pseudo-classes are combined, but i'm still curious:
input[type="checkbox"]:not(:checked) {
/* styles */
}
Edit:
The w3c recommends the same technique
An unchecked checkbox can be selected by using the negation pseudo-class:
:not(:checked)
:unchecked
is not defined in the Selectors or CSS UI level 3 specs, nor has it appeared in level 4 of Selectors.
In fact, the quote from W3C is taken from the Selectors 4 spec. Since Selectors 4 recommends using :not(:checked)
, it's safe to assume that there is no corresponding :unchecked
pseudo. Browser support for :not()
and :checked
is identical, so that shouldn't be a problem.
This may seem inconsistent with the :enabled
and :disabled
states, especially since an element can be neither enabled nor disabled (i.e. the semantics completely do not apply), however there does not appear to be any explanation for this inconsistency.
(:indeterminate
does not count, because an element can similarly be neither unchecked, checked nor indeterminate because the semantics don't apply.)