A form acts as a bridge between the user and the website. It collects information entered by users and sends it to a server where it can be processed, stored, or validated.
Without HTML forms, websites would only display information. Users wouldn't be able to interact with them by entering data.
In this blog, we'll learn everything about HTML Forms, including how they work, their important attributes, and the most commonly used form elements.
What is HTML Form?
An HTML Form is a section of a webpage used to collect user input.
It contains different input fields such as:
Text boxes
Password fields
Radio buttons
Checkboxes
Drop-down lists
File upload
Buttons
The collected information is usually sent to a web server for processing.
Syntax
<form>
Form Elements
</form>
What Happens Without HTML Forms?
Imagine visiting these websites without forms:
Gmail - You cannot enter your email or password.
Amazon - You cannot search products.
Instagram - You cannot login or sign up.
The HTML <form> element is used to create an HTML form for user input.
Important Attributes of the <form> Tag
action
method
name
novalidate
autocomplete
target
action Attribute
- The action attribute tells the browser where to send the form data after the user clicks the Submit button.
<form action="login.php">
Method Attribute
The method attribute tells how the form data should be sent to the server.
There are two commonly used methods:
GET
POST
The GET method sends form data through the URL. It is mainly used when the data is not sensitive, such as search queries.
<form action="login.php" method="GET">
The POST method sends form data inside the request body, so it does not appear in the URL.
<form action="search.php" method="POST">
name Attribute
- The name attribute gives a name to the form or its controls. When the form is submitted, the server identifies each value using its name.
<input type="text" name="username">
<input type="password" name="password">
novalidate Attributes
- HTML checks required fields before submitting.
<input type="email" required>
- The browser won't submit until a valid email is entered.
autocomplete Attribute
- This attribute tells the browser whether it should remember previously entered values.
<form autocomplete="on">
target Attribute
- The target attribute specifies where the server's response will be displayed after the form is submitted.
_self (Default)- Opens the response in the same browser tab.
<form target="_self">
_blank - Opens the response in a new browser tab.
<form target="_blank">
HTML Forms are one of the most powerful features of HTML because they allow users to interact with websites. Understanding the <form> tag, its attributes like action and method, and common form elements is an essential step toward becoming a web developer
Top comments (0)