Checkboxes Radio Buttons in HTML
Indroduction of Checkboxes and Radio Buttons in HTML
Introduction
When building web forms, checkboxes and radio buttons are essential for collecting user input. These form controls allow users to make selections, whether it's multiple options or just one. In this guide, we’ll walk you through how to work with checkboxes and radio buttons in HTML — from basic syntax to practical use cases.
Whether you’re a beginner or brushing up on your HTML skills, this article will help you confidently use these input types in your web forms.
Checkboxes allow users to select multiple options from a list. Each checkbox works independently, so users can check one, multiple, or no options.
Example:
<form>
<label><input type="checkbox" name="skills" value="HTML"> HTML</label><br>
<label><input type="checkbox" name="skills" value="CSS"> CSS</label><br>
<label><input type="checkbox" name="skills" value="JavaScript"> JavaScript</label>
</form>
Radio buttons let users select only one option from a group. All radio buttons in a group share the same name
attribute.
Example:
<form>
<label><input type="radio" name="gender" value="male"> Male</label><br>
<label><input type="radio" name="gender" value="female"> Female</label><br>
<label><input type="radio" name="gender" value="other"> Other</label>
</form>
Feature | Checkboxes | Radio Buttons |
---|---|---|
Selection type | Multiple | Single |
Input type | type="checkbox" |
type="radio" |
Use case example | Skills, Interests | Gender, Age Group |
<label>
for better accessibilityAssociating inputs with labels helps users (and screen readers) understand the form.
<label for="subscribe">Subscribe</label>
<input type="checkbox" id="subscribe" name="newsletter">
name
for radio groupsThis ensures only one option can be selected at a time.
<input type="radio" name="color" value="red">
<input type="radio" name="color" value="blue">
<input type="radio" name="color" value="green">
Here’s how to handle checkbox and radio button values using JavaScript.
const checkboxes = document.querySelectorAll('input[name="skills"]:checked');
let values = [];
checkboxes.forEach((checkbox) => {
values.push(checkbox.value);
});
console.log(values);
const selected = document.querySelector('input[name="gender"]:checked');
console.log(selected.value);
✅ Checkboxes: Selecting multiple interests, newsletter topics, or product features.
🔘 Radio Buttons: Choosing payment methods, survey options, or delivery preferences.
Giving each radio button a different name
— it breaks the group behavior.
Missing value
attributes — your backend won't receive proper data.
Forgetting labels — hurts accessibility and UX.
Understanding how to work with checkboxes and radio buttons is vital for building intuitive and accessible forms. These input types may seem simple, but when used correctly, they significantly enhance user interaction and data collection.
Whether you’re creating a simple contact form or a complex survey, mastering these elements will help you build better, user-friendly websites.
Want more HTML tips and tutorials? Explore our full collection on developerIndian for beginner-friendly web development guides.