TExcelTAD
Home › HTML › HTML Input Types

HTML Input Types

The type attribute turns one humble <input> element into more than twenty different controls: text boxes, date pickers, colour pickers, sliders, file choosers and more. Choosing the right type gives users a better keyboard on phones, free validation and less code for you.

All input types at a glance

Type What it shows Notes
text Single-line text The default if type is missing
password Masked text Characters show as dots
email Text field Checks for an @; phone shows @ key
url Text field Must start with a scheme like https://
tel Text field Phone shows a number pad; no format checking
search Text field May show a clear (×) button
number Numeric field with spinner Use min, max, step
range Slider Exact value is less important
date Date picker Value is YYYY-MM-DD
time Time picker Value is HH:MM
datetime-local Date and time picker No time zone
month / week Month or week picker Limited support in some browsers
color Colour picker Value is #rrggbb
checkbox Square tick box Independent on/off
radio Round button One per name group
file File chooser Needs multipart/form-data to upload
hidden Nothing Sends a value the user doesn't see
submit / reset / button Buttons Like <button> but text-only
image Image used as a submit button Sends click coordinates

Text-like types

These all look like text boxes, but each tells the browser what kind of text to expect. On a phone, the keyboard changes to match.

html · try it yourself
<style>
  label { display: block; margin: 6px 0; }
  input { margin-left: 6px; }
</style>
<form action="#">
  <label>Username <input type="text" name="user" value="linh_dev"></label>
  <label>Password <input type="password" name="pw" value="secret123"></label>
  <label>Email <input type="email" name="email" placeholder="you@example.com"></label>
  <label>Website <input type="url" name="site" placeholder="https://"></label>
  <label>Phone <input type="tel" name="phone" placeholder="0901 234 567"></label>
  <label>Search <input type="search" name="q" value="clear me"></label>
  <button>Send</button>
</form>

Type an address without @ into the email field and press Send — the browser refuses and explains why.

Numbers and sliders

number and range both hold numbers and accept min, max and step. Use number when the exact value matters (a quantity) and range when the user just wants "more" or "less" (volume, brightness).

html · try it yourself
<form action="#" oninput="shown.value = vol.value">
  <p><label>Tickets (1–8): <input type="number" name="tickets" min="1" max="8" value="2"></label></p>
  <p>
    <label>Volume: <input type="range" id="vol" name="vol" min="0" max="100" step="5" value="40"></label>
    <output id="shown">40</output>%
  </p>
</form>

Dates, times and colours

Browsers draw their own pickers for these types, so their look differs between Chrome, Firefox and Safari. The submitted value, however, always uses a standard format.

html · try it yourself
<style>
  body { font-family: sans-serif; }
  #preview { width: 120px; height: 50px; border-radius: 8px; border: 1px solid #999; }
</style>
<form action="#">
  <p><label>Birthday <input type="date" name="bday" value="2005-09-02" min="1900-01-01"></label></p>
  <p><label>Alarm <input type="time" name="alarm" value="06:30"></label></p>
  <p><label>Meeting <input type="datetime-local" name="meet" value="2026-01-15T14:00"></label></p>
  <p><label>Theme colour <input type="color" id="c" name="color" value="#e34c26"></label></p>
  <div id="preview"></div>
</form>
<script>
  const c = document.getElementById('c');
  const box = document.getElementById('preview');
  const paint = () => { box.style.background = c.value; box.textContent = c.value; };
  c.addEventListener('input', paint);
  paint();
</script>

Choice types, file and hidden

html · try it yourself
<form id="f">
  <p>Size:
    <label><input type="radio" name="size" value="S"> S</label>
    <label><input type="radio" name="size" value="M" checked> M</label>
    <label><input type="radio" name="size" value="L"> L</label>
  </p>
  <p><label><input type="checkbox" name="newsletter" value="yes" checked> Send me news</label></p>
  <p><label>Photo <input type="file" name="photo" accept="image/*"></label></p>
  <input type="hidden" name="source" value="lesson-page">
  <input type="submit" value="Show data">
  <input type="reset" value="Reset">
</form>
<pre id="out"></pre>
<script>
  document.getElementById('f').addEventListener('submit', (e) => {
    e.preventDefault();
    const rows = [];
    for (const [k, v] of new FormData(e.target)) {
      rows.push(k + ' = ' + (v instanceof File ? (v.name || '(no file)') : v));
    }
    document.getElementById('out').textContent = rows.join('\n');
  });
</script>

The hidden field is invisible but still appears in the data. An unticked checkbox sends nothing at all.

Note: If a browser does not support a type, it falls back to type="text". Your form keeps working — it just loses the special picker.

Tip: hidden fields are not secret. Anyone can see and change them with the browser's developer tools, so never trust them on the server.

Test yourself

Which input type shows a numeric keypad on phones but does not validate the format?

  1. number
  2. tel
  3. digits
  4. phone

What value format does <input type="date"> submit?

  1. DD/MM/YYYY
  2. MM-DD-YYYY
  3. YYYY-MM-DD
  4. Whatever the user's locale shows

What happens when a browser doesn't recognise an input type?

  1. The input disappears
  2. It behaves like type="text"
  3. The form can't be submitted
  4. An error is shown