Ronnie Ronnie - 3 years ago 160
HTML Question

How do I make a checkbox toggle from clicking on the text label as well?

Checkboxes in html forms don't have implicit labels with them. Adding an explicit label (some text) next to it doesn't toggle the checkbox.

Mat Mat
Answer Source

Set the CSS "display" property for the label to be a block element and use that instead of your div - it keeps the semantic meaning of a label while allowing whatever styling you like.

For example

<label for="test" style="width: 100px; height: 100px; display: block; background-color: #e0e0ff;">
    A ticky box! <input type="checkbox" id="test" />
</label>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download