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

Try it yourself
Result
typeBehaviour
textDefault single-line text
emailValidates email format; phones show an @ key
passwordHides characters; password managers recognise it
telPhone keypad on mobile (no format validation — phone formats vary)
urlValidates a URL; keyboard with "/" and ".com"
searchSearch field, often with a clear button

Numbers and ranges

Try it yourself
Result

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

Try it yourself
Result

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

Try it yourself
Result

Colour, file and hidden

Try it yourself
Result
  • color opens a colour picker and submits a hex value.
  • file lets users choose files. accept filters the file picker, multiple allows several, and capture can open the camera on phones. The form needs method="post" and enctype="multipart/form-data" to upload files.
  • hidden sends 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 addresstype="email"
A quantity or amounttype="number"
A credit card, postcode or one-time codetype="text" + inputmode="numeric" + autocomplete
A birthday or booking datetype="date"
One choice from 2–5 optionsRadio buttons
One choice from many options<select> (lesson 30)
Yes/no or several independent optionsCheckboxes

Try it yourself

Try it yourself
Result