November 22, 2026
What is the HTML Form Tag (<form></form>) and how is it used?
A form is an important element of HTML language, which contain other form elements such as textboxes, radio buttons etc. Through forms we can send data from client side (browser) to server side. If you want to get some information from your website visitors or if you want to contact with your website visitors, so for it, you will have to create forms in your webpage. And whatever information they will fill through these form you can get it at server side.
Usually a form can contain input elements such as textboxes, radio buttons, check boxes, drop down list boxes, textarea, hidden fields submit buttons reset buttons, password fields etc. Whenever user submit any form then data is sent to server.
A form starts with <form> tag and ends with </form> tag form has some attribute. Syntax for creating forms :
Code
<form action="URL" method="post">
Form contents
</form>
Attribute of form tag
| Attribute |
Description |
| Action |
This attribute identifies the URL (uniform recourse locator) of the script, where data of the form will be sent. In the absence of this attribute data of the form will be sent to the base URL or on the same page where form is written. Syntax is mentioned below:
action="file_name.php"
|
| Method |
Whenever you submit form in HTML, form's data send to server in a method such as post or get method. So with method attribute you can send data to server either with post or get.
method="get" or method="post"
Difference between get and post method.
Whenever you send data through get method then data gets display in the URL. But If you send data through post method then data does not get display in URL. So if you have critical information so you should use post method.
You can sent more data through post method as compare to get method.
|
| enctype |
This Attribute identifies the media type. The media type is used for encoding the name/value pairs of the form's data. |
| name |
Through name attribute you can identify the form in your HTML file. Multiple form in an HTML file can be possible so in this condition you can easily identify forms through their names.
name="formname"
|
| id |
Through id attribute you can identify the form in your HTML file. Multiple form in an HTML file can be possible so in this condition you can easily identify forms through their ids.
id="formid"
|
Example of form
<form action="test.php" method="post" name="myform">
Enter your first name:
<input type="text" name=" txtFirstName" id=" txtFirstName" />
Enter your last name:
<input type="text" name="txtLastName" id=" txtLastName" />
<input type="submit" name="save" id="save" value="Save">
</form>
Output
Enter your first name:
Enter your last name:
FAQ
1. Can I create an HTML form without using the action attribute?
Yes, the action attribute is optional. If it is omitted, the browser submits the form to the URL of the current page by default.
2. Can I create multiple forms on a single HTML page?
Yes, you can create multiple forms on one webpage. For example, a page can contain separate login, newsletter subscription, and contact forms. However, form elements should not be nested inside one another.
3. How can I make an HTML form submit data securely?
You should use HTTPS to protect information during transmission, validate submitted data on the server, and use appropriate authentication and security protections. Remember that the POST method alone does not make a form secure.