This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

checked

Summary

Indicates the initial state of a checkbox or radio button.

Applies to [html/elements/input](/html/elements/input)
The checked attribute can be used to specify what the visual or initial state of an input element is. It's often used to toggle an element through JavaScript.

As a boolean attribute, valid values are "checked" and nothing. The attribute is never required.

Examples

This example shows a set of radio buttons with one checked by default.

<form>
    <fieldset>
        <legend>Radio buttons</legend>
        <input type="radio" name="rad" id="rad1" value="Option 1">
        <label for="rad1">Option 1</label><br>
        <input type="radio" name="rad" id="rad2" value="Option 2" checked>
        <label for="rad2">Option 2</label><br>
        <input type="radio" name="rad" id="rad3" value="Option 3">
        <label for="rad3">Option 3</label><br>
        <input type="radio" name="rad" id="rad4" value="Option 4">
        <label for="rad4">Option 4</label>
    </fieldset>
</form>

View live example

This example shows a set of check boxes with multiple checked by default.

<form>
    <fieldset>
        <legend>Check boxes</legend>
        <input type="checkbox" name="check1" id="check1" value="Option 1">
        <label for="check1">Option 1</label><br>
        <input type="checkbox" name="check2" id="check2" value="Option 2" checked>
        <label for="check2">Option 2</label><br>
        <input type="checkbox" name="check3" id="check3" value="Option 3">
        <label for="check3">Option 3</label><br>
        <input type="checkbox" name="check4" id="check4" value="Option 4" checked>
        <label for="check4">Option 4</label>
    </fieldset>
</form>

View live example

Notes

Remarks

Check boxes that are not selected do not return their values when the form is submitted.

A user can select a radio button only if the button has a name. A set of radio buttons is defined by the same value for the name attribute. To clear a selected radio button, a user must select another button in the set. One radio button in a set should always be checked, else the form is invalid by default. Only the value of the selected radio button is returned when the form is submitted.

Windows Internet Explorer 8 and later. In IE8 Standards mode, parsing operations on the checked content attribute always affect both the checked content attribute and defaultChecked Document Object Model (DOM) attribute. For example, removeAttribute(‘checked’) sets both checked and defaultChecked to false. Similarly, setAttribute('checked’, ‘checked’) sets both DOM attributes to true (as if the element was being re-parsed) For more information on IE8 mode, see Defining Document Compatibility. Internet Explorer 8 and later. In IE8 mode, the defaultChecked DOM attribute reflects the value of the checked content attribute.

Related specifications

HTML5
W3C Candidate Recommendation

See also

Related articles

HTML

Other articles

External resources

Attributions