In HTML, form attributes are used to control the behavior of the <form> tag and define how data is sent, processed, and displayed.
They provide extra information to browsers such as where the data should go, which method should be used, and how the form behaves when submitted.
Example
<form action="submit_form.php" method="post" target="_blank" autocomplete="on" enctype="multipart/form-data">
<label for="name">Name:</label>
<input type="text" id="name" name="username" required>
<input type="submit" value="Submit Form">
</form>
Commonly Used Form Attributes
1. action Attribute
The action attribute defines the destination URL where form data is sent after submission.
<form action="submit_data.php">
If omitted, data is sent to the same page.
Example: <form action=”process.php” method=”post”>
2. method Attribute
Defines how form data is sent to the server.
| Method | Description | When to Use |
|---|---|---|
| GET | Sends data via URL query string. | For search, filters, or non-sensitive data. |
| POST | Sends data in the request body. | For login, file uploads, and secure submissions. |
Example: <form action=”login.php” method=”post”>
3. target Attribute
Specifies where to display the response after form submission.
| Value | Description |
|---|---|
| _self | Default. Opens the response in the same browser tab or window where the form was submitted. |
| _blank | Opens the response in a new tab or window. Useful when you want users to stay on the current page. |
| _parent | Opens the response in the parent frame, if the page is inside an iframe. |
| _top | Opens the response in the full body of the current window, breaking out of all frames. |
Example: <form action=”thanks.html” target=”_blank”>
4. autocomplete Attribute
Controls whether the browser should automatically fill previously entered form data.
| Value | Description |
|---|---|
| on | Enables autofill (default). |
| off | Disables autofill. |
Example: <form autocomplete=”off”>
Useful for login and secure forms where autofill could expose sensitive data.
5. enctype Attribute
Defines how form data should be encoded before sending to the server.
Used only when method="post".
| Value | Description |
|---|---|
| application/x-www-form-urlencoded | Default. Encodes form data as key-value pairs (e.g., name=Dharmesh&email=test@example.com). |
| multipart/form-data | Used when the form includes file uploads. It sends each form field as a separate part of the message. |
| text/plain | Sends data as plain text (no encoding). Rarely used, mainly for debugging. |
Example (for file upload): <form action=”upload.php” method=”post” enctype=”multipart/form-data”>
6. name Attribute
Assigns a unique name to the form for identification.
Example: <form name=”contactForm”>
Useful in JavaScript for form validation and submission control.
7. novalidate Attribute
Disables browser’s automatic form validation. Developers can use JavaScript for custom validation instead.
Example: <form action=”data.php” novalidate>
8. accept-charset Attribute
Specifies the character encoding for the form submission.
Example: <form accept-charset=”UTF-8″>
This ensures multilingual compatibility essential for global websites.
9. rel Attribute (HTML5)
Specifies the relationship between the form and an external resource (commonly used with action URLs).
Example: <form action=”register.php” rel=”noopener”>
10. onsubmit & onreset Attributes
Used with JavaScript to run functions during form submission or reset.
Example: <form onsubmit=”return validateForm()” onreset=”alert(‘Form Cleared!’)”>
Full HTML Form with All Attributes
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Deep tutorial on HTML form attributes, including action, method, enctype, and target with practical examples and AdSense-safe SEO optimization.">
<meta name="keywords" content="HTML form attributes, HTML forms, action method, enctype, autocomplete, target, novalidate, HTML tutorial">
<meta name="author" content="Dharmesh Kundariya">
<title>HTML Form Attributes Example</title>
</head>
<body>
<h1>HTML Form Attributes Example</h1>
<form action="submit_form.php" method="post" target="_blank" enctype="multipart/form-data" autocomplete="on" accept-charset="UTF-8" name="contactForm" onsubmit="return confirm('Are you sure you want to submit?')"> <label for="fullname">Full Name:</label><br> <input type="text" id="fullname" name="fullname" required><br><br> <label for="email">Email:</label><br> <input type="email" id="email" name="email" required><br><br> <label for="file">Upload Resume:</label><br> <input type="file" id="file" name="resume"><br><br> <input type="submit" value="Submit Form"> <input type="reset" value="Clear Form"> </form>
</body>
</html>