forms
<form>
Container for a set of input controls that are submitted together to a server. Use it any time users need to send data — search, sign-up, checkout, comments.
<form action="/submit" method="post">...</form> Common attributes
| Attribute | Purpose |
|---|---|
| action | URL that receives the submission |
| method | get | post |
| enctype | application/x-www-form-urlencoded | multipart/form-data | text/plain |
| target | Where the response opens (_self, _blank) |
| autocomplete | on | off for the whole form |
| novalidate | Skip built-in HTML validation |
Examples
<form action="/search" method="get"><input name="q"><button>Go</button></form> Search form via query string
<form action="/upload" method="post" enctype="multipart/form-data"><input type="file" name="f"><button>Upload</button></form> File upload requires multipart enctype
<form method="post" novalidate>...</form> Disable native validation to run your own
Gotcha
File uploads require enctype="multipart/form-data" — plain forms will only send the filename. Always include a real submit control so keyboard users can submit with Enter.
Related tags
<input>
The single most versatile form control — its behavior is driven by the type attribute (text, email, password, number, checkbox, radio, file, date, range, color, hidden, and more). Use it for every scalar user input; use <textarea> only for multi-line text.
<button>
Interactive control that triggers an action — submitting a form, opening a dialog, or running JavaScript. Use it for anything that does something; use <a href> for anything that navigates.
<label>
Associates a caption with a form control so clicking the label focuses the input and screen readers announce it. Use one for every input, select, and textarea.
<select>
Drop-down (or list-box) that lets the user pick one or more predefined options. Use it when the option set is short and known; for many options, an autocomplete input is friendlier.
<textarea>
Multi-line plain-text input control. Use it for comments, messages, code snippets, or any free-form text that may span more than one line.