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
allows you to set the checked state to “on” by default.
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
type for more on this), and the
checked attribute is used to identify which one is
selected. If you accidentally mark as
number of radio inputs that share a given
attribute, the last one that’s marked as such will be selected.
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
"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!
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>
"checked" is the
only possible value. If the input should be unchecked, simply omit the
It causes no compatibility issues, and has excellent support across all tested browsers.