The <form> tag
The <form> tag groups input elements (input, select, textarea, etc.) into a single form for submitting data.
Syntax
<form action="/submit" method="post">...</form> Attributes
| action | The URL the form data is submitted to. |
| method | "get" (data in the URL) or "post" (data in the request body). |
| enctype | The data encoding format; file uploads require multipart/form-data. |
| novalidate | Disables the browser's built-in HTML5 field validation before submission. |
Example
<form action="/subscribe" method="post">
<label for="email">Email</label>
<input type="email" id="email" name="email" required>
<button type="submit">Subscribe</button>
</form>
Notes
- A button inside a form without an explicit type="button" defaults to type="submit" and submits the form.
- File inputs (input type="file") require the form to have enctype="multipart/form-data".
Accessibility
- Every input should have an associated label (via for/id, or by wrapping it).
Related tools
The <label> tag
The for attribute of <label>, linking a caption to an input.
The <select> tag
The multiple, size, and required attributes of <select> with option children.
The <textarea> tag
The rows, cols, and maxlength attributes of <textarea> for multi-line text.
The <input> tag
Types and attributes of the <input> tag: type, name, value, required, pattern.
The <button> tag
The type attribute of the <button> tag: submit, button, reset — the difference, with examples.