Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 1016423 of <input type="checkbox">

  • Revision slug: Web/HTML/Element/input/checkbox
  • Revision title: <input type="checkbox">
  • Revision id: 1016423
  • Created:
  • Creator: Tigt
  • Is current revision? No
  • Comment Removed attributes that explicitly ignore checkboxes

Revision Content

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.

{{htmlattrdef("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.

{{htmlattrdef("value")}}
The initial value of the control. This attribute is optional except when the value of the type attribute is checkbox.
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:

{{EmbedLiveSample("Example")}}

Specifications

Specification Status
{{SpecName('HTML WHATWG', 'forms.html#checkbox-state-(type=checkbox)', '<checkbox>')}} {{Spec2('HTML WHATWG')}}  
{{SpecName('HTML5 W3C', 'forms.html#checkbox-state-(type=checkbox)', '<checkbox>')}} {{Spec2('HTML5 W3C')}}  
{{SpecName('HTML4.01', 'interact/forms.html#checkbox', '<checkbox>')}} {{Spec2('HTML4.01')}}  

Browser compatibility

{{CompatibilityTable}}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1.0 {{CompatGeckoDesktop("1.7 or earlier")}} 2 or earlier 1.0 1.0
type=checkbox 1.0 {{CompatGeckoDesktop("1.7 or earlier")}}
{{CompatGeckoDesktop("1.9.2")}} for indeterminate value
2 1.0 1.0
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{CompatVersionUnknown}} {{CompatGeckoMobile("2.0")}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}
type=checkbox {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}

Revision Source

<p><span class="seoSummary">The HTML input element <strong><code>&lt;input type="checkbox"&gt;</code></strong> is an input element to enter an array of different values. The <strong>value</strong> attribute is used to define the value submitted by the checkbox. The <strong>checked</strong> attribute is used to indicate whether this item is selected. The <strong>indeterminate</strong> attribute is used to indicate that the checkbox is in an indeterminate state (on most platforms, this draws a horizontal line across the checkbox).</span></p>

<h2 id="Attributes">Attributes</h2>

<p>This element includes the <a href="https://developer.mozilla.org/en-US/docs/HTML/Global_attributes">global attributes</a>.</p>

<dl>
 <dt>{{htmlattrdef("checked")}}</dt>
 <dd>
 <p>When the value of the <strong>type</strong> attribute is <code>checkbox</code>, the presence of this Boolean attribute indicates that the control is selected by default; otherwise it is ignored.</p>
 </dd>

 <dt>{{htmlattrdef("value")}}</dt>
 <dd>The initial value of the control. This attribute is optional except when the value of the <strong>type</strong> attribute is <code>checkbox</code>.<br />
 Note that when reloading the page, Gecko and IE <a class="link-https" href="https://bugzilla.mozilla.org/show_bug.cgi?id=46845#c186">will ignore the value specified in the HTML source</a>, if the value was changed before the reload.</dd>
</dl>

<h2 id="Example">Example</h2>

<pre class="brush: html">
&lt;label&gt;&lt;input type="checkbox" id="cbox1" value="first_checkbox"&gt; This is the first checkbox&lt;/label&gt;&lt;br&gt;

&lt;input type="checkbox" id="cbox2" value="second_checkbox"&gt; &lt;label for="cbox2"&gt;This is the second checkbox&lt;/label&gt;
</pre>

<p>This creates two checkboxes, which look like this:</p>

<p>{{EmbedLiveSample("Example")}}</p>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <td>Specification</td>
   <td>Status</td>
  </tr>
  <tr>
  </tr>
  <tr>
   <td>{{SpecName('HTML WHATWG', 'forms.html#checkbox-state-(type=checkbox)', '&lt;checkbox&gt;')}}</td>
   <td>{{Spec2('HTML WHATWG')}}</td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>{{SpecName('HTML5 W3C', 'forms.html#checkbox-state-(type=checkbox)', '&lt;checkbox&gt;')}}</td>
   <td>{{Spec2('HTML5 W3C')}}</td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>{{SpecName('HTML4.01', 'interact/forms.html#checkbox', '&lt;checkbox&gt;')}}</td>
   <td>{{Spec2('HTML4.01')}}</td>
   <td>&nbsp;</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<p>{{CompatibilityTable}}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>1.0</td>
   <td>{{CompatGeckoDesktop("1.7 or earlier")}}</td>
   <td>2 or earlier</td>
   <td>1.0</td>
   <td>1.0</td>
  </tr>
  <tr>
   <td>type=checkbox</td>
   <td>1.0</td>
   <td>{{CompatGeckoDesktop("1.7 or earlier")}}<br />
    {{CompatGeckoDesktop("1.9.2")}} for <code>indeterminate</code> value</td>
   <td>2</td>
   <td>1.0</td>
   <td>1.0</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatGeckoMobile("2.0")}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
  </tr>
  <tr>
   <td>type=checkbox</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>
Revert to this revision