Skip to content
Tutorials Center
My learning

Topics

Lesson 64 of 122 ยท Forms

Input Types

A guided tour of every HTML input type, from text, email and number to date, color, file and range, with what each one does on desktop and mobile.

The <input> element is the workhorse of HTML forms. On its own it is a plain text box, but its type attribute turns it into something else entirely: a password field, a slider, a color picker, a date picker or a file chooser. Picking the right type gives people a better keyboard on their phone, free validation and a control that works with assistive technology, all without a line of JavaScript.

This lesson tours every type. It is a long list, so the types are grouped by job. Every example uses the submit handler from Forms, so you can see exactly what each control sends.

How type works

<input> is a void element: it has no closing tag and no content. Everything is configured with attributes, starting with type:

HTML
<input type="email" id="work-email" name="work_email">

If you leave type out, or write a value the browser does not recognize, you get type="text". That fallback is deliberate. A browser that does not know a newer type still shows a usable text box, so your form keeps working everywhere.

Text-like types

These six types all show a single-line text box. What changes is the meaning of the value, which affects validation, the on-screen keyboard and autofill.

Type Use it for What you get
text Names, titles, anything free-form A plain text box
password Passwords and PINs Characters are masked; password managers offer to fill and save
email Email addresses Checks for a valid address; mobile keyboards add @
url Web addresses Checks for an absolute URL such as https://โ€ฆ; keyboards add / and .com
tel Phone numbers A phone keypad on mobile; no format check, because phone formats vary worldwide
search Search boxes Often a clear (ร—) button; some keyboards show a Search key
Text-like inputs

Type hello into the email field and press Send. The browser refuses and explains why. Do the same with example.com in the website field: a URL needs a scheme such as https://. Notice that the password is sent as plain text in the pairs; masking only hides it on screen.

On a phone, the type changes the keyboard. Open this page on a phone and tap each field: email, URL and phone each get a different layout. When you need a numeric keyboard for something that is not a number, such as a one-time code, use inputmode, covered in Input Attributes.

Numbers: number and range

type="number" accepts only numbers and usually shows small up and down buttons (a spinner). type="range" shows a slider for when the exact number matters less than the rough position. Both use min, max and step:

HTML
<input type="number" id="guests" name="guests" min="1" max="12" step="1">
<input type="range" id="volume" name="volume" min="0" max="100" step="5">

A range input always has a value. If you do not set one, it starts in the middle between min and max (50 for the defaults of 0 and 100). Because a slider does not show its number, pair it with a visible readout; Output, Meter and Progress shows how.

Not everything made of digits is a number. Credit card numbers, postal codes, phone numbers and IDs can have leading zeros, may contain spaces or letters, and make no sense with a spinner or arrow keys that add 1. Use type="text" with inputmode="numeric" for those. Reserve type="number" for real quantities: ages, amounts, counts.

Dates and times

Five types give people a native picker instead of making them type a date in the right format:

Type Picks Submitted value
date A day 2026-10-13
time A time of day 14:30
datetime-local A day and a time, without a time zone 2026-10-13T14:30
month A month of a year 2026-10
week A week of a year 2026-W42

Whatever the person sees on screen (10/13/2026, 13.10.2026, a calendar), the submitted value always uses these fixed, international formats. That makes life easy on the server: no guessing whether 03/04 means March 4 or April 3.

Date and time inputs

The pickers look different in every browser and operating system, and that is by design: people get the picker they already know. Support for month and week is still patchy in some desktop browsers, which fall back to a plain text box, so test those two before relying on them. You may also see an old type="datetime" in tutorials; it was dropped from HTML years ago and is treated as text.

Color and file

type="color" opens the system color picker. Its value is always a lowercase hex color such as #3366cc, and it defaults to black (#000000).

type="file" lets people choose files from their device. A few attributes shape it:

  • accept limits the choices shown in the file dialog, by type (image/*) or extension (.pdf,.docx). It is a hint, not a security check: the server must still verify every upload.
  • multiple allows selecting more than one file.
  • capture on mobile can ask for the camera directly (capture="environment" for the rear camera).

When a form contains a file input, it must use method="post" and enctype="multipart/form-data", or only the file name is sent. Form Attributes explains why.

In this example the submit script has one small change: a chosen file is a File object, so the script prints its name instead of the object itself.

Color and file inputs

Choose two images and notice that photos appears twice. Repeated names are normal in form data; the server receives a list.

Hidden inputs

type="hidden" sends a value the person never sees or edits:

HTML
<input type="hidden" name="product_id" value="4821">

Servers use hidden inputs for things like the ID of the item being edited or a security token. Hidden does not mean secret, though. Anyone can read and change the value with DevTools, so never trust it blindly on the server. A hidden input needs no label, because no one interacts with it.

Checkboxes and radio buttons

type="checkbox" is an on/off choice, and type="radio" picks exactly one option from a group:

HTML
<input type="checkbox" id="newsletter" name="newsletter">
<label for="newsletter">Send me the monthly newsletter</label>

They have their own rules for values and grouping, so they get a whole lesson: Checkboxes and Radio Buttons.

Button types

Four input types act as buttons. Their visible text comes from the value attribute:

HTML
<input type="submit" value="Place order">
<input type="reset" value="Clear form">
<input type="button" value="Preview">
<input type="image" src="send-button.svg" alt="Send">
  • submit submits the form.
  • reset restores every control to its starting value. It is rarely helpful and easy to press by accident.
  • button does nothing on its own; it exists for scripts.
  • image is a submit button drawn as a picture. It needs alt text, and it also sends the click position as x and y values.

In modern HTML you will usually prefer the <button> element, which can contain text, icons and other markup. Text Areas and Buttons compares the two.

Choosing the right type

When in doubt, ask what the value means rather than what it looks like:

  • Is it an email address, URL or phone number? Use email, url or tel.
  • Is it a quantity you could add or subtract? Use number, or range if a rough value is fine.
  • Is it a calendar value? Use one of the date and time types.
  • Is it a code made of digits? Use text with inputmode="numeric".
  • Is it anything else? text is always a safe choice.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Which type should you use for a postal code like 02134?

    Postal codes are identifiers, not quantities. A number input would drop the leading zero and offer arrow keys that add 1. A text input with a numeric keyboard hint fits best.
  2. 2. A person in Germany picks October 13, 2026 in a type=date field and sees 13.10.2026. What value is submitted?

    Date inputs always submit the ISO-style format year-month-day, whatever the display format is.
  3. 3. What does a browser do with type=datetime, a type that is no longer part of HTML?

    Unknown or obsolete types fall back to text. Use datetime-local for a date and time picker.
  4. 4. Why is accept="image/*" on a file input not enough to keep non-images off your server?

    accept is a convenience for people choosing files. The server must still check every uploaded file.
  5. 5. Which type gives you masked characters and lets password managers fill the field?

    type=password masks what is typed and tells browsers and password managers what the field is for. hidden fields are not shown at all.

Summary

  • type turns <input> into many different controls; unknown types fall back to text.
  • email, url, tel and search are text boxes with meaning: better keyboards, autofill and (for email and URL) validation.
  • Use number and range only for real quantities; use text with inputmode="numeric" for codes.
  • Date and time types submit fixed formats such as 2026-10-13, whatever the person sees.
  • color, file and hidden cover colors, uploads and invisible values; hidden is not secret.
  • submit, reset, button and image are buttons, though the <button> element is usually the better choice.

Next up: Labels, Fieldsets and Legends, the markup that gives every control a name.