Forms & Input Types
Forms allow users to enter and submit information. In this chapter, you will learn how to create enquiry forms, admission forms, registration forms and feedback forms using HTML.
form
Creates the main form area for collecting user information.
input
Creates fields like text, email, number, date, password and file.
label
Gives a clear name to each form field.
submit
Sends the form data to the given action page.
After This Chapter, You Will Understand
This chapter teaches how to collect user information using HTML forms.
Form Tag
Understand form, action and method attributes.
Input Fields
Use different input types for different data.
Labels
Connect labels with fields for clarity and accessibility.
Validation
Use required, minlength, maxlength and pattern basics.
Creating a Simple HTML Form
A form is used when users need to enter and submit information.
1 form Tag
The <form> tag creates a form section. It commonly uses action and method attributes.
# form fields here
</form>
method: Specifies how form data will be sent.
2 label and input
A label describes the input field. An input field allows the user to enter data.
<input type="text" id="name" name="name">
Important HTML Input Types
Different input types help collect different kinds of data correctly.
| Input Type | Use | Example Code |
|---|---|---|
| text | Normal text such as name | <input type="text"> |
| Email address | <input type="email"> | |
| password | Hidden password field | <input type="password"> |
| number | Numeric value | <input type="number"> |
| tel | Phone number | <input type="tel"> |
| date | Date selection | <input type="date"> |
| radio | Select one option | <input type="radio"> |
| checkbox | Select multiple options | <input type="checkbox"> |
| file | Upload a file | <input type="file"> |
| submit | Submit form data | <input type="submit"> |
textarea, select, option, fieldset and button
HTML forms also provide special controls for messages, dropdowns and grouped fields.
3 textarea and select
The textarea tag is used for long messages. The select and option tags are used for dropdown menus.
<select name="course">
<option>HTML with CSS</option>
<option>MS Excel</option>
</select>
4 fieldset and legend
The fieldset tag groups related fields, and legend gives a title to that group.
<legend>Personal Details</legend>
<input type="text">
</fieldset>
Basic HTML Form Validation
Validation helps collect correct and complete data from users.
required
Forces the user to fill the field before submitting.
minlength / maxlength
Controls minimum and maximum number of characters.
placeholder
Shows hint text inside the input field.
Where Forms Are Used
Forms are important for business, education, enquiries and online services.
Admission
Student admission and registration forms.
Enquiry
Course enquiry and contact forms.
Upload
Photo, document and certificate upload forms.
Feedback
Reviews, ratings and message forms.
Sample Enquiry Form Preview
Create a Student Enquiry Form
Edit the code and click Run Code to see the output.
Mistakes Students Should Avoid
Clean forms are important for user experience and professional websites.
Wrong Habits
- Creating input fields without labels
- Using text input for email instead of email type
- Forgetting name attribute in form fields
- Using radio buttons with different name values
- Not adding required fields where necessary
Correct Habits
- Use label for every important field
- Use correct input type for correct data
- Use name attribute for submitted fields
- Group related radio buttons with same name
- Use required for compulsory fields
Test Your Understanding
Select the correct answers and check your score.
1. Which tag is used to create a form?
2. Which input type is best for email address?
3. Which tag describes an input field?
4. Which tag is used for long messages?
5. Which attribute makes a field compulsory?
Remember These Points
Revise these before moving to Chapter 9.
form
The form tag creates the main form section.
input
The input tag creates fields for user data.
label
The label tag gives a clear name to a form field.
textarea
The textarea tag is used for long messages.
select
The select tag creates a dropdown list.
required
The required attribute makes a field compulsory.