The <input> element creates most form fields, and its type attribute changes everything: how the field looks, the keyboard offered on mobile, the validation done by the browser and the value sent. The HTML standard defines 22 types. Choosing well saves unnecessary JavaScript and makes the form far nicer to use, especially on a phone.

The 22 types in one table

TypeUseNotes
Text
textfree text on one linethe default when type is missing or unknown
emailemail addresskeyboard with “@” on mobile, format checked; multiple accepts several addresses
telphone numbernumeric keypad on mobile, no format check
urlweb addressmust start with a scheme (https://)
passwordpasswordcharacters masked; provides no encryption
searchsearch boxclear button in some browsers, “Search” key on mobile
Numbers
numberquantity, age, pricespin buttons, min, max, step
rangesliderapproximate value between min and max (50 by default on 0–100)
Dates and times
datea datevalue sent as YYYY-MM-DD, whatever the display
timea timevalue HH:MM (24-hour)
datetime-localdate and time, no time zonevalue YYYY-MM-DDTHH:MM
montha monthnot supported by every browser (Firefox, notably): the field falls back to text
weeka weeksame limitation as month
Choices
checkboxcheckboxsends nothing when unchecked
radioone choice among severalbuttons in a group share the same name
colorcolour pickerhexadecimal value #rrggbb
filefile uploadaccept, multiple; requires enctype="multipart/form-data" on the form
Buttons and technical fields
submitsubmits the formsame as <button type="submit">
resetrestores the initial valuesrarely useful, often clicked by mistake
buttonbutton with no default actiondriven by JavaScript
imageimage submit buttonalso sends the click coordinates
hiddenvalue sent without being shownvisible and editable in the page source: never for sensitive data

A well-built form

<form action="/signup" method="post">
  <label for="email">Email</label>
  <input type="email" id="email" name="email" autocomplete="email" required>

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

  <label for="zip">ZIP code</label>
  <input type="text" id="zip" name="zip" inputmode="numeric" pattern="[0-9]{5}" autocomplete="postal-code">

  <label for="birth">Date of birth</label>
  <input type="date" id="birth" name="birth" max="2026-12-31">

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

  <button type="submit">Create my account</button>
</form>

Each field has a <label> linked through for / id: clicking the label focuses the field, and screen readers announce the right name.

Attributes worth knowing

AttributeEffect
requiredmandatory field: the browser blocks submission if it is empty
minlength, maxlengthtext length
min, max, stepbounds and step for numbers and dates
patternregular expression the whole value must match (see the regex guide)
autocompletetells the browser what to suggest: email, tel, postal-code, current-password, new-password…
inputmodepicks the mobile keyboard without changing the type: numeric, decimal, tel, email…
list + <datalist>input suggestions, while still allowing any value
placeholdersample input; disappears as soon as you type, so it does not replace a label
readonly, disablednot editable; a disabled field is not submitted

The most common mistakes

Using number for a ZIP code, phone or card number

type="number" is meant for quantities. It shows pointless spin buttons, accepts input such as “1e5”, rejects the spaces and dashes of a number, and in some browsers the value changes if you turn the mouse wheel while the field is focused. For an identifier made of digits, use type="text" with inputmode="numeric" and a pattern.

Relying on browser validation

Checks such as required, email or pattern improve comfort, but anyone can bypass them. Always validate data on the server.

Replacing the label with a placeholder

The text disappears at the first keystroke: users no longer know what they are filling in, and the contrast is often too low. Keep a real <label>.

Forgetting name

A field without a name attribute is not submitted with the form, even if it is filled in.

Frequently asked questions

What is the difference between <input type="submit"> and <button>?

Both submit the form. <button> can contain HTML (an icon, formatted text), which makes it more flexible. Note that inside a form, a <button> without a type is a submit button.

How do I display the date as MM/DD/YYYY?

You do not choose the display: the browser follows the user’s language settings. The value received, however, is always YYYY-MM-DD, which makes processing easier.

What happens to an unknown type?

The browser treats it as text. That is why you can use month or week without breaking the page, as long as you accept free input where they are not supported.