Input Types
The <input> element changes completely depending on its type. The right type gives users a suitable control — a date picker, a colour picker, a numeric keypad on phones — and gives you free validation. This lesson tours all of them.
Text-like inputs
| type | Behaviour |
|---|---|
text | Default single-line text |
email | Validates email format; phones show an @ key |
password | Hides characters; password managers recognise it |
tel | Phone keypad on mobile (no format validation — phone formats vary) |
url | Validates a URL; keyboard with "/" and ".com" |
search | Search field, often with a clear button |
Numbers and ranges
number shows a numeric field with spin buttons and validates min, max and step. range shows a slider — fine when the exact value doesn't matter much. For things like card numbers or postcodes that are digits but not quantities, use type="text" with inputmode="numeric" instead (lesson 28).
Dates and times
Browsers show a native picker, and the submitted value is always in a standard format (2026-10-06, 14:30) regardless of how it's displayed to the user. step="900" on the time input means 15-minute increments.
Choices: checkboxes and radio buttons
Colour, file and hidden
coloropens a colour picker and submits a hex value.filelets users choose files.acceptfilters the file picker,multipleallows several, andcapturecan open the camera on phones. The form needsmethod="post"andenctype="multipart/form-data"to upload files.hiddensends a value the user doesn't see — like a tracking source or an ID. Users can still inspect and change it, so never trust it for security.
Buttons as inputs
type="submit", type="reset", type="button" and type="image" create buttons. The <button> element is more flexible — it can contain HTML like icons — and is generally preferred (lesson 31).
Unsupported types fall back to text
If a browser doesn't recognise a type, it shows a plain text field. That makes the specialised types safe to use: older browsers still work, just without the extras.
Choosing the right type
| You want… | Use |
|---|---|
| An email address | type="email" |
| A quantity or amount | type="number" |
| A credit card, postcode or one-time code | type="text" + inputmode="numeric" + autocomplete |
| A birthday or booking date | type="date" |
| One choice from 2–5 options | Radio buttons |
| One choice from many options | <select> (lesson 30) |
| Yes/no or several independent options | Checkboxes |