Course contentsShow
← Web Development
Lesson 96 of 2,9822. HTML FundamentalsFree lesson

Checkbox and Radio Inputs

Creating single and grouped selection controls with proper name attributes for form submission.

Checkbox and Radio Inputs

You'll learn how to create selectable options that let users pick one or more choices in a form.

What Are They?

Checkboxes and radio buttons are input types that let users make selections by clicking boxes or circles. Think of them like a paper form where you mark boxes or fill in circles:

  • Checkboxes: Users can select multiple options (like toppings on a pizza)
  • Radio buttons: Users can select only one option from a group (like choosing a shirt size: S, M, or L)

Creating a Checkbox

<input type="checkbox" name="newsletter" value="yes">
<label for="newsletter-input">Subscribe to newsletter</label>

Checkboxes stand alone or in groups. Each can be checked independently.

Creating Radio Buttons

Radio buttons must share the same name attribute to work as a group:

<input type="radio" name="size" value="small">
<label>Small</label>

<input type="radio" name="size" value="medium">
<label>Medium</label>

<input type="radio" name="size" value="large">
<label>Large</label>

All three have name="size", so selecting one automatically deselects the others—just like old car radio buttons where pushing one made the others pop out.

The Name Attribute is Critical

The name attribute determines:

  • For checkboxes: What key is sent when the form submits
  • For radio buttons: Which inputs belong to the same group and what key is sent

The value attribute specifies what data gets sent to the server when that option is selected.

Key Takeaway: Checkboxes allow multiple selections and work independently, while radio buttons allow only one selection per group when they share the same name attribute.