The User's Choice: Checkboxes & Radios

Master the essential form inputs for gathering user selections, from multiple-choice toppings to single-choice sizes.

Lesson ProgressStep 1 of 8

Toppings:

Size:

0 EXP

Welcome! Let's learn to build forms. We'll start with the <input> tag, the most versatile form element.


<form>

</form>

The <input> Element

The **<input>** tag is the most powerful and complex of all HTML form elements. It's a single, self-closing tag, but its behavior changes completely based on its `type` attribute.

<input type="text"> 
<input type="password"> 
<input type="checkbox"> 
<input type="radio"> 
<input type="submit">

In this lesson, we'll focus on `type="checkbox"` and `type="radio"`, which are used to create selection controls.

System Check

What attribute is most important for defining what an <input> element does?

Advanced Holo-Simulations

0 EXP

Log in to unlock these advanced training modules and test your skills.


Achievements

📝
Form Builder

Create a form with both checkboxes and radio buttons.

🔗
Input Grouper

Correctly group radio buttons using the 'name' attribute.

🤝
Accessibility Advocate

Properly associate labels with inputs using 'for' and 'id'.

Mission: Build a Pizza Order Form

Create a form with two radio buttons for `size` (Small, Large) and two checkboxes for `topping` (Pepperoni, Mushrooms).

A.D.A. Feedback:

> Awaiting input...

Challenge: Order the Form Group

A logical and accessible form structure is key. Drag the elements into the correct logical order.

<input type='radio' name='contact' id='email'>
<p>Preferred Contact Method:</p>
<label for='email'>Email</label>

Challenge: Group the Inputs

Fill in the missing parts to create a functional radio button group for 'shipping'.

<input type="" ="shipping"> Standard
<input type="radio" ="shipping"> Express

Consult A.D.A.

Unlock with Premium

Community Holo-Net

Peer Project Review

Submit your "Pizza Order Form" project for feedback from other Net-Runners.

Beyond the Box: Building Accessible and Semantic Forms

At their core, HTML forms are a conversation. You ask the user for information, and they provide it. **Checkboxes** and **radio buttons** are the simplest form of multiple-choice questions in this conversation. But building a *good* form goes beyond just using the right `type` attribute. A great form is **semantic**, **accessible**, and **easy to use**.

1. Checkbox vs. Radio: Choosing the Right Tool

The most fundamental rule is choosing the correct input for the job.

  • Checkboxes** (`type="checkbox"`): Use when the user can select **zero, one, or multiple** options from a list. Think of "Select all toppings that apply." Each checkbox is an independent yes/no switch.
  • Radio Buttons** (`type="radio"`): Use when the user must select **exactly one** option from a group. Think of "Select your size." The browser enforces this "one-or-none" rule, but only if you group them correctly.

2. The Unsung Hero: The <label> Tag

A form without labels is like a test without questions. A label describes the purpose of an input. More importantly, it's the single most critical feature for **form accessibility**.

By **associating** a label with an input, you tell screen readers what the input is for. You also create a larger clickable area—users can click the text of the label to select the radio button or check the box. There are two ways to do this:

✔️ Good: Explicit Association (Recommended)

<label for="email-opt">Email</label>
<input type="checkbox" id="email-opt">

The label's `for` attribute matches the input's `id`. This is robust and clear.

✔️ Also Good: Implicit Association

<label>
  <input type="checkbox">
  Email
</label>

Wrapping the input inside the label also works, but can be less flexible for styling.

3. Grouping with <fieldset> and <legend>

What if you have two groups of radio buttons on one form? For example, a "Size" group and a "Delivery Method" group. For sighted users, visual spacing and headings work. But for screen reader users, it can be confusing.

The semantic solution is the **<fieldset>** element, which groups related form controls. The **<legend>** element provides a caption for that group.

Semantic Grouping Example

<fieldset>
  <legend>Choose your size:</legend>

  <label for="s">Small</label>
  <input type="radio" name="size" id="s" value="s">

  <label for="m">Medium</label>
  <input type="radio" name="size" id="m" value="m">
</fieldset>

A screen reader will announce "Choose your size: group" and then read the options, giving crucial context.

4. How Data is Sent: `name` and `value`

When a form is submitted, the browser only sends data from **checked** inputs. It sends them as `name` / `value` pairs.

  • `name` Attribute:** This is the "key" for the data. For radio buttons, the shared `name` is what **groups them**. For checkboxes, giving them the same `name` (e.g., `name="topping"`) allows the server to receive an array of toppings.
  • `value` Attribute:** This is the "answer" that gets sent. If you have <input type="radio" name="size" value="large">, and the user selects it, the browser sends `size=large` to the server. **If you forget the `value` attribute, it may send `value="on"`, which is not useful!**
Key Takeaway: A professional HTML form isn't just a pile of inputs. It's a carefully structured document using <label> for accessibility, `name` for grouping and data, `value` for meaningful data, and <fieldset> for semantic context.

Form Inputs Glossary

<form>
The container element for all form inputs. It defines the `action` (where to send the data) and `method` (how to send it, e.g., POST) for submission.
<input>
The primary element for creating form controls. Its behavior is defined by its `type` attribute.
type="checkbox"
Creates a checkbox input. Allows for zero, one, or multiple selections from a group of options.
type="radio"
Creates a radio button input. Allows for only one selection from a group of options that share the same `name` attribute.
<label>
A tag that provides a descriptive caption for a form input. Crucial for accessibility, it can be associated with an input implicitly (by wrapping) or explicitly (using `for` and `id`).
name
A required attribute for form inputs. It serves two purposes:
1. It groups radio buttons together so only one can be selected.
2. It acts as the "key" for the data sent to the server (e.g., `name="size"`).
value
An attribute that defines the data to be sent to the server if that option is selected. E.g., `value="large"` sends the text "large", not just "on".
id
A unique identifier for an element. In forms, it is used by the<label> tag's `for` attribute to create an explicit association.
for
An attribute on a <label> that must match the `id` of the input it describes. This links them for accessibility and usability.
checked
A boolean attribute. When present on a checkbox or radio button, it makes that option selected by default when the page loads.
<fieldset>
A semantic tag used to group related form controls and labels within a form.
<legend>
A tag that provides a caption or title for its parent `<fieldset>`. This is excellent for accessibility.

Credibility and Trust

About the Author

Author's Avatar

Todotutorial Team

Passionate developers and educators making programming accessible to everyone.

This article was written and reviewed by our team of web development experts, who have years of experience teaching HTML and building robust and accessible web applications.

Verification and Updates

Last reviewed: October 2025.

We strive to keep our content accurate and up-to-date. This tutorial is based on the latest HTML5 specifications and is periodically reviewed to reflect industry best practices.

External Resources

Found an error or have a suggestion? Contact us!