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
| Type | Use | Notes |
|---|---|---|
| Text | ||
text | free text on one line | the default when type is missing or unknown |
email | email address | keyboard with “@” on mobile, format checked; multiple accepts several addresses |
tel | phone number | numeric keypad on mobile, no format check |
url | web address | must start with a scheme (https://) |
password | password | characters masked; provides no encryption |
search | search box | clear button in some browsers, “Search” key on mobile |
| Numbers | ||
number | quantity, age, price | spin buttons, min, max, step |
range | slider | approximate value between min and max (50 by default on 0–100) |
| Dates and times | ||
date | a date | value sent as YYYY-MM-DD, whatever the display |
time | a time | value HH:MM (24-hour) |
datetime-local | date and time, no time zone | value YYYY-MM-DDTHH:MM |
month | a month | not supported by every browser (Firefox, notably): the field falls back to text |
week | a week | same limitation as month |
| Choices | ||
checkbox | checkbox | sends nothing when unchecked |
radio | one choice among several | buttons in a group share the same name |
color | colour picker | hexadecimal value #rrggbb |
file | file upload | accept, multiple; requires enctype="multipart/form-data" on the form |
| Buttons and technical fields | ||
submit | submits the form | same as <button type="submit"> |
reset | restores the initial values | rarely useful, often clicked by mistake |
button | button with no default action | driven by JavaScript |
image | image submit button | also sends the click coordinates |
hidden | value sent without being shown | visible 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
| Attribute | Effect |
|---|---|
required | mandatory field: the browser blocks submission if it is empty |
minlength, maxlength | text length |
min, max, step | bounds and step for numbers and dates |
pattern | regular expression the whole value must match (see the regex guide) |
autocomplete | tells the browser what to suggest: email, tel, postal-code, current-password, new-password… |
inputmode | picks the mobile keyboard without changing the type: numeric, decimal, tel, email… |
list + <datalist> | input suggestions, while still allowing any value |
placeholder | sample input; disappears as soon as you type, so it does not replace a label |
readonly, disabled | not 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.