HTML forms have several attributes that control how they behave. These attributes tell the browser where to send the data, how to send it, and where to show the response.
The Action Attribute
The action attribute defines where the form data should be sent when the user clicks submit. Usually, this is a file on the server that processes the data.
If you omit the action attribute, the form data is sent to the current page itself.
action="#" which sends the data to the same page (nothing will happen, but the form structure works).
The Target Attribute
The target attribute specifies where to display the response after submitting the form. By default (_self), the response opens in the same tab.
| Target Value | Description |
|---|---|
_blank
| Opens the response in a new tab or window |
_self
| Opens the response in the same tab (default) |
_parent
| Opens the response in the parent frame |
_top
| Opens the response in the full body of the window |
The Method Attribute
The method attribute tells the browser how to send the form data. There are two main methods: GET and POST.
GET Method
With GET, the form data is appended to the URL. You can see it in the address bar. This is good for search forms or when you want users to bookmark the results.
POST Method
With POST, the form data is sent in the background (in the HTTP request body). It does not appear in the URL. This is safer and has no size limits.
GET vs POST: When to Use Which
| GET | POST | |
|---|---|---|
| Data visibility | Visible in URL | Not visible in URL (in request body) |
| Security | Not secure (do not use for passwords) | More secure for sensitive data |
| Size limit | Limited (2048 characters max) | No size limit (can send large files) |
| Bookmarkable | Yes, users can bookmark the result | No, cannot bookmark POST requests |
| Best for | Search forms, filters, queries | Login forms, registrations, file uploads |
The Autocomplete Attribute
The autocomplete attribute tells the browser whether to remember and suggest previously entered values. This is helpful for forms that users fill out repeatedly.
You can also turn autocomplete off for the entire form or for specific fields:
<form action="/action_page.php" method="post" autocomplete="off">
The Novalidate Attribute
The novalidate attribute tells the browser NOT to validate the form data before submitting. This means the browser will not check if required fields are filled or if emails are correctly formatted.
This can be useful when you want to use your own custom validation with JavaScript.
Complete Form Attributes Example
Here is a complete form using multiple attributes together:
Quick Summary
action– Where to send the form data (usually a server-side script)target– Where to display the response (_selfor_blank)method– How to send data (getorpost)autocomplete– Whether browser should suggest previous valuesnovalidate– Turn off browser validation- Use
POSTfor sensitive data andGETfor search forms - Always validate data on the server, even if you use novalidate
What Just Happened? Let Me Explain
- The
actionattribute points to a backend script (like/action_page.php). That script receives the data and processes it (saves to database, sends email, etc.). - Using
target="_blank"is nice when you want users to keep the original form open while seeing the result in a new tab. - GET puts data in the URL. You can see it. POST hides it. That is why POST is for passwords.
- Autocomplete saves users time by remembering what they typed before. Turn it off only for very sensitive fields.
- The novalidate attribute is useful when you want to build your own validation with JavaScript. But always validate on the server too.
method="post" for login, registration, and contact forms. Use method="get" for search boxes and filters where users might share or bookmark the URL.
HTML Form Attributes Reference
Here are all the form attributes we covered in this chapter:
| Attribute | Description |
|---|---|
action
| Specifies where to send the form data |
target
| Specifies where to display the response |
method
| Specifies HTTP method (get or post) |
autocomplete
| Whether form should have autocomplete on/off |
novalidate
| Turns off browser validation when present |