type=checkbox

FilterElements

HTML: <input type="checkbox">
XHTML: <input type="checkbox"/>  or  <input type="checkbox" />

Creates a checkbox input element within a form. Checkboxes are like on/off switches that can be toggled by the user. Several checkboxes in a group may be selected at one time. When a form is submitted, only the “on” checkboxes submit values to the server.

Start/End Tags

This is an empty element. In HTML, the end tag is forbidden. In XHTML, the element must be closed with a trailing slash as just shown. Developers may include a space character before the slash for backward compatibility with older browsers.

Specifications

  • HTML 4.01
  • HTML5

align=

Values: bottom | left | middle | right | top
Deprecated. Not in HTML5. Specifies the alignment of an image.

autofocus

Values: None in HTML. (autofocus="autofocus" in XHTML)
HTML5 only. Indicates the control should have focus (be highlighted and ready for user input) when the document loads.

checked

Values: None in HTML. (checked="checked" in XHTML)
When this attribute is added to a radio button or checkbox input, the input will be checked when the page loads.

disabled

Values: None in HTML. (disabled="disabled" in XHTML)
Disables the control for user input. It can be altered only via a script. Browsers may display disabled controls differently (grayed out, for example), which could be useful for dimming certain controls until required info is supplied.

form=

Values: id of the form owner
HTML5 only. Explicitly associates the input control with its associated form (its form owner). With this method, the input control does not need to be a child of the applicable form element.

name=

Values: text
Required. Assigns a name to the control; a script program uses this name to reference the control.

readonly

Values: None in HTML. (readonly="readonly" in XHTML)
Indicates that the form input may not be modified by the user.

required

Values: None in HTML. (required="required" in XHTML)
HTML5 only. When present, indicates the input value is required.

value=

Values: text
Required. Specifies the initial value for this control.

HTML 4.01 <input> Events

onchange
Occurs when the element loses the input focus and its value has been modified since gaining focus
<p>Which of the following operating systems have you used?</p>
<ul>
<li><input type="checkbox" name="os" value="WinXP"> Windows XP</li>
<li><input type="checkbox" name="os" value="Linux" checked > Linux</li>
<li><input type="checkbox" name="os" value="OSX" checked > Macintosh OSX</li>
<li><input type="checkbox" name="os" value="DOS"> DOS</li>
</ul>

Rendered Example

Which of the following operating systems have you used?

  • Windows XP
  • Linux
  • Macintosh OSX
  • DOS