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 action and method do
  • 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 get for retrieval and bookmarkable searches, or post for 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

Related pages