The HTML input element <input type="checkbox">
is an input element to enter an array of different values. The value attribute is used to define the value submitted by the checkbox. The checked attribute is used to indicate whether this item is selected. The indeterminate attribute is used to indicate that the checkbox is in an indeterminate state (on most platforms, this draws a horizontal line across the checkbox).
Attributes
This element includes the global attributes.
checked
-
When the value of the type attribute is
checkbox
, the presence of this Boolean attribute indicates that the control is selected by default; otherwise it is ignored. value
- The initial value of the control. If omitted, the result of getting the value property of the element will be the string "on".
Note that when reloading the page, Gecko and IE will ignore the value specified in the HTML source, if the value was changed before the reload.
Example
<label><input type="checkbox" id="cbox1" value="first_checkbox"> This is the first checkbox</label><br> <input type="checkbox" id="cbox2" value="second_checkbox"> <label for="cbox2">This is the second checkbox</label>
This creates two checkboxes, which look like this:
Specifications
Specification | Status | |
WHATWG HTML Living Standard The definition of '<checkbox>' in that specification. |
Living Standard | |
HTML5 The definition of '<checkbox>' in that specification. |
Recommendation | |
HTML 4.01 Specification The definition of '<checkbox>' in that specification. |
Recommendation |
Browser compatibility
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | 1.0 | 1.0 (1.7 or earlier) | 2 or earlier | 1.0 | 1.0 |
type=checkbox | 1.0 | 1.0 (1.7 or earlier) 3.6 (1.9.2) for indeterminate value |
2 | 1.0 | 1.0 |
Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | (Yes) | 4.0 (2.0) | (Yes) | (Yes) | (Yes) |
type=checkbox | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |