Skip to: content, navigation

by Ian Lloyd

checked (HTML attribute)

Browser support full matrix
IE5.5+ FF1+ Saf1.3+ Op9.2+
Full Full Full Full
Spec
Depr. Version
No HTML 2
checked="checked"

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>

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!

Value

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

Compatibility

IE5.5Full
6.0Full
7.0Full
Firefox1.0Full
1.5Full
2.0Full
Safari1.3Full
2.0Full
3.0Full
Opera9.2Full

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

User-contributed notes

There are no comments yet.

Add a note

To post a note on this topic, please log in with your SitePoint username and password. If you don't have an account yet, you can create a new account for free.

Related Products

The Principles of Beautiful Web Design

Best Seller!

You don’t need to go to Art School to design great looking web sites!

Book Cover: The Principles of Beautiful Web Design

Download the FREE sample chapters