{"id":14166,"date":"2013-02-17T18:25:37","date_gmt":"2013-02-18T01:25:37","guid":{"rendered":"http:\/\/css-tricks.com\/?page_id=14166"},"modified":"2015-03-27T08:18:38","modified_gmt":"2015-03-27T15:18:38","slug":"checked","status":"publish","type":"page","link":"https:\/\/css-tricks.com\/almanac\/selectors\/c\/checked\/","title":{"rendered":":checked"},"content":{"rendered":"
The So when a checkbox is checked, and you are targeting the label immediately after it:<\/p>\n The label text will turn from grey italic to red normal font. <\/p>\n :checked<\/code> pseudo-class in CSS selects elements when they are in the selected state. It is only associated with input (
<input><\/code>) elements of type radio and checkbox . The
:checked<\/code> pseudo-class selector matches radio and checkbox input types when checked or toggled to an on state. If they are not selected or checked, there is no match.<\/p>\n
input[type=checkbox] + label {\r\n color: #ccc;\r\n font-style: italic;\r\n} \r\ninput[type=checkbox]:checked + label {\r\n color: #f00;\r\n font-style: normal;\r\n} <\/code><\/pre>\n
<input type=\"checkbox\" id=\"ossm\" name=\"ossm\"> \r\n<label for=\"ossm\">CSS is Awesome<\/label> <\/code><\/pre>\n