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="name">Name</label>
<input type="text" id="name" name="name" autocomplete="name" required>
<label for="email">Email</label>
<input type="email" id="email" name="email" autocomplete="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".
- HTML on its own does not email the data: action points to a handler on a server (a PHP or Node.js script, or a form service) that receives the data and sends the email. action="mailto:..." only opens the visitor's mail app and is unreliable.
- method="get" puts the data into the URL — it shows up in the address bar and browser history — so use method="post" for passwords and personal data.
Accessibility
- Every input should have an associated label (via for/id, or by wrapping it).
Related tools
HTML Form Generator
Add text, email, phone, password, select, checkbox or radio fields and get ready HTML form code with proper labels and built-in validation.
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.
Build a contact form
Practice exercise: build a contact form with name, email, and message fields.
Build a registration form with built-in validation
Practice exercise: build a course sign-up form with fieldset, input types, required, pattern and minlength — validation without JavaScript.
Forms
form, input, label, button — the basic building blocks of a data-entry form.
Build a login form
Practice exercise: fix a broken sign-in form — email and password with autocomplete for password managers, remember me and a forgot-password link.