- Home
- /
- Tutorials
- /
- HTML Tutorial
- /
- HTML Input Types
HTML Forms
HTML Input Types
The
typeattribute decides what an<input>is: a text box, a checkbox, a date picker, a file chooser. Picking the right one gets you the right on-screen keyboard on phones, some validation for free, and a control users already know how to operate. Picking the wrong one quietly breaks the form.
Try it
A short signup form using five different types. Run it, then open the preview on a phone if you can: the keyboard changes for each field.
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Input types</title>
<style>
label { display: block; margin-bottom: 12px; }
input:not([type=checkbox]) { display: block; width: 100%; max-width: 320px; padding: 8px; }
input:invalid:not(:placeholder-shown) { border-color: #dc2626; }
</style>
</head>
<body>
<form>
<label>Name <input type="text" name="name" autocomplete="name" required></label>
<label>Email <input type="email" name="email" autocomplete="email" required></label>
<label>Phone <input type="tel" name="phone" autocomplete="tel" inputmode="tel"></label>
<label>Date of birth <input type="date" name="dob"></label>
<label>Password <input type="password" name="password" minlength="8" required></label>
<label><input type="checkbox" name="news"> Send me the newsletter</label>
<button type="submit">Create account</button>
</form>
</body>
</html>Press "Create account" with the email field empty or malformed: the browser blocks submission and explains why. That is built-in validation, and it only works when the type is right.
Text-like types
| Type | Use it for | What you get |
|---|---|---|
| text | Anything short with no better type | The default. A plain single-line box. |
| Email addresses | Validates the shape (something@something), shows @ on phone keyboards. Add multiple for comma-separated lists. | |
| tel | Phone numbers | Numeric phone keypad on mobile. No validation: phone formats vary too much. Add pattern if you need one. |
| url | Web addresses | Requires a scheme (https://…); keyboard shows / and .com. |
| password | Passwords, PINs, secrets | Masks the characters. Pair with autocomplete="new-password" or "current-password" so password managers work. |
| search | Search boxes | Looks like text; some browsers add a clear (×) button and a Search key on the keyboard. |
| number | Actual quantities: count, price, age | Spinner arrows, min/max/step, numeric keyboard. Strips leading zeros and rejects letters. |
Pickers
| Type | Value format | Notes |
|---|---|---|
| date | 2026-09-16 | Native calendar. The value is always ISO regardless of how the user sees it. |
| time | 14:30 | 24-hour in the value even if the picker shows 12-hour. |
| datetime-local | 2026-09-16T14:30 | No time zone: it is the user's local time. Convert on the server. |
| month, week | 2026-09, 2026-W38 | Safari has been slow to support these; they fall back to text. |
| color | #0ea5e9 | System colour picker. Always a 7-character lowercase hex. |
| range | A number | A slider. Users cannot see the exact value, so show it next to the control. |
| file | One or more files | Add accept="image/*" to filter and multiple to allow several. The form needs enctype="multipart/form-data". |
Choices and buttons
| Type | Behaviour |
|---|---|
| checkbox | Independent on/off. Only checked boxes are submitted, as name=value (value defaults to on). |
| radio | One of a group. Radios with the same name form the group; exactly one submits. |
| submit | Sends the form. Its value is the button label. |
| reset | Clears the form to its initial values. Users rarely want this; leave it out. |
| button | Does nothing by itself, for JavaScript. Prefer the element, which can hold markup. |
| image | A submit button that is a picture, and sends the click coordinates. Rare. |
| hidden | Not shown. Sends a value along with the form: a record id, a CSRF token. |
A realistic example: a quantity field done right
type="number" is the type people misuse most, so here is a case where it is correct, a quantity in a shopping cart, with the attributes that make it behave.
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Quantity field</title>
<style>
input { width: 5em; padding: 6px; font-size: 16px; }
.hint { color: #64748b; font-size: 14px; }
</style>
</head>
<body>
<label for="qty">Quantity</label>
<input id="qty" type="number" name="qty" value="1" min="1" max="10" step="1" inputmode="numeric">
<p class="hint">Between 1 and 10 per order.</p>
</body>
</html>min and max stop the spinner going out of range and fail validation if someone types 0 or 99. step="1" rejects 1.5. font-size: 16px stops iOS zooming the page when the field is focused: that applies to every input type.
Common mistakes
1. type="number" for things that are not numbers
Phone numbers, PIN codes, card numbers, OTPs and postcodes are strings of digits, not quantities. A number field strips the leading zero from 01234, refuses +91, shows useless up/down arrows, and in some browsers changes the value when you scroll over it. Use type="text" with inputmode="numeric", that gives the digit keyboard without the number behaviour, or type="tel" for phones.
2. Trusting type="email" as validation
The browser only checks the shape. a@b passes. It will not tell you the address exists or the domain has mail. Treat it as a typo guard, and validate on the server.
3. No label
Every type needs a <label>. placeholder is not a label: it disappears as soon as the user types, it is skipped by many screen readers, and its grey text often fails contrast. This is the single most common form accessibility failure.
4. Assuming the date picker looks the same everywhere
type="date" is a calendar in Chrome, a wheel on iOS, and plain text in some older browsers. The value is always YYYY-MM-DD, which is what matters; do not try to style the picker itself to match a design, because you largely cannot.
5. Forgetting autocomplete
Browsers can fill names, emails, addresses and cards in one tap, but only if you tell them which field is which. autocomplete="email", "tel", "postal-code", "cc-number". On a phone this is the difference between a form people finish and one they abandon.
6. Unknown types
A typo like type="emial" does not error. The browser falls back to text, and you lose the keyboard and validation without noticing. Validate your HTML.
Browser support
The text-like types, checkbox, radio, file, hidden and the buttons work everywhere. date, time, color and range are supported in all current browsers; month and week are missing in Safari and Firefox on desktop and fall back to plain text, which still submits fine.
Related chapters
- The <input> tag: the element itself
- Input attributes:
min,pattern,requiredand the rest - Form validation
- The <label> tag
- Styling input fields
HTML Input Types exercises
An email field
Add the label Email for a field that takes only email addresses. Its id and name are email.
Result
