Protected Learning Content

AICPE Gurukul content is created for learning purposes. Printing, copying and unauthorized reuse are restricted.

AICPE Learning Hub HTML with CSS
Chapter 8
Forms & Input Types
Chapter 8 | User Input

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.

Learning Objectives

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.

Form 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 action="submit.php" method="post">
    # form fields here
</form>
action: Specifies where form data will be sent.
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.

<label for="name">Full Name</label>
<input type="text" id="name" name="name">
Professional Tip: Always use labels with form fields. It improves clarity and accessibility.
Input Types

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 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">
Smart Use: Use the correct input type. For email, use type="email"; for date, use type="date"; for number, use type="number".
Form Controls

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.

<textarea name="message"></textarea>

<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.

<fieldset>
    <legend>Personal Details</legend>
    <input type="text">
</fieldset>
Practice Task: Create a student admission form using fieldset and legend.
Validation Basics

Basic HTML Form Validation

Validation helps collect correct and complete data from users.

required

Forces the user to fill the field before submitting.

<input type="text" required>

minlength / maxlength

Controls minimum and maximum number of characters.

<input minlength="3" maxlength="30">

placeholder

Shows hint text inside the input field.

<input placeholder="Enter name">
Professional Tip: Browser validation is helpful, but important forms should also be validated on the server side using PHP or backend code.
Real Website Uses

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

Try It Yourself

Create a Student Enquiry Form

Edit the code and click Run Code to see the output.

HTML Code Edit and run
Output Preview Browser result
Practice Task: Add a date of birth field, file upload field and checkbox for “I agree to terms”.
Common Mistakes

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
Remember: HTML forms collect data, but backend language like PHP is needed to save or process that data.
Quick Quiz

Test Your Understanding

Select the correct answers and check your score.

1. Which tag is used to create a form?

The form tag creates the main form area.

2. Which input type is best for email address?

type='email' is used for email address fields.

3. Which tag describes an input field?

The label tag gives a name or description to an input field.

4. Which tag is used for long messages?

The textarea tag is used for long text messages.

5. Which attribute makes a field compulsory?

The required attribute makes a field compulsory.
Quick Revision

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.