Lesson 21 of 36
HTML Tutorial

Input Types

Pick the right input type for text, email, numbers, dates, passwords and more to get free validation and better mobile keyboards.

3 min readBeginnerWeb FundamentalsHTML Forms

The <input> element is the Swiss army knife of forms. Its type attribute decides what kind of control appears. Choosing the right type gives you a suitable keyboard on phones, built-in validation and often a native picker, all without JavaScript.

html
<input type="text" name="fullname" id="fullname">

If you omit type, it defaults to text.

Common text-like types#

TypePurposeBonus
textShort free text, such as a nameDefault
emailAn email addressChecks the format; email keyboard on phones
passwordA secretHides what is typed
telA phone numberNumeric keypad on phones
urlA web addressChecks the format
searchA search queryMay show a clear button
html
<label for="email">Email</label>
<input type="email" id="email" name="email" autocomplete="email">

<label for="phone">Phone</label>
<input type="tel" id="phone" name="phone" autocomplete="tel">

<label for="password">Password</label>
<input type="password" id="password" name="password" autocomplete="new-password">

Numbers and ranges#

html
<!-- number accepts digits, with optional limits and step -->
<label for="cups">Cups of coffee</label>
<input type="number" id="cups" name="cups" min="1" max="12" step="1" value="2">

<!-- range shows a slider -->
<label for="sweet">Sweetness</label>
<input type="range" id="sweet" name="sweetness" min="0" max="10" value="5">

min, max and step limit the values the user may choose. Use type="number" for quantities, not for things like phone numbers or postal codes, which are identifiers, not amounts.

Dates and times#

html
<label for="visit">Visit date</label>
<input type="date" id="visit" name="visit_date" min="2025-01-01">

<label for="time">Arrival time</label>
<input type="time" id="time" name="arrival_time">

Other variants include datetime-local, month and week. Browsers show a native picker, and the value is always sent in a standard format such as 2025-06-30.

Other handy types#

html
<label for="colour">Favourite cup colour</label>
<input type="color" id="colour" name="colour">

<label for="pic">Upload a photo</label>
<input type="file" id="pic" name="photo" accept="image/png, image/jpeg">

<input type="hidden" name="source" value="homepage-form">

hidden sends a value without displaying a field. Remember that users can still change hidden values, so treat them as untrusted.

Helpful attributes for all inputs#

  • placeholder shows a hint inside the empty field. It disappears once typing starts and is not a replacement for a label.
  • value sets a starting value.
  • required makes a field mandatory.
  • readonly shows the value but prevents editing, while still submitting it.
  • disabled greys out the field and prevents it from being submitted.
  • autofocus focuses a field on page load. Use sparingly.
  • autocomplete helps browsers fill known values, such as name, email or tel.

Common mistakes#

  • Using type="text" for everything.
  • Using type="number" for phone numbers or card numbers.
  • Treating placeholder as the label.
  • Using type="password" without autocomplete tokens, which makes password managers less helpful.
  • Trusting hidden fields as secure.

Try it yourself#

Build a "Book a table" form with inputs for name, email, phone, date, time and number of guests (between 1 and 8). Use the most specific input type for each, with suitable autocomplete values. Open the page on your phone, or in your browser's device mode, and compare the keyboards that appear.

Recap#

The type attribute selects the control and unlocks validation and native pickers. Use email, tel, number, date and friends in preference to plain text, and remember that placeholders and hidden fields are not substitutes for labels and server-side checks.

Check your understanding

Lesson quiz

Optional

A short quiz to check what you just learned.

Questions
4
Time limit
5 min
Pass mark
70%
Best score
-