Skip to content
techsnow

HTML Forms

Form Tag

Forms collect information from users: sign-ups, logins, searches, contact messages and payments. The <form> element wraps all the inputs and sends their data when submitted.

Syntax:

<form action="/signup" method="post">
  <!-- inputs and buttons go here -->
</form>
AttributePurpose
actionThe URL the data is sent to (usually a server script or API).
method="get"Sends data in the URL, e.g. /search?q=html. Good for searches.
method="post"Sends data hidden in the request body. Use it for passwords and personal data.
autocompleteon or off: whether the browser can autofill the form.

A complete simple form

<form action="/search" method="get">
  <label for="q">Search tutorials</label>
  <input id="q" name="q" type="search" placeholder="e.g. flexbox">
  <button type="submit">Search</button>
</form>

Every input that should be sent needs a name. When submitted, this form goes to /search?q=flexbox.