The <form> tag

The <form> tag groups input elements (input, select, textarea, etc.) into a single form for submitting data.

Syntax

<form action="/submit" method="post">...</form>

Attributes

action The URL the form data is submitted to.
method "get" (data in the URL) or "post" (data in the request body).
enctype The data encoding format; file uploads require multipart/form-data.
novalidate Disables the browser's built-in HTML5 field validation before submission.

Example

<form action="/subscribe" method="post">
  <label for="name">Name</label>
  <input type="text" id="name" name="name" autocomplete="name" required>

  <label for="email">Email</label>
  <input type="email" id="email" name="email" autocomplete="email" required>

  <button type="submit">Subscribe</button>
</form>

Notes

  • A button inside a form without an explicit type="button" defaults to type="submit" and submits the form.
  • File inputs (input type="file") require the form to have enctype="multipart/form-data".
  • HTML on its own does not email the data: action points to a handler on a server (a PHP or Node.js script, or a form service) that receives the data and sends the email. action="mailto:..." only opens the visitor's mail app and is unreliable.
  • method="get" puts the data into the URL — it shows up in the address bar and browser history — so use method="post" for passwords and personal data.

Accessibility

  • Every input should have an associated label (via for/id, or by wrapping it).

Related tools