I am trying to style a checkbox using the following:
I think the easiest way to do it is by styling a label
and making the checkbox
invisible.
HTML
CSS
checkbox {
display: none;
}
checkbox + label {
/* Style for checkbox normal */
width: 16px;
height: 16px;
}
checkbox::checked + label,
label.checked {
/* Style for checkbox checked */
}
The checkbox
, even though it is hidden, will still be accessible, and its value will be sent when a form is submitted. For old browsers you might have to change the class of the label
to checked using JavaScript because I don't think old versions of Internet Explorer understand ::checked
on the checkbox
.