HTML
<form>elements contain several attributes that define how form data is collected, processed, and submitted. These attributes control important aspects such as where and how the data is sent, how it is encoded, and how the form behaves during submission.
The action Attribute
Specifies the URL or file that will handle the form submission.
When the user clicks the submit button, the form data is sent to this location.
<form action="submit_form.php">
<input type="text" name="username">
<input type="submit">
</form>If the action attribute is omitted, the form submits to the same page it’s currently on.
The method Attribute
Defines the HTTP method used to send form data.
There are two common methods:
- GET – Data is appended to the URL (visible in the address bar).
- POST – Data is sent in the request body (not visible in the URL).
<form action="submit_form.php" method="post">
<input type="text" name="email">
<input type="submit" value="Submit">
</form>The target Attribute
Specifies where to display the response after submitting the form.
| Value | Description |
|---|---|
_self | Default. Submits in the same tab. |
_blank | Opens in a new tab or window. |
_parent | Loads in the parent frame. |
_top | Loads in the full body of the window. |
<form action="submit_form.php" target="_blank">
<input type="text" name="query">
<input type="submit" value="Search">
</form>The enctype Attribute
Specifies how the form data should be encoded before sending it to the server.
It is mainly used with the POST method.
| Value | Description |
|---|---|
application/x-www-form-urlencoded | Default. All characters are encoded. |
multipart/form-data | Used for forms that include file uploads. |
text/plain | Sends data without encoding (rarely used). |
<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="fileUpload">
<input type="submit" value="Upload">
</form>The autocomplete Attribute
Enables or disables autocomplete for all input fields inside a form.
<form autocomplete="off">
<input type="text" name="name" placeholder="Full name">
<input type="email" name="email" placeholder="Email address">
<input type="submit">
</form>You can also set autocomplete on individual input fields.
The novalidate Attribute
Disables form validation when submitting.
This is useful during testing or when validation is handled via JavaScript.
<form action="submit_form.php" novalidate>
<input type="email" name="email" placeholder="Enter your email">
<input type="submit">
</form>The name Attribute
Assigns a name to the form.
This is often used to reference the form in JavaScript.
<form name="registrationForm">
<input type="text" name="username">
<input type="submit">
</form>The rel Attribute
Defines the relationship between the current document and the target resource when the action points to another URL.
<form action="https://example.com/submit" rel="external">
<input type="text" name="data">
<input type="submit">
</form>The accept-charset Attribute
Specifies the character encodings the server should expect for submitted form data.
<form action="submit_form.php" accept-charset="UTF-8">
<input type="text" name="comment">
<input type="submit">
</form>Example: Various Form Attributes
<form action="register.php" method="post" target="_self"
enctype="multipart/form-data" autocomplete="on" name="userForm">
<label>Full Name:</label>
<input type="text" name="fullname" required><br><br>
<label>Email:</label>
<input type="email" name="email" required><br><br>
<label>Profile Picture:</label>
<input type="file" name="profile_pic"><br><br>
<label>Message:</label><br>
<textarea name="message" rows="4" cols="30"></textarea><br><br>
<input type="submit" value="Submit Form">
</form>Conclusion
HTML form attributes define how form data is sent and processed.
By understanding and combining attributes like action, method, enctype, and target, developers can control form behavior precisely and build robust user input systems.