input type="checkbox" ElementThe input type="checkbox" element is an inline element declared by the XHTML 1.1 Forms Module
Elements in the Forms Module are:form | label | textarea | select | optgroup | option | button | fieldset | legend | input type="button" | input type="checkbox" | input type="file" | input type="hidden" | input type="image" | input type="password" | input type="radio" | input type="reset" | input type="submit" | input type="text"
An input type="checkbox" element
may be used within a form
to create a checkbox, which may be toggled by the user between
a checked and an un-checked state. If the checkbox is to be pre-checked
(i.e. checked when the form is first rendered) the
input type="checkbox" element should be given the
checked attribute.
For example, the first checkbox below should initially be un-checked and the second initially checked:
<label for="terms">I accept the Terms & Conditions above:</label>
<input type="checkbox" name="terms" id="terms" value="yes" /><br />
<label for="emails">Please send me interesting emails:</label>
<input type="checkbox" name="emails" id="emails" value="1" checked="checked" />
This example renders as:
The value
attribute specifies the value to be sent in the name=value pair to the processing URI
if the checkbox is checked when the form is submitted. For example, if the form containing
the example checkboxes above were submitted with both buttons checked, two pairs would be
submitted to the processing URI: terms=yes and emails=1.
For an unchecked checkbox, no pair is sent at all.
Note: Although the
value
attribute is technically optional - and most browsers will make up a value to send
(usually "on") if required - you should always specify a value for your checkboxes.
This is based on a note in the W3C HTML 4.01 specifications
(*HTML 4.01 value attribute of the input element)
which says that the value attribute is optional on
input elements except when the
type attribute has the value
"radio" or "checkbox".
A set of checkboxes, each with the same value for its name
attribute, is logically equivalent to a select list
with the multiple attribute specified.
For example, the two example divs below are logically equivalent:
<div><fieldset>
<legend>I wish to help on:</legend>
<label for="mon">Monday</label>
<input type="checkbox" name="days" value="1" id="mon" checked="checked" /><br />
<label for="tue">Tuesday</label>
<input type="checkbox" name="days" value="2" id="tue" /><br />
<label for="wed">Wednesday</label>
<input type="checkbox" name="days" value="3" id="wed" checked="checked" /><br />
<label for="thu">Thursday</label>
<input type="checkbox" name="days" value="4" id="thu" /><br />
<label for="fri">Friday</label>
<input type="checkbox" name="days" value="5" id="fri" /><br />
<label for="sat">Saturday</label>
<input type="checkbox" name="days" value="6" id="sat" /><br />
<label for="sun">Sunday</label>
<input type="checkbox" name="days" value="7" id="sun" />
</fieldset></div>
<div>
<label for="days">I wish to help on:</label>
<select id="days" name="days" multiple="multiple" size="4">
<option value="1" selected="selected">Monday</option>
<option value="2">Tuesday</option>
<option value="3" selected="selected">Wednesday</option>
<option value="4">Thursday</option>
<option value="5">Friday</option>
<option value="6">Saturday</option>
<option value="7">Sunday</option>
</select>
</div>
These two examples render as:
As shown above, a semantically-significant method to add an overall label to a set of checkboxes, stating their
combined purpose, is to use enclose the set within a
fieldset element and label it using a
legend element. (Appearance, including removal of any border,
can be controlled using CSS.)
The label
element itself serves this purpose for the select list.
See also: input type="radio".
Although the type attribute is not #REQUIRED
on the input element, its default value is "text" and so must be present on input type="checkbox".
input type="checkbox" element are listed below:accesskey [ type Character ]checked [ type Boolean ]disabled [ type Boolean ]name [ type CDATA ]name attribute is not present, no data will be sent for this element). The value sent (in a name=value pair) is that of the value attribute of this element - but data is sent only for those checkboxes which are checked at the time of submission.Note: Although technically optional, a note in the *Forms Module DTD says that the name attribute is required on all input elements except "submit" and "reset"
tabindex [ type Number ]value [ type CDATA ]Note: Although this attribute is optional, and most browsers will make up a value to send (usually "on") if required, you should always specify a value attribute for your checkboxes (ref: *HTML 4.01 value attribute of the input element).
onblur [ type Script ]onchange [ type Script ]onfocus [ type Script ]input type="checkbox" element are listed below:class [ type NMTOKENS ]id [ type ID ]style [ type CDATA ], from the Style Attribute Module (deprecated)title [ type Text ]xmlns [ type URI - #FIXED 'http://www.w3.org/1999/xhtml' ]dir [ type Enumeration (ltr | rtl) ], from the Bi-directional Text Modulexml:lang [ type LanguageCode ]All attributes in the
Events Attribute Collection
are supported:onclick, ondblclick, onmousedown, onmouseup, onmouseover, onmousemove, onmouseout, onkeypress, onkeydown, onkeyup
input type="checkbox" element is:
EMPTY
See Content Model & Nesting for information about Content Model syntax and Nesting Groups.
input type="checkbox"This element is empty and may have no children.
input type="checkbox"abbr, acronym, address, cite, code, dfn, div, em, h1 - h6, kbd, p, q, samp, span, strong, varadd, dt, licaption, td, thfieldset, label, legendb, big, i, small, sub, sup, ttdel, insbdoobjectrb, rt