An HTML form collects user input with fields such as text boxes, checkboxes and buttons, then sends the values to a server when the user submits it. Modern HTML5 gives you built-in field types, labels and validation, so a form can be accessible and checked before any JavaScript runs.
This tutorial builds a complete sign-up form and explains the pieces you need for real pages.
The action is the URL that receives the data and method is get or post. Use post for anything that changes data or contains sensitive values.
Every control needs a visible <label> linked by for and id, or wrapped around the input. Labels give screen reader users a name and enlarge the click target. Do not use placeholder as a replacement for a label.
| Type | Use |
|---|---|
text | Free text |
email | Email address with format check and mobile keyboard |
password | Hidden text |
number | Numeric value with min, max, step |
date | Date picker |
checkbox / radio | Yes or no, or one of several |
file | File upload (needs enctype="multipart/form-data") |
Group radio buttons with the same name and wrap related fields in <fieldset> with a <legend>.
Attributes such as required, minlength, maxlength, pattern, min and max trigger browser validation on submit. Style states with CSS:
:user-invalid applies only after the user has interacted with the field, which avoids showing errors on a fresh form. Client-side validation is a convenience only. Always validate and sanitise again on the server.
FormData reads every named control. Fields without a name attribute are not submitted.
get puts values in the URL and suits searches. post sends them in the request body and suits sign-ups, logins and changes.
The input has no name attribute, or it is disabled. Only named, enabled controls are submitted.
No. Users can bypass browser checks, so the server must validate every request.
Use real labels, group related fields, keep the tab order logical and show clear error messages linked to their fields.
Build forms with labelled inputs, the right type, built-in validation attributes and a clear submit button. Use post for changes, give every field a name and repeat all validation on the server.