Explain it simply
Explain it simply
Think of <input> as a shape-shifting tool. It is a single tag, yet changing one attribute, type, turns it into a text box, a calendar picker, a tick box, a box that hides a password, and more.
type changes more than looks. It decides which keyboard a phone shows, what the browser checks for you, and what value reaches the server when the form is submitted. So you first ask "what kind of data is this?" and only then pick the type.
Problem → Why → Solution
The problem: asking for a phone number with type="number"
A phone number is made of digits, so type="number" looks like a good fit. But when a user types +95 9 4512 3456 with a country code and spaces, Chrome cannot parse it as a valid number, so the field's value becomes an empty string and nothing reaches the server. Even 09451234567 loses its leading 0 as soon as JavaScript converts it with Number().
<label for="phone">Phone</label>
<input id="phone" name="phone" type="number">
<!-- User types "+95 9 4512 3456" -> input.value is "" (nothing submitted) -->
<!-- User types "09451234567" -> Number(input.value) is 9451234567 -->
<!-- Up/down arrow keys and spinner buttons now "increment" the phone number -->Why does this happen?
type="number" is meant for quantities you calculate with. The browser checks the value as a floating-point number, treats +, spaces and dashes as invalid, and adds spinner buttons. You never add or subtract phone numbers: a phone number is an identifier that happens to be written with digits, which makes it text. type="tel" brings up a phone keypad and keeps exactly what was typed.
Core concept: the four things type changes
An <input>'s type decides four things at once. First, the native control the browser draws: date gives a calendar picker, checkbox a tick box, password a box that masks characters with dots. Second, the mobile keyboard: email brings up a keyboard with an @ key, tel a numeric phone keypad.
Third, built-in validation: type="email" flags a value without an @ as a typeMismatch, and number flags values outside min/max. Fourth, the submitted value format. Whatever format a date field shows on screen, it always sends YYYY-MM-DD, such as 2026-11-09. A checkbox is sent only when it is ticked, and sends "on" if it has no value attribute.
When a browser meets a type it does not know, it silently falls back to type="text". This is progressive enhancement: newer browsers get a richer UI and older ones still have a working form. Browser validation is only a convenience for the user, though. Anyone can delete an attribute in DevTools or send a request directly, so the server must check every value again.
Keep one question in mind when choosing: "will I ever do arithmetic with this value?" Ticket counts, ages and amounts are number. Phone numbers, postal codes, card numbers and OTP codes are text (or tel), with inputmode="numeric" to request a digit keyboard. The table below sums up what the most common types give you and what each one submits.
| type | What you get | Submitted value |
|---|---|---|
| text | Plain text box | Exactly as typed |
| @ keyboard + format check | Exactly as typed | |
| tel | Phone keypad, no format check | Exactly as typed |
| number | Spinner + min/max check | Decimal string ("" if invalid) |
| date | Calendar picker | YYYY-MM-DD |
| checkbox | Tick box | value only if ticked (default "on") |
- Ask what the data is
- Will you do arithmetic with it?
- Pick type (+ inputmode)
- Predict the submitted value
- Validate again on the server
type does not pick a look; it tells the browser what the data means.
General pattern
<label for="field-id">Visible label</label>
<input id="field-id" name="fieldName" type="kind" autocomplete="hint">
<!-- identifiers made of digits: text + a numeric keyboard -->
<input id="code-id" name="code" type="text" inputmode="numeric">
<!-- a tick box sends name=value only when it is checked -->
<input id="opt-id" name="option" type="checkbox" value="yes">id connects the label, name becomes the key sent to the server, and type says what kind of data it is. autocomplete hints which saved data the browser may fill in.
Example: a labelled sign-up form
Every field here has a label, and each type is picked from the data: tel for the phone, number only for the ticket count. Do not use a placeholder in place of a label: it disappears as soon as the user starts typing and is not a reliable name for screen readers.
<form action="/signup" method="post">
<p>
<label for="full-name">Full name</label>
<input id="full-name" name="fullName" type="text" autocomplete="name">
</p>
<p>
<label for="email">Email</label>
<input id="email" name="email" type="email" autocomplete="email">
</p>
<p>
<label for="phone">Phone</label>
<input id="phone" name="phone" type="tel" autocomplete="tel">
</p>
<p>
<label for="password">Password</label>
<input id="password" name="password" type="password" autocomplete="new-password">
</p>
<p>
<label for="tickets">Tickets</label>
<input id="tickets" name="tickets" type="number" min="1" max="10" value="1">
</p>
<p>
<label for="visit">Visit date</label>
<input id="visit" name="visit" type="date">
</p>
<p>
<input id="news" name="newsletter" type="checkbox" value="yes">
<label for="news">Send me the monthly newsletter</label>
</p>
<button type="submit">Sign up</button>
</form>Code breakdown
- Email field
<input id="email" name="email" type="email" autocomplete="email">type="email" gives mobile users an @ keyboard and checks the format before submitting. autocomplete="email" lets the browser offer the user's saved address.
- Phone as tel
<input id="phone" name="phone" type="tel" autocomplete="tel">tel shows a phone keypad but does not validate the format, because phone formats differ by country. +95 and spaces are sent exactly as typed.
- Password
type="password" autocomplete="new-password"password only masks characters on screen; it does not encrypt anything, which is HTTPS's job. new-password tells password managers to suggest a fresh password.
- Quantity as number
type="number" min="1" max="10" value="1"A ticket count is a real quantity, so number fits. min/max limit the spinner and flag a value like 11 as rangeOverflow, and value="1" is the starting value.
- Date
<input id="visit" name="visit" type="date">The picker displays the user's locale format, but the submitted value is always YYYY-MM-DD, such as visit=2026-11-09.
- Checkbox
<input id="news" name="newsletter" type="checkbox" value="yes">When ticked it sends newsletter=yes; when unticked the newsletter key is missing from the request entirely. Putting a checkbox's label after the box is the usual convention.
Each field appears on its own line next to its label: three text boxes (name, email, phone), a password box that shows dots, a Tickets box showing 1 with up/down arrows, a date box with a calendar picker, a labelled checkbox and a Sign up button. Clicking a label focuses its field.Radio buttons versus checkboxes
Each checkbox is an independent yes/no choice. Radio buttons that share a name form a group in which only one can be selected. Wrapping the group in a fieldset with a legend lets a screen reader announce the question along with each option, and arrow keys move the selection within the group.
<fieldset>
<legend>Ticket type</legend>
<input id="t-std" name="ticketType" type="radio" value="standard" checked>
<label for="t-std">Standard</label>
<input id="t-vip" name="ticketType" type="radio" value="vip">
<label for="t-vip">VIP</label>
</fieldset>inputmode and autocomplete
inputmode only changes the keyboard and adds no validation; values include numeric, decimal, tel and email. That is why type="text" inputmode="numeric" suits a postal code: it keeps leading zeros and still shows digits. autocomplete uses tokens such as name, email, tel, postal-code and one-time-code to tell the browser what to fill in, which saves a lot of typing on mobile.
In real projects
Where this shows up in real projects
On checkout pages, the right type and autocomplete directly affect how many people finish. An email field without an @ keyboard on a phone, a card number field with a spinner, or a postal code that loses its 0 are all reasons users abandon a form. On a login form, autocomplete="username" and "current-password" let password managers work smoothly.
In booking systems the date input's YYYY-MM-DD format is a gift: wherever the user lives, the server parses a single format. Before shipping a form, teams tap every field on a real phone to check the keyboard, confirm autofill works, and compare the submitted name=value pairs with what the backend expects.
Forms for users in Myanmar receive phone numbers typed both as 09... and as +95.... type="tel" accepts both, and the server normalizes them, for example into a single +959 format. Splitting the work this way never blocks the user in the browser while still keeping the stored data clean.
Common mistakes
Common mistakes
1. Using type="number" for identifiers
Using number for a phone, postal code, card number or OTP makes + and spaces invalid, adds a spinner, and lets a scroll of the mouse wheel change the value. Use type="tel", or type="text" with inputmode="numeric".
2. Assuming type="email" checks for a real address
The browser checks shape only: even a@b, with no dot in the domain, is valid. To know a mailbox really exists, the server has to send a confirmation email.
3. Expecting an unticked checkbox to send "off"
An unticked checkbox is left out of the request completely. Server code must treat a missing key as false, and without a value attribute a ticked box sends the meaningless string "on".
Best practices
Best practices
- Give every input a label, an id and a name; a placeholder is not a label.
- Add the matching autocomplete token to every field that has one.
- Test the form on a real phone and check each keyboard that appears.
Mini challenge
Mini challenge: a workshop registration form
Write a registration form for a workshop. Choose each type by asking whether you will ever calculate with the value.
- Name (text), email and phone (tel) fields with labels and autocomplete
- A postal code written as text + inputmode="numeric" so leading zeros survive
- A guest-count number field that only allows 0 to 3
- A Morning / Afternoon session choice as a radio group inside a fieldset with a legend
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Workshop registration</title>
</head>
<body>
<form action="/register" method="post">
<!-- TODO: name, email and phone, each with a label and autocomplete -->
<!-- TODO: postal code that keeps leading zeros but shows a digit keyboard -->
<!-- TODO: number of guests, allowed range 0 to 3 -->
<!-- TODO: fieldset + legend with two radio buttons sharing one name -->
<!-- TODO: a submit button -->
</form>
</body>
</html>Expected: Five labelled fields, a bordered Session group with two radio buttons, and a Register button appear. Typing 01234 as the postal code submits postalCode=01234 unchanged, and entering 5 guests makes the browser block the submit.
Show hint
Both radio buttons need the same name and different values. The autocomplete token for a postal code is postal-code.
Show solution
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Workshop registration</title>
</head>
<body>
<form action="/register" method="post">
<p>
<label for="name">Your name</label>
<input id="name" name="name" type="text" autocomplete="name">
</p>
<p>
<label for="mail">Email</label>
<input id="mail" name="email" type="email" autocomplete="email">
</p>
<p>
<label for="tel">Phone</label>
<input id="tel" name="phone" type="tel" autocomplete="tel">
</p>
<p>
<label for="zip">Postal code</label>
<input id="zip" name="postalCode" type="text" inputmode="numeric"
autocomplete="postal-code">
</p>
<p>
<label for="guests">Guests you will bring</label>
<input id="guests" name="guests" type="number" min="0" max="3" value="0">
</p>
<fieldset>
<legend>Session</legend>
<input id="am" name="session" type="radio" value="morning" checked>
<label for="am">Morning</label>
<input id="pm" name="session" type="radio" value="afternoon">
<label for="pm">Afternoon</label>
</fieldset>
<button type="submit">Register</button>
</form>
</body>
</html>Quick quiz 1 / 3
Quick quiz 2 / 3
Quick quiz 3 / 3
What to remember
- type decides the native control, the mobile keyboard, built-in validation and the submitted value format.
- Use number only for quantities; phone numbers, postal codes and OTPs need tel or text plus inputmode.
- A date submits YYYY-MM-DD, and a checkbox submits only when ticked.
- Browser validation is a convenience; always validate again on the server.
HTML Living Standard — Forms — WHATWG