Form attributes define how a form behaves when the user submits the data. These attributes are applied to the <form> tag.
<form action="submit.php" method="post">
Below are the most commonly used form attributes.
Defines the URL where the form data will be sent.
<form action="submit.php">
If omitted, the form submits to the same page.
Specifies how form data is sent.
| Method | Usage |
|---|---|
GET |
Data visible in URL |
POST |
Data sent securely inside request body |
<form action="register.php" method="post">
Defines where to open the response.
| Value | Meaning |
|---|---|
_self |
Opens in the same tab (default) |
_blank |
Opens in a new tab |
_parent |
Opens in parent frame |
_top |
Opens full window |
<form action="search.php" target="_blank">
Controls browser autofill.
<form autocomplete="off">
| Value | Meaning |
|---|---|
on |
Enable autofill |
off |
Disable autofill |
Defines how form data is encoded when sent to the server.
Required for file uploads.
| Value | Use Case |
|---|---|
application/x-www-form-urlencoded |
Default |
multipart/form-data |
File uploads |
text/plain |
Debugging text format |
<form method="post" enctype="multipart/form-data">
Disables built-in browser validation.
<form novalidate>
Gives a name to the form (useful in JavaScript).
<form name="loginForm">
<table border="1" cellpadding="8" cellspacing="0">
<tr>
<th>Attribute</th>
<th>Description</th>
</tr>
<tr>
<td><code>action</code></td>
<td>URL where the form sends data</td>
</tr>
<tr>
<td><code>method</code></td>
<td>HTTP method (<code>GET</code> or <code>POST</code>)</td>
</tr>
<tr>
<td><code>target</code></td>
<td>Where to open the response (<code>_self</code>, <code>_blank</code>)</td>
</tr>
<tr>
<td><code>autocomplete</code></td>
<td>Enables or disables autofill</td>
</tr>
<tr>
<td><code>enctype</code></td>
<td>Encoding type for form data (required for file uploads)</td>
</tr>
<tr>
<td><code>novalidate</code></td>
<td>Disables browser validation</td>
</tr>
<tr>
<td><code>name</code></td>
<td>Specifies form name</td>
</tr>
</table>
| Attribute | Description |
|---|---|
action |
URL where the form sends data |
method |
HTTP method (GET or POST) |
target |
Where to open the response (_self, _blank) |
autocomplete |
Enables or disables autofill |
enctype |
Encoding type for form data (required for file uploads) |
novalidate |
Disables browser validation |
name |
Specifies form name |