HTML Checkbox

HTML Checkbox: Choose More Than One

Checkboxes let users make multiple selections from a list of options. They're perfect for choosing favorite fruits, selecting preferences, or agreeing to terms. In this tutorial, you'll learn how to create single and grouped checkboxes, and how to handle multiple selections in a form.

Creating a Single Checkbox

A checkbox input is created using <input type="checkbox">. It's often paired with a <label> for clarity.

<input type="checkbox" id="apple" name="fruit" value="apple">
<label for="apple">Apple</label>
☐ Apple

This creates a checkbox for a single fruit. When selected, the value "apple" will be submitted with the form.

Creating Multiple Checkboxes

To allow users to select more than one option, give all checkboxes the same name with brackets — like name="fruit[]".

<p>Select your favorite fruits:</p>
<input type="checkbox" id="apple" name="fruit[]" value="apple">
<label for="apple">Apple</label><br>

<input type="checkbox" id="banana" name="fruit[]" value="banana">
<label for="banana">Banana</label><br>

<input type="checkbox" id="cherry" name="fruit[]" value="cherry">
<label for="cherry">Cherry</label>
☐ Apple  
☐ Banana  
☐ Cherry

This allows users to pick one, two, or all three options. Upon form submission, an array of selected values will be sent.

Pre-Checked Checkboxes

You can mark a checkbox as selected by default using the checked attribute.

<input type="checkbox" id="banana" name="fruit[]" value="banana" checked>
<label for="banana">Banana</label>
☑ Banana

This helps when there's a recommended or commonly chosen option.

Checkbox in Forms

Here’s how checkboxes work inside a full form:

<form action="/submit" method="post">
  <p>Pick your fruits:</p>
  <input type="checkbox" id="apple" name="fruits[]" value="apple">
  <label for="apple">Apple</label><br>

  <input type="checkbox" id="banana" name="fruits[]" value="banana">
  <label for="banana">Banana</label><br>

  <input type="checkbox" id="cherry" name="fruits[]" value="cherry">
  <label for="cherry">Cherry</label><br><br>

  <input type="submit" value="Submit">
</form>
Pick your fruits:
☐ Apple  
☐ Banana  
☐ Cherry  
[Submit]

Grouping with Fieldsets

Use <fieldset> and <legend> to group related checkboxes semantically.

<fieldset>
  <legend>Choose your fruits:</legend>
  <input type="checkbox" id="apple" name="fruit[]" value="apple">
  <label for="apple">Apple</label><br>
  <input type="checkbox" id="banana" name="fruit[]" value="banana">
  <label for="banana">Banana</label>
</fieldset>
Choose your fruits:
☐ Apple  
☐ Banana

This adds structure and improves accessibility for screen readers.

Best Practices

  • Use labels for every checkbox
  • Match label for with input id to allow clickable text
  • Use name="field[]" when handling multiple values
  • Group with fieldsets when applicable

Summary

Checkboxes are ideal when you want users to select one or more options. In this tutorial, you learned how to:

  • Create a single checkbox with label
  • Handle multiple checkboxes using [] naming
  • Set default selections with checked
  • Use <fieldset> for grouping

Check your understanding 1

Which HTML tag and input type is used to create a checkbox?
Choose one answer. You can try again.

Answer and explanation

<code><input type="checkbox"></code>

The correct syntax to create a checkbox in HTML is <input type="checkbox">. There is no separate <checkbox> tag in HTML.

Check your understanding 2

You can select multiple checkboxes at the same time in a form.
Choose one answer. You can try again.

Answer and explanation

True

Yes, checkboxes are designed for multiple selections. Unlike radio buttons, each checkbox operates independently, allowing more than one to be checked.

Check your understanding 3

Choose the option that lists all and only the correct statements.

  1. Select subjects: Maths, Physics, Chemistry
  2. Choose gender: Male, Female
  3. Opt-in for newsletter updates
  4. Choose extra-curricular activities: Dance, Music, Art
Which of the following are valid and meaningful checkbox use cases in a school admission form?
Choose one answer. You can try again.

Answer and explanation

Statements 1 and 3 and 4

Checkboxes are ideal for multiple selections like subjects or activities. For exclusive choices like gender, radio buttons should be used instead.

Check your understanding 4

What is the purpose of assigning the same name attribute to multiple checkboxes?
Choose one answer. You can try again.

Answer and explanation

To send selected values as an array during form submission

When multiple checkboxes share the same name, all checked values are sent as an array in the form data, which is helpful for capturing multiple responses under a single category.

Check your understanding 5

Checkboxes require the checked attribute to be pre-selected when the page loads.
Choose one answer. You can try again.

Answer and explanation

True

To make a checkbox pre-selected, use the checked attribute. For example: <input type="checkbox" checked>.

Check your understanding 6

Choose the option that lists all and only the correct statements.

  1. <input type="checkbox" name="activities" value="sports" checked> Sports
  2. <input type="checkbox" name="language" value="Hindi"> Hindi
  3. <checkbox name="language"> Telugu
  4. <input checkbox name="opt"> Newsletter
Which of the following are valid checkbox implementations in HTML?
Choose one answer. You can try again.

Answer and explanation

Statements 1 and 2

Only the first two are valid checkbox inputs. The others use incorrect HTML — <checkbox> is not a valid tag, and checkbox is not a valid type value on its own.

What’s Next?

Now that you’ve mastered checkboxes, it’s time to explore Radio Buttons — for single-choice questions where only one answer is allowed.

Reaching the recap and completing the quizzes are separate milestones.

    Next lesson: HTML Radio Buttons →