HTML Tags

HTML <form> Tag

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

html

<form action="submit.php" method="post" target="_blank" enctype="multipart/form-data" autocomplete="on">
   <!-- form elements go here -->
</form>

Attributes

AttributeDescription
actionSpecifies where to send the form data when submitted.
methodDefines how the form data is sent - either GET or POST.
targetSpecifies where to display the response after submitting (_blank, _self, etc.).
enctypeSpecifies how the form data should be encoded when submitted.
autocompleteEnables or disables autocomplete feature.
novalidateDisables HTML5 form validation.
nameAssigns a name to the form.
relSpecifies the relationship between the current document and the linked resource.

Example

html

<!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

html

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
Edge
Firefox
Safari
Opera
IE9+
YesYesYesYesYesYes

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.