Course Content
Project file
0/1
Complete Web Designing Course for Beginners

πŸ“˜ MODULE 2 – Forms & User Input

πŸ”˜ Lesson 2.3 – Radio Buttons & Checkboxes

πŸ“ Allowing Users to Select One or Multiple Options in Forms


🎯 Learning Objectives

After completing this lesson, students will be able to:

βœ… Understand Radio Buttons

βœ… Understand Checkboxes

βœ… Know the difference between Radio Buttons and Checkboxes

βœ… Create Single Choice Questions

βœ… Create Multiple Choice Questions

βœ… Build Professional Forms

βœ… Create Admission and Registration Forms


πŸ“– Introduction

Imagine a college admission form.

Question:

Gender

  • Male
  • Female
  • Other

Student can select:

βœ… Only One Option


Another question:

Skills

  • HTML
  • CSS
  • JavaScript
  • Python

Student can select:

βœ… One Skill

βœ… Two Skills

βœ… Three Skills

βœ… All Skills


To solve these situations HTML provides:

πŸ”˜ Radio Buttons

and

β˜‘οΈ Checkboxes


πŸ€” What is a Radio Button?

Radio Buttons allow users to select:

Only One Option

from multiple choices.


Real Life Examples

Gender Selection

Β 
( ) Male

( ) Female

( ) Other
Β 

Only one can be selected.


Payment Method

Β 
( ) Cash

( ) UPI

( ) Debit Card
Β 

Only one option.


🌟 Creating Radio Buttons

Syntax:

Β 
<input type="radio">
Β 

Example

<label>Male</label>

<input type="radio">

Output

β—‹ Male

Multiple Radio Buttons

<input type="radio"> Male

<br>

<input type="radio"> Female

<br>

<input type="radio"> Other

Problem

All buttons work independently.

Multiple selections become possible.

❌ Wrong


🎯 Name Attribute

Radio buttons must share the same name.

Example:

<input type="radio" name="gender">

Correct Example

<input type="radio" name="gender">

Male

<br>

<input type="radio" name="gender">

Female

<br>

<input type="radio" name="gender">
Other
Β 

Output

Β 
β—‹ Male

β—‹ Female

β—‹ Other

Now only one option can be selected.

βœ… Correct


🌟 Value Attribute

Stores selected data.

Example:

<input
type="radio"
name="gender"
value="Male">

Example

<input
type="radio"
name="gender"
value="Male">

Male

Why Value is Important?

When the form is submitted:

Β 
Male
Β 

is stored.


🎯 Checked Attribute

Used to select a default option.

Example:

<input
type="radio"
name="gender"
checked>

Result

Option selected automatically.


Example

<input
type="radio"
name="gender"
checked>

Male

<br>

<input
type="radio"
name="gender">

Female

Output

Male selected by default.


β˜‘οΈ What is a Checkbox?

Checkboxes allow users to select:

Multiple Options


Real Life Example

Skills

Β 
☐ HTML

☐ CSS

☐ JavaScript

☐ Python
Β 

Students can select:

βœ” HTML

βœ” CSS

βœ” JavaScript

All together.


Creating Checkboxes

Syntax:

<input type="checkbox">

Example

Β 
Β 
<input type="checkbox">

HTML

Output

Β 
☐ HTML
Β 

Multiple Checkboxes

<input type="checkbox">

HTML

<br>

<input type="checkbox">

CSS

<br>

<input type="checkbox">

JavaScript

Output

Β 
☐ HTML

☐ CSS

☐ JavaScript

🌟 Value Attribute in Checkboxes

Example:

<input
type="checkbox"
value="HTML">

Example

<input
type="checkbox"
value="HTML">

HTML

Result

When selected:

Β 
HTML
Β 

is stored.


🎯 Checked Checkbox

Default selected checkbox.

Example:

<input
type="checkbox"
checked>

Output

β˜‘ HTML

Already selected.


🌟 Radio vs Checkbox

Radio Button Checkbox
Single Choice Multiple Choices
One Option Many Options
Circular Shape Square Shape
Gender Selection Skills Selection
Payment Method Hobbies

Example – Gender Selection

<h3>Gender</h3>

<input
type="radio"
name="gender">

Male

<br>

<input
type="radio"
name="gender">

Female

<br>

<input
type="radio"
name="gender">

Other

Output

Β 
β—‹ Male

β—‹ Female

β—‹ Other
Β 

