HTML · Forms

Input Types

Choosing the right input type is free help: mobile phones show the right keyboard, browsers validate the value, and some types give you a date picker or colour picker for free.

Intermediate 5 min Lesson 11 of 22 Runnable examplesFollows the WHATWG HTML Living Standard.
Before you start:Forms
0/22 in HTML
On this page · 5 min · Intermediate

Learning objectives#

  • Pick the correct input type for each kind of data
  • Use number, range and date inputs with min, max and step
  • Accept files with type="file"
  • Know when to use type="hidden"

Explanation#

type="email", "url" and "tel" show a matching keyboard on phones (an @ key, a .com key, a number pad). email and url are also validated automatically.

type="number" and "range" accept numbers; min, max and step set the limits. range shows a slider.

type="date", "time" and "datetime-local" give a built-in picker and send a standard format like 2026-10-28.

type="file" lets users choose files; add accept="image/*" to filter and multiple to allow several. The form needs enctype="multipart/form-data" to upload them.

type="hidden" sends a value the user does not see, such as a product ID. Never trust it — users can still change it with DevTools.

Code example: An input-type showcase#

HTMLAn input-type showcase Runnable
<style> label { display:block; margin:8px 0; font-family:sans-serif; } </style>
<form>
  <label>Email <input type="email" name="email"></label>
  <label>Phone <input type="tel" name="phone" placeholder="98765 43210"></label>
  <label>Website <input type="url" name="site"></label>
  <label>Quantity <input type="number" name="qty" min="1" max="10" value="1"></label>
  <label>Volume <input type="range" name="vol" min="0" max="100" step="10"></label>
  <label>Birthday <input type="date" name="dob"></label>
  <label>Favourite colour <input type="color" name="color" value="#2965f1"></label>
  <label>Photo <input type="file" name="photo" accept="image/*"></label>
  <label>Search <input type="search" name="q"></label>
  <input type="hidden" name="source" value="newsletter">
  <button>Submit</button>
</form>
Expected output
A form with an email box, phone box, URL box, a number spinner, a slider, a date picker, a colour picker, a file chooser and a search box.
Opens this example in the full playground

Step-by-step explanation#

  1. type="email" rejects text without an @ on submit.
  2. type="tel" shows a number keypad on phones but does not validate (phone formats vary worldwide).
  3. number with min/max/value starts at 1 and refuses 0 or 11.
  4. range shows a slider moving in steps of 10.
  5. date and color open native pickers.
  6. file with accept="image/*" filters the file chooser to images.
  7. hidden sends source=newsletter without showing anything.

Real-world use case#

A flight booking form uses date for travel dates, number for passengers, tel for the contact number and email for the ticket — giving mobile users the right keyboard for each.

Common mistakes#

type="number" for phone numbers or PINs

number removes leading zeros and shows spinner arrows. Use type="tel" for phones, or inputmode="numeric" for PINs and OTPs.

File upload without enctype

Without enctype="multipart/form-data" and method="post", only the file name is sent, not the file.

Trusting hidden fields

A hidden price field can be edited in DevTools. Always look up prices and permissions on the server.

Best practices#

  • Use the most specific input type available
  • Add autocomplete values (email, tel, postal-code)
  • Use inputmode for numeric text that is not a quantity
  • Always set min/max for number and date inputs where limits exist

Remember this#

Right type = right keyboard on mobile.

Can you do maths with it? number. Otherwise (phone, PIN, zip) → text/tel.

Hidden ≠ secret. Users can see and change it.

Practice exercise#

Your task: Build a hotel booking form with check-in and check-out dates, number of guests (1–6) and an email address.

Need a hint?
Two date inputs, one number input with min and max, one email input.
Show solution
HTML Runnable
<form>
  <label>Check-in <input type="date" name="checkin" required></label>
  <label>Check-out <input type="date" name="checkout" required></label>
  <label>Guests <input type="number" name="guests" min="1" max="6" value="2"></label>
  <label>Email <input type="email" name="email" autocomplete="email" required></label>
  <button>Book</button>
</form>
Opens this example in the full playground

Mini quiz#

Input Types quizMultiple choice Question 1 of 3

Which type is best for a mobile phone number?

Score so far: 0/0

Want more? Practise all HTML MCQs · HTML interview questions

My notes#

Saved in this browser.

Progress is saved in this browser. Sign in to sync.