Problem Statement
Which input type allows multiple selections?
Explanation
The input type equals checkbox allows users to select multiple options from a group. Unlike radio buttons which allow only one selection, checkboxes are independent and users can check as many as they want, including none or all. Each checkbox can be checked or unchecked individually. Checkboxes with the same name attribute send their values as an array to the server. For example, if a user selects coding and design from interests, the server receives both values. Checkboxes are displayed as small squares that show a checkmark when selected. They are perfect for situations like selecting multiple interests, agreeing to terms and conditions, enabling optional features, or choosing toppings on a pizza. Always provide clear labels for checkboxes and consider grouping related checkboxes in a fieldset.
Code Solution
SolutionRead Only
<!-- Multiple checkboxes -->
<form>
<fieldset>
<legend>Select your interests:</legend>
<label>
<input type="checkbox" name="interests" value="coding">
Coding
</label>
<label>
<input type="checkbox" name="interests" value="design">
Design
</label>
<label>
<input type="checkbox" name="interests" value="marketing">
Marketing
</label>
<label>
<input type="checkbox" name="interests" value="business">
Business
</label>
</fieldset>
</form>
<!-- Single checkbox for agreement -->
<form>
<label>
<input type="checkbox" name="terms" required>
I agree to the terms and conditions
</label>
<label>
<input type="checkbox" name="newsletter">
Subscribe to newsletter (optional)
</label>
</form>