Search code examples
htmlcheckboxchecked

What is the proper way to check and uncheck a checkbox in HTML5?


Looked at the HTML spec, but couldn't make heads or tails of it: http://www.w3.org/TR/html5/the-input-element.html#attr-input-checked

What is the correct way to check a checkbox in HTML (not dynamically)?

checked="true"
checked="checked"

What is the correct way to uncheck a checkbox?

<input type="checkbox" /> with no checked attribute
checked="false"
checked="none"

Where to check the HTML specification to check/uncheck a checkbox?


Solution

  • For checked state

    Older browsers may need:

    <input type="checkbox" checked="checked" />
    

    But nowadays simply do:

    <input type="checkbox" checked />
    

    For unchecked state

    Remove checked attribute, like:

    <input type="checkbox" />
    

    Reference: http://www.w3.org/TR/html-markup/input.checkbox.html#input.checkbox.attrs.checked