Skip to content
Kuza Ndoto Academy

Input Types

BeginnerChapter 4 · Page 17 of 254 min readUpdated 15 Nov 2026

The <input> element is the most flexible control in HTML. Change its type attribute and it becomes a text box, a password field, a date picker, a slider, a checkbox or a file chooser. Picking the right type gives users the right keyboard on their phone, built-in checking and a better experience overall.

Text-like inputs

<label for="fullname">Full name</label>
<input type="text" id="fullname" name="fullname" autocomplete="name">

<label for="email">Email</label>
<input type="email" id="email" name="email" autocomplete="email">

<label for="pw">Password</label>
<input type="password" id="pw" name="password" autocomplete="new-password">
TypeWhat it does
textAny single line of text. The default if type is missing or unknown.
emailChecks the value looks like an email address; phones show a keyboard with @.
passwordHides the characters as dots. It does not encrypt anything; HTTPS does that.
telA phone number. Phones show a number pad. It doesn't check the format, because phone formats differ by country.
urlChecks the value is a full URL, such as https://example.com.
searchA search box; some browsers add a clear (×) button.

Useful attributes for these types include placeholder (a faint example inside the empty box), value (a starting value), maxlength and autocomplete, which tells the browser what kind of data the field holds so it can offer saved details.

Common mistake

Using placeholder instead of a label. The placeholder disappears as soon as the user types, its pale text is hard to read, and some screen readers don't announce it reliably. Always add a real <label>; a placeholder can show an example format, like 0712 345 678.

Numbers, dates and ranges

<label for="tickets">Tickets (1–6)</label>
<input type="number" id="tickets" name="tickets" min="1" max="6" step="1" value="1">

<label for="travel">Travel date</label>
<input type="date" id="travel" name="travel" min="2026-12-01">

<label for="volume">Volume</label>
<input type="range" id="volume" name="volume" min="0" max="10" value="5">
  • number shows a box with small up/down arrows. min, max and step set limits and increments; step="0.01" allows cents. Don't use it for phone numbers or ID numbers, which are not quantities. A leading zero would be lost, and the arrows make no sense.
  • date shows a calendar picker. Whatever display format the user sees, the value sent is always YYYY-MM-DD, for example 2026-12-24. Related types are time, datetime-local, month and week.
  • range shows a slider for when an exact value matters less than a rough position.
  • color opens a colour picker and sends a hex value such as #ffcc00.

Checkboxes and radio buttons

Checkboxes are for yes/no choices or picking any number of options. Radio buttons are for picking exactly one option from a group. Radios are grouped by giving them the same name.

<fieldset>
  <legend>Seat class</legend>
  <input type="radio" id="economy" name="class" value="economy" checked>
  <label for="economy">Economy</label>
  <input type="radio" id="first" name="class" value="first">
  <label for="first">First class</label>
</fieldset>

<input type="checkbox" id="news" name="newsletter" value="yes">
<label for="news">Send me the monthly newsletter</label>
  • Choosing "First class" automatically unselects "Economy" because they share name="class". The form sends class=first.
  • The checked attribute selects an option at the start.
  • An unticked checkbox sends nothing at all. A ticked one sends its value, or on if you didn't set one.
  • <fieldset> and <legend> group related choices under a shared question; see Accessible Forms.

Files, hidden values and buttons

<form action="/apply" method="post" enctype="multipart/form-data">
  <label for="cv">Upload your CV (PDF)</label>
  <input type="file" id="cv" name="cv" accept=".pdf">
  <input type="hidden" name="job_id" value="1042">
  <button type="submit">Apply</button>
</form>
  • file lets the user choose files. accept filters the file chooser and multiple allows several files. The form must use method="post" and enctype="multipart/form-data", or only the file name is sent.
  • hidden sends a value the user doesn't see, such as which job they are applying for. It's still visible in the page source, so never use it for secrets.
  • submit and reset input types also exist, but the <button> element is more flexible because it can contain any text or an icon.

Try it

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Input types</title>
  </head>
  <body>
    <h1>Bus booking</h1>
    <form>
      <p><label for="phone">Phone</label>
         <input type="tel" id="phone" name="phone" placeholder="0712 345 678"></p>
      <p><label for="date">Date</label>
         <input type="date" id="date" name="date"></p>
      <p><label for="time">Departure time</label>
         <input type="time" id="time" name="time" value="08:30"></p>
      <p><label for="seats">Seats</label>
         <input type="number" id="seats" name="seats" min="1" max="6" value="1"></p>
      <fieldset>
        <legend>Seat class</legend>
        <input type="radio" id="economy" name="class" value="economy" checked>
        <label for="economy">Economy</label>
        <input type="radio" id="vip" name="class" value="vip">
        <label for="vip">VIP</label>
      </fieldset>
      <p><input type="checkbox" id="sms" name="sms" checked>
         <label for="sms">Send my ticket by SMS</label></p>
      <p><label for="colour">Favourite colour</label>
         <input type="color" id="colour" name="colour" value="#ffcc00"></p>
      <p><label for="comfort">Comfort rating</label>
         <input type="range" id="comfort" name="comfort" min="1" max="5"></p>
    </form>
  </body>
</html>

Each control looks a little different in each browser and operating system. You'll see a text box with a faint example number, a date box with a calendar button, a time box showing 08:30, a number box with arrows that stops at 1 and 6, two radio buttons where only one can be selected, a ticked checkbox, a yellow colour swatch and a slider. Click the labels: each one focuses or toggles its control. On a phone, the phone field opens a number pad.

Key points

  • The type attribute turns <input> into many different controls; unknown types fall back to text.
  • Specific types (email, tel, number, date) give better phone keyboards and built-in checks.
  • Radio buttons in one group share a name; unticked checkboxes send nothing.
  • File uploads need method="post" and enctype="multipart/form-data"; hidden inputs are not secret.
Up next · FormsForm ValidationBuilt-in validation with required, pattern and min/max.
→

Tip: use the ← and → keys to move between pages.