HTML Checkbox Tag
Web structure starts with solid HTML. Learn how HTML Checkbox Tag contributes to accessible and semantic web pages in the tutorial below.
The HTML <checkbox> tag is employed to specify rectangular containers. This element in forms enables users to choose single or multiple choices from the provided selection.
It is generated by the type attribute of the <input> tag as illustrated in the syntax below:
<input type="checkbox" name="field name" value="Initial value">
If there is a need to preselect a checkbox by default, the checked attribute should be assigned a value of "yes" as outlined in the following syntax:
<input type="checkbox" name="field name" value="Initial value" checked="yes">
Example
<html>
<head>
</head>
<body>
<form>
Programming Languages: <br>
<input type="checkbox" id="C" name="C" value="C"/>
<label>C</label> <br>
<input type="checkbox" id="Java" name="Java" value="Java" checked=?yes?/>
<label>Java</label> <br>
<input type="checkbox" id="Python" name="Python" value="Python"/>
<label>Python</label> <br>
<input type="checkbox" id="PHP" name="PHP" value="PHP"/>
<label>PHP</label>
</form>
</body>
</html>
Output:
Browser Support
| Element | Chrome | IE | Firefox | Opera | Safari |
|---|---|---|---|---|---|
<checkbox> |
Yes | Yes | Yes | Yes | Yes |