HTML input: checkbox
allowing the user to select one or more out of several options
Essentials
The <input>
field for type="checkbox"
looks like this:
Takeaways
Unlike
type="radio"
the checkboxes do not need the same value in thename
attributeThe checkbox does have an optional
value
attribute which will submit along with thename
which will act as a "key" or property nameWhen the checkbox does not have a
value
then the value would simply beon
The
checked
attribute makes the checkbox checked by defaultWe can do this for more than one checkbox
The
<label>
for eachtype="checkbox"
corresponds with each checkbox'sid
value (not thename
)The
<label>
also allows the user to click on the label instead of the checkbox for greater accessibility
Last updated