An introduction to use HTML form elements to collect information from users.
Go fullscreen: ⌃⌥F
Forms
Forms
Collecting user information
HTML by itself cannot do anything with the data
Most often a server is needed to process the information—and a server language: PHP, Ruby, Python, JavaScript, etc.
But JavaScript can do quite a bit of processing in the browser
Do not use forms unless absolutely necessary
Forms are a usability hurdle—especially on mobile
Contact forms are stupid—they do nothing more than what a simple email address does
Use forms only if collecting very specific information
HTML
<formmethod="POST"action="…"><!-- Surrounds every form element --><labelfor="…"><!-- The text label for a control — ALWAYS REQUIRED --><inputtype="…"id="…"><!-- An input control, lots of different types --><selectid="…"><!-- A dropdown menu box --><option><!-- An entry inside the <select> --><textareaid="…"><!-- A large, multi-line text field --><buttontype="submit"><!-- Submission button — sends data, does not link to other pages --><fieldset><!-- To group fields together, like address fields --><legend><!-- A label for the group of fields -->
HTML
<inputtype="text"id="…"><!-- Generic text; `type="text"` is optional --><inputtype="number"id="…"><!-- A number, integer or float --><inputtype="url"id="…"><!-- A valid URL --><inputtype="color"id="…"><!-- A colour; often presents a colour picker --><inputtype="date"id="…"><!-- A date; often presents a calendar --><inputtype="time"id="…"><!-- A time; often presents a time picker --><inputtype="email"id="…"><!-- A valid email address --><inputtype="password"id="…"><!-- The typed characters are hidden by bullets --><inputtype="tel"id="…"><!-- For collecting a telephone number --><inputtype="checkbox"id="…"><!-- The checkmark input --><inputtype="radio"id="…"><!-- Those circular inputs where you can only select one --><inputtype="range"id="…"><!-- A number slider -->