- Home
- /
- Tutorials
- /
- HTML Tutorial
- /
- HTML <form> Tag
HTML Tags
HTML <form> Tag
The form tag wraps a set of fields and sends them somewhere when the user presses Submit. Its attributes decide where (action), how (method) and in what format (enctype). Most form bugs are a missing one of these three.
This is the tag reference. Every attribute is explained with its own example in HTML Form Attributes, and how forms work as a whole in HTML form basics.
Syntax
html
<form action="/samples/form_processor.php" method="post" target="_blank" enctype="multipart/form-data" autocomplete="on">
<!-- form elements go here -->
</form>| Attribute | What it does |
|---|---|
| action | The address that receives the data. If missing, the form sends to the current page. |
| method | get adds the data to the address; post sends it hidden. The default is get. |
| enctype | How the data is packed. File uploads need multipart/form-data. |
| target | Where the response opens, like _blank for a new tab. |
| autocomplete | Turns the browser's saved suggestions on or off. |
| novalidate | Switches off the browser's built-in checks. |
| name | A name, so scripts can find the form. |
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>The registration form has fields for a name, an email and a photo. Because there is a file field, the form uses method="post" and enctype="multipart/form-data"; with the default encoding, the server would receive only the file name.
Browser Support
Chrome | Edge | Firefox | Safari | Opera | IE9+ |
|---|---|---|---|---|---|
| Yes | Yes | Yes | Yes | Yes | Yes |
Good to know
HTML <form> Tag exercises
Add a form
Make a form that sends to /subscribe. It has an email field named email and a button that sends it, with the text Join.
Result
Check your answer to see it here.
