checked (HTML attribute)

Spec
Depr. Version
No HTML 2
Browser support (more…)
IE5.5+ FF1+ SA1.3+ OP9.2+ CH2+
Full Full Full Full Full

Syntax

checked="checked"

Description

In some circumstances, you may need to present one or more checkboxes in such a way that the state of the control at the point of page load is checked, and the user has to opt out rather than opting in. Or perhaps you’re presenting the user with a form—including a series of checkboxes—that he or she has previously filled in, and you want to preserve the state of the selections that were made. The checked attribute allows you to set the checked state to “on” by default.

The checked attribute is also used for radio input controls. Unlike the checkbox, only one in a range of related radio inputs can be selected (see the section on radio inputs in type for more on this), and the checked attribute is used to identify which one is selected. If you accidentally mark as "checked" a number of radio inputs that share a given name attribute, the last one that’s marked as such will be selected.

Note that the checkbox’s appearance differs between browsers and operating systems—in some, the checked checkbox appears as a ticked or checked box, while in others, it’s a crossed box. A radio input that’s "checked" will almost certainly not look like a tick or a check, but let’s not get hung up on appearances. The key is to know that the right control is selected!

Example

This checked attribute is applied to a newsletter signup checkbox:

<form>
  <input type="checkbox" name="chknewsletter" id="chknewsletter"
      checked="checked"/>
  <label for="chknewsletter">Send me the monthly newsletter</label>
</form>

Value

"checked" is the only possible value. If the input should be unchecked, simply omit the attribute entirely.

Compatibility

Internet Explorer Firefox Safari Opera Chrome
5.5 6.0 7.0 8.0 1.0 1.5 2.0 3.0 3.5 1.3 2.0 3.1 4.0 9.2 9.5 10.0 2.0
Full Full Full Full Full Full Full Full Full Full Full Full Full Full Full Full Full

It causes no compatibility issues, and has excellent support across all tested browsers.

User-contributed notes

There are no comments yet.

Related Products