The
<form>tag is used to create an HTML form for collecting user input.
It acts as a container for various input elements like text fields, checkboxes, radio buttons, buttons, and more.
Forms are essential for user interaction — for example, submitting login details or feedback.
Syntax
<form action="submit.php" method="post" target="_blank" enctype="multipart/form-data" autocomplete="on">
<!-- form elements go here -->
</form>Attributes
| Attribute | Description |
|---|---|
| action | Specifies where to send the form data when submitted. |
| method | Defines how the form data is sent — either GET or POST. |
| target | Specifies where to display the response after submitting (_blank, _self, etc.). |
| enctype | Specifies how the form data should be encoded when submitted. |
| autocomplete | Enables or disables autocomplete feature. |
| novalidate | Disables HTML5 form validation. |
| name | Assigns a name to the form. |
| rel | Specifies the relationship between the current document and the linked resource. |
Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Form Example</title>
</head>
<body>
<h2>Registration Form</h2>
<form action="/samples/form_processor.php" method="post" enctype="multipart/form-data">
<label for="name">Full Name:</label><br>
<input type="text" id="name" name="fullname" placeholder="Enter your name" required><br><br>
<label for="email">Email:</label><br>
<input type="email" id="email" name="email" required><br><br>
<label for="file">Upload Photo:</label><br>
<input type="file" id="file" name="photo"><br><br>
<input type="submit" value="Register">
</form>
</body>
</html>Output
Browser Output
You’ll see a registration form with input fields for name, email, and photo upload.
Once filled, clicking Register will open a new tab (because of target="_blank") showing the submission result.
Use our TryIt Editor to test this behavior interactively.
Browser Support
Chrome | Firefox | Edge | Safari | Opera | IE9+ |
|---|---|---|---|---|---|
| ✅Yes | ✅Yes | ✅Yes | ✅Yes | ✅Yes | ✅Yes |
The <form> element itself doesn’t produce any visible output until form controls are added inside it.
Notes
- The
<form>tag itself does not produce visible output — the contained elements do. - Always validate user input for security.
- Use HTTPS when submitting sensitive data.
Conclusion
The <form> tag is the foundation of web interactivity, allowing users to submit data efficiently and securely.
It’s one of the most essential building blocks for any web application.