Building Forms
Forms are how HTML collects input from a visitor: search boxes, login screens, checkout pages.
A basic form
actionis the URL the data is sent to;methodis usuallyGET(data in the URL, for searches/filters) orPOST(data in the request body, for anything that changes data).- Every
<input>needs a matching<label>, connected byforon the label andidon the input. This isn't cosmetic, screen reader users rely on it, and it lets sighted users click the label text to focus the field.
Input types matter
Each type changes both the on-screen keyboard/widget shown (especially on mobile) and what the browser validates automatically, type="email" alone gives you free client-side validation for a well-formed address.
WARNING
Client-side form validation (like required or type="email") improves the experience, but it is never a substitute for validating input on the server. Anyone can bypass it entirely by sending a request directly.