Only one option.


Example – Skills Selection

<h3>Skills</h3>

<input
type="checkbox">

HTML

<br>

<input
type="checkbox">

CSS

<br>

<input
type="checkbox">

JavaScript

<br>

<input
type="checkbox">

Python

Output

Β 
☐ HTML

☐ CSS

☐ JavaScript

☐ Python
Β 

Multiple selections allowed.


🎯 Complete Example Program

<!DOCTYPE html>

<html>

<head>

<title>Radio and Checkbox Example</title>

</head>

<body>

<h1>Student Registration Form</h1>

<form>

<h3>Gender</h3>

<input
type="radio"
name="gender">

Male

<br>

<input
type="radio"
name="gender">

Female

<br>

<input
type="radio"
name="gender">

Other

<br><br>

<h3>Skills</h3>

<input
type="checkbox">

HTML

<br>

<input
type="checkbox">

CSS

<br>

<input
type="checkbox">

JavaScript

<br>

<input
type="checkbox">

Python

</form>

</body>

</html>

🎯 Expected Output

Student Registration Form

Gender

β—‹ Male

β—‹ Female

β—‹ Other


Skills

☐ HTML

☐ CSS

☐ JavaScript

☐ Python


🏫 Real World Example – College Admission Form

<h3>Gender</h3>

<input
type="radio"
name="gender">

Male

<br>

<input
type="radio"
name="gender">

Female

<br>

<input
type="radio"
name="gender">

Other

<br><br>

<h3>Interests</h3>

<input
type="checkbox">

Sports

<br>

<input
type="checkbox">

Music

<br>

<input
type="checkbox">

Programming

🌟 Using Labels with Radio Buttons

Professional method:

<label>

<input
type="radio"
name="gender">

Male

</label>

Advantage

Clicking on text also selects the option.


⚠️ Common Beginner Mistakes


Mistake 1

Different Names for Radio Buttons

Wrong:

<input type="radio" name="a">

<input type="radio" name="b">

Both can be selected.

❌ Wrong


Correct:

<input type="radio" name="gender">

<input type="radio" name="gender">

Mistake 2

Using Radio Instead of Checkbox

Wrong:

Skills:

<input type="radio">

Only one skill can be selected.


Correct:

Β 
<input type="checkbox">
Β 

Mistake 3

Forgetting Value Attribute

Wrong:

<input type="radio">

Better:

<input
type="radio"
value="Male">

🌟 Best Practices

βœ… Use Radio Buttons for single choice.

βœ… Use Checkboxes for multiple choices.

βœ… Always use labels.

βœ… Use value attributes.

βœ… Use meaningful names.


πŸ† Mini Project – Student Interest Form

Create:

Gender

β—‹ Male

β—‹ Female

β—‹ Other


Skills

☐ HTML

☐ CSS

☐ JavaScript

☐ Python


Hobbies

☐ Reading

☐ Gaming

☐ Music

☐ Sports


πŸ“ Practical Activity

Create a form containing:

Gender

Radio Buttons


Branch

Radio Buttons


Skills

Checkboxes


Hobbies

Checkboxes

Run it in Chrome Browser.


πŸ“‹ Assignment

Assignment 2.3

  1. What is a Radio Button?
  2. What is a Checkbox?
  3. What is the difference between them?
  4. Why is the name attribute important?
  5. What is the purpose of the value attribute?
  6. Create a gender selection form.
  7. Create a skills selection form.

🧠 Quiz

Q1. Which input type creates radio buttons?

A. check

B. select

C. radio

D. option

βœ… Answer: C


Q2. Radio buttons are used for?

A. Multiple choices

B. Single choice

C. Images

D. Tables

βœ… Answer: B


Q3. Which input type creates checkboxes?

A. radio

B. select

C. checkbox

D. option

βœ… Answer: C


Q4. Checkboxes allow?

A. One selection

B. Multiple selections

C. No selection

D. Images

βœ… Answer: B


Q5. Which attribute groups radio buttons together?

A. value

B. id

C. name

D. checked

βœ… Answer: C


πŸ“Œ Lesson Summary

βœ… Radio Buttons allow one option to be selected.

βœ… Checkboxes allow multiple options to be selected.

βœ… Radio buttons use the same name attribute.

βœ… The value attribute stores data.

βœ… The checked attribute selects options by default.

βœ… Radio buttons and checkboxes are widely used in registration and admission forms.

Scroll to Top