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.
On this page · 5 min · Intermediate
On this page
- Learning objectives
- Explanation
- Code example
- Step by step
- Real-world use
- Common mistakes
- Best practices
- Remember this
- Practice exercise
- Mini quiz
- Related topics
- My notes
- Reading time
- 5 min
- Difficulty
- Intermediate
- Updated
- Oct 28, 2026
Related tutorials
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#
<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>
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.
Step-by-step explanation#
- type="email" rejects text without an @ on submit.
- type="tel" shows a number keypad on phones but does not validate (phone formats vary worldwide).
- number with min/max/value starts at 1 and refuses 0 or 11.
- range shows a slider moving in steps of 10.
- date and color open native pickers.
- file with accept="image/*" filters the file chooser to images.
- 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#
number removes leading zeros and shows spinner arrows. Use type="tel" for phones, or inputmode="numeric" for PINs and OTPs.
Without enctype="multipart/form-data" and method="post", only the file name is sent, not the file.
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?
Show solution
<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>
Mini quiz#
Which type is best for a mobile phone number?
Want more? Practise all HTML MCQs · HTML interview questions
My notes#
Saved in this browser.