<form>
A form: collects data from its fields and sends it to the server.
Syntax
<form action="url" method="post">…</form>Attributes
| Parameter | Type | Description |
|---|---|---|
| action | URL | Where to send the data. Without it — to the current page address. |
| method | get | post | How to send. `get` adds the data to the address, `post` sends it in the request body. |
| novalidate | — | Optional. Turn off built-in field validation. |
Examples
A subscription form:
<form action="/subscribe" method="post">
<label>Email <input type="email" name="email" required></label>
<button>Subscribe</button>
</form>A search with get — the data ends up in an address like /search?q=latte:
<form action="/search" method="get">
<input type="search" name="q" placeholder="Search drinks">
<button>Find</button>
</form>Notes
Only fields with a name attribute are sent to the server. Send passwords and personal data with post; get suits search and filters — such an address can be bookmarked. Forms cannot be nested.
See also
- <input> — An input field; its kind is set by the `type` attribute.
- <button> — A button: submits a form or triggers an action.
- <label> — A label for a form field.
- <fieldset>, <legend> — A group of related form fields with a `<legend>` title.
Related recipes
In the tutorial
- Forms — How a form works in HTML — the form tag, the input field, the name attribute, the submit button, action and the GET and POST methods.