HTML reference
form
The <form> element groups controls that collect user input and submits their values to a server or another handler.
What you will learn
- How a form sends submitted values
- What
actionandmethoddo - How to label fields and choose their
name
Basic example
<form action="/search" method="get">
<label for="query">Search</label>
<input id="query" name="q" type="search">
<button type="submit">Search</button>
</form>Important attributes
action- The URL that receives the submitted data.
method- Usually
getfor retrieval and bookmarkable searches, orpostfor data that should be sent in the request body. name- The key used to identify a control's value when the form is submitted.
Accessibility and safety
- Give every form control a visible, associated
label. - Use the correct input type and validation, but validate again on the server.
- Use HTTPS and protect state-changing forms against unauthorized requests.
- Do not put passwords or secrets in a GET URL.