Free HTML tutorial

HTML Forms and Input Basics

HTML forms collect information and submit it for processing. Use labels, appropriate input types and clear instructions so people can complete forms reliably.

Create a form

<form action="/submit" method="post">
  <fieldset>
    <legend>Contact details</legend>
    <label for="email">Email address</label>
    <input id="email" name="email" type="email" autocomplete="email" required>
  </fieldset>
  <button type="submit">Send</button>
</form>

The action identifies where the form submits. The method determines how the browser sends the form data. A fieldset and legend group related controls. The server must be configured to receive and process submissions; validate data on the server even when the browser provides client-side validation.

Form attributes

Common form attributes include action, method, autocomplete and novalidate. Select attributes based on the behavior your form needs.

Input types

Choose a type that matches the information, such as text, email, password, number, date or checkbox. The browser can provide useful controls and basic validation for some types.

Input attributes

Attributes such as name, required, placeholder, min, max and maxlength configure inputs. A placeholder is a hint, not a replacement for a visible label.

Input form attributes

An input can use the form attribute to associate it with a form elsewhere in the same document by ID. Use this when the visual layout places controls outside the form element.