Lesson 36 of 51 · Module 6, lesson 2 of 6 · 3 min

Choosing input types

Pick the right input type so that phones show the right keyboard and the browser can check the answer.

What you'll learn

  • The most useful <input> types
  • How the right type helps phone users and screen readers
  • Checkboxes, and the password field

Why this matters

The type attribute changes how a field behaves. On a phone, type="email" shows a keyboard with @, and type="tel" shows a number pad. Screen readers announce the type. And some types check the input for you. Choosing the right type costs nothing and helps everyone.

The types you will use most

TypeForWhat changes
textShort text: a name, a cityNothing special — the default
emailAn email addressPhone keyboard with @; the browser checks the format
telA phone numberNumber pad on phones (no format check, because formats differ by country)
urlA web addressKeyboard with / and .com; checks it starts like an address
numberA quantityNumber keyboard; arrows to go up and down
passwordA passwordCharacters hidden as dots
dateA dateA date picker
searchA search boxOften a small × to clear it
checkboxYes or noA box to tick

A form with several types

html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Cooking class</title>
</head>
<body>
  <h1>Book a cooking class</h1>
  <form>
    <p>
      <label for="email">Email</label>
      <input id="email" name="email" type="email">
    </p>
    <p>
      <label for="phone">Phone (with country code)</label>
      <input id="phone" name="phone" type="tel">
    </p>
    <p>
      <label for="people">Number of people</label>
      <input id="people" name="people" type="number" min="1" max="6" value="1">
    </p>
    <p>
      <label for="day">Preferred day</label>
      <input id="day" name="day" type="date">
    </p>
    <p>
      <input id="vegetarian" name="vegetarian" type="checkbox" value="yes">
      <label for="vegetarian">I would like vegetarian dishes</label>
    </p>
    <p>
      <button type="submit">Book</button>
    </p>
  </form>
</body>
</html>

What you'll see: an email box, a phone box, a number box with small arrows, a date box with a calendar icon, a checkbox with its label after it, and a Book button.

The booking form: an Email box, a Phone box, a "Number of people" box showing 1 with small up and down arrows, a "Preferred day" date box, a checkbox labelled "I would like vegetarian dishes", and a Book button.

Notes on some types

  • number accepts min, max and step. Use it for real quantities only — not for phone numbers, card numbers or postcodes, which are text made of digits.
  • checkbox: the label usually comes after the box. If the box is ticked, the form sends vegetarian=yes (the value). If not, it sends nothing for that field.
  • password: the characters are hidden on screen. That is all — it does not make sending the password safe. (See Where form data goes.)
  • date: the picker looks different in every browser, and the value is always sent as YYYY-MM-DD, such as 2026-10-05.

Try it yourself

  1. Select the example and choose Try it.
  2. Type ana (with no @) into the email box and press Book. The browser stops you.
  3. Tick the checkbox, submit, and look for vegetarian=yes in the message. Untick it and submit again.
  4. Open your own copy on a phone, if you can, and tap each box to see the different keyboards.

Common mistakes

  • type="text" for everything. Phone users get the wrong keyboard. Fix: pick the matching type.
  • type="number" for a phone number. Leading zeros and + can be lost. Fix: type="tel".
  • A checkbox without a label, or with plain text next to it. The small box is hard to hit and unnamed for screen readers. Fix: a <label for> connected to it.

Check yourself

  1. Which type shows a keyboard with @ on phones?
  2. Which type should a phone number use?
  3. What does an unticked checkbox send?

Answers

  1. email.
  2. tel.
  3. Nothing.

Next: some answers are a choice from a list, or a long message. The next lesson covers dropdowns, text areas and groups of options.

Chat with us on WhatsApp