Lesson 2.2 β Input Types
π Understanding Different Types of User Input Fields in HTML Forms
π― Learning Objectives
After completing this lesson, students will be able to:
β Understand HTML Input Types
β Create Text Fields
β Create Password Fields
β Create Email Fields
β Create Number Fields
β Create Date Fields
β Create Telephone Fields
β Create URL Fields
β Create Search Fields
β Use Different Input Types Professionally
π Introduction
In the previous lesson, we learned that:
<input>
creates an input field.
But think about this:
Should a password field look the same as a name field?
β No
Should a date field look the same as a phone number field?
β No
HTML provides different input types for different purposes.
Example:
- Name β Text Field
- Password β Password Field
- Email β Email Field
- Age β Number Field
- Date of Birth β Date Field
π€ What is an Input Type?
An input type tells the browser:
What kind of information the user should enter.
Syntax:
<input type="value">
π Common Input Types
Most important input types:
type="text"
Β
type="password"
type="email"
type="number"
Β
type="tel"
type="date"
type="url"
type="search"
1οΈβ£ Text Input
Most common input type.
Used for:
- Name
- City
- College Name
- Branch
Syntax
<input type="text">
Example
<label>Name:</label>
<input type="text">
Output
Name:
[____________]
π Placeholder Attribute
Provides guidance to users.
Example:
<input type="text"
placeholder="Enter Your Name">
Output
[Enter Your Name]
2οΈβ£ Password Input
Used for passwords.
Characters are hidden automatically.
Syntax
<input type="password">
Example
<label>Password:</label>
<input type="password">
Output
Password:
[********]
Why Use Password Fields?
Protects user privacy.
3οΈβ£ Email Input
Used for email addresses.
Syntax
<input type="email">
Example
<label>Email:</label>
<input type="email">
Output
Email:
[____________]
Benefit
Modern browsers can validate email format automatically.
Example:
β studentgmail.com
4οΈβ£ Number Input
Used for numbers only.
Syntax
<input type="number">
Example
<label>Age:</label>
<input type="number">
Output
Age:
[____]
Benefit
Only numeric values are allowed.
Example with Limits
<input type="number"
min="1"
max="100">
Meaning
Allowed range:
1 to 100
5οΈβ£ Telephone Input
Used for mobile numbers.
Syntax
Β
<input type="tel">
Example
<label>Mobile:</label>
<input type="tel">
Output
Mobile:
[____________]
Real World Example
Admission Forms
Registration Forms
Contact Forms
6οΈβ£ Date Input
Used for selecting dates.
Syntax
<input type="date">
Example
<label>Date of Birth:</label>
<input type="date">
Output
Date Picker appears.
Benefit
Users can select dates easily.
Example
π
25-12-2026
7οΈβ£ URL Input
Used for website links.
Syntax
<input type="url">
Example
<label>Website:</label>
<input type="url">
Output
Website:
[____________]
Example Value
https://www.google.com
Real World Use
Portfolio Websites
Business Websites
Company Profiles
8οΈβ£ Search Input
Used for search boxes.
Syntax
<input type="search">
Example
<label>Search:</label>
<input type="search">
Output
Search:
[____________]
Real World Example
Google Search
YouTube Search
Amazon Search
π― Readonly Input
User can view but cannot edit.
Example
<input type="text"
value="Polytechnic"
readonly>
Output
Polytechnic
Cannot be changed.
π― Disabled Input
Completely disabled.
Example
<input type="text"
value="Disabled"
disabled>
Output
Greyed out field.
π― Required Attribute
Makes a field mandatory.
Example
<input type="text"
required>
Result
Form cannot be submitted if field is empty.
π Complete Example Program
<!DOCTYPE html>
<html>
<head>
<title>Input Types Example</title>
</head>
<body>
<h1>Student Registration Form</h1>
<form>
<label>Name:</label>
<input type="text">
<br><br>
<label>Password:</label>
<input type="password">
<br><br>
<label>Email:</label>
<input type="email">
<br><br>
<label>Age:</label>
<input type="number">
<br><br>
<label>Mobile:</label>
<input type="tel">
<br><br>
<label>Date of Birth:</label>
<input type="date">
<br><br>
<label>Website:</label>
<input type="url">
<br><br>
<label>Search:</label>
<input type="search">
</form>
</body>
</html>
π― Expected Output
Form containing:
β Name Field
β Password Field
β Email Field
β Number Field
β Mobile Field
β Date Picker
β Website Field
β Search Field
π« Real World Example β College Registration Form
<form>
<label>Student Name:</label>
<input type="text">
<br><br>
<label>Email:</label>
<input type="email">
<br><br>
<label>Mobile:</label>
<input type="tel">
<br><br>
<label>Date of Birth:</label>
<input type="date">
</form>
β οΈ Common Beginner Mistakes
Mistake 1
Using Text for Password
Wrong:
<input type="text">
Correct:
<input type="password">
Mistake 2
Using Text for Email
Wrong:
<input type="text">
Correct:
<input type="email">
Mistake 3
Forgetting Placeholder
Wrong:
<input type="text">
Better:
<input type="text"
placeholder="Enter Your Name">
π Best Practices
β Use the correct input type.
β Use placeholders for guidance.
β Use required fields when necessary.
β Use email type for email addresses.
β Use password type for passwords.
β Use date picker for dates.
π Mini Project β Student Registration Form
Create a form containing:
- Name
- Mobile Number
- Date of Birth
- Password
Use proper input types for each field.
π Practical Activity
Create a form containing:
β Name
β Email
β Mobile Number
β Age
β Date of Birth
β Website
Run it in Chrome Browser.
π Assignment
Assignment 2.2
- What is an input type?
- Which input type is used for passwords?
- Which input type is used for emails?
- Which input type is used for dates?
- Which input type is used for phone numbers?
- What is a placeholder?
- Create a form using at least five input types.
π§ Quiz
Q1. Which input type hides characters?
A. text
B. email
C. password
D. date
β Answer: C
Q2. Which input type is used for email addresses?
A. text
B. mail
C. email
D. url
β Answer: C
Q3. Which input type displays a date picker?
A. calendar
B. time
C. date
D. day
β Answer: C
Q4. Which input type is used for phone numbers?
A. mobile
B. tel
C. phone
D. number
β Answer: B
Q5. Which attribute makes a field mandatory?
A. readonly
B. disabled
C. required
D. placeholder
β Answer: C
π Lesson Summary
β Input types help collect different types of user information.
β
text is used for normal text.
β
password hides user input.
β
email validates email addresses.
β
number accepts numeric values.
β
tel is used for phone numbers.
β
date provides a date picker.
β Using correct input types improves user experience.