HTML Reference
<input> — The Form Input Element
A single element that becomes 20+ different controls. The workhorse of every form on the web.
Last updated: October 2026
Definition: The <input> element is a void element that creates an interactive control inside a form. Its behavior is entirely determined by the type attribute — text, email, number, date, file, checkbox, radio, and more.
🎬 Live Example
The same element, eight different types. Try each one.
💡 Every control above is the same <input> element — only the type attribute differs.
Basic Syntax
<input type="text" id="name" name="name" placeholder="Your name">
Input is a void element — no closing tag. The type attribute determines what kind of control it becomes.
🎯 All Input Types
| Type | Purpose | Mobile Keyboard |
|---|---|---|
text | Generic text input. Default. | Standard |
email | Email addresses. Validates format. | @ visible |
password | Masked text. | Standard |
tel | Phone numbers. | Dial pad |
url | Web addresses. Validates URL. | .com key |
search | Search boxes with a clear button. | Search key |
number | Numeric input with steppers. | Numeric |
range | Slider between min and max. | Slider UI |
date | Date picker. | Date picker |
time | Time picker. | Time picker |
datetime-local | Date and time. | Combined picker |
month | Month and year. | Month picker |
week | Week and year. | Week picker |
color | Color picker. | Color wheel |
file | File upload. | File picker |
checkbox | Multiple-choice toggle. | Toggle |
radio | Single-choice from a group. | Radio |
hidden | Invisible data sent with the form. | — |
submit / reset / button | Button variants. | — |
⚙️ Attributes Reference
| Attribute | Purpose |
|---|---|
type | The control type. Default is text. |
name | The key sent to the server. Required for form submission. |
id | Unique identifier. Required for labels to work. |
value | The initial value. |
placeholder | Hint text. Disappears when typing. |
required | Field cannot be empty. |
disabled | Cannot be edited or submitted. |
readonly | Cannot be edited but is submitted. |
min / max | Range limits for number, date, range. |
minlength / maxlength | Text length limits. |
pattern | Regex validation. |
step | Increment step for number/range. |
autocomplete | Autofill hint (name, email, tel, etc.). |
autofocus | Focus this field on page load. |
multiple | Allow multiple values (email, file). |
accept | File type filter for type="file". |
checked | Pre-select a checkbox or radio. |
The Three Essential Inputs
<label for="name">Full Name</label>
<input type="text" id="name" name="name"
placeholder="Jane Doe" required
autocomplete="name">
<label for="email">Email</label>
<input type="email" id="email" name="email"
placeholder="jane@example.com" required
autocomplete="email">
<label for="password">Password</label>
<input type="password" id="password" name="password"
minlength="8" required
autocomplete="new-password">
Notice how each input has: type, id, name, and matches a <label> via the for attribute.
Validation Attributes
<!-- Required -->
<input type="text" required>
<!-- Length -->
<input type="text" minlength="3" maxlength="20">
<!-- Numeric range -->
<input type="number" min="18" max="120" step="1">
<!-- Regex pattern -->
<input type="text" pattern="[0-9]{3}-[0-9]{4}"
title="Format: 123-4567">
<!-- Custom error message -->
<input type="email" required
title="Please enter a valid email">
All of these work without JavaScript. The browser shows native error messages and blocks form submission.
Checkbox vs Radio
<!-- Checkboxes: multiple selections -->
<label><input type="checkbox" name="features" value="wifi"> WiFi</label>
<label><input type="checkbox" name="features" value="parking"> Parking</label>
<label><input type="checkbox" name="features" value="pool"> Pool</label>
<!-- Radio buttons: single selection -->
<label><input type="radio" name="plan" value="basic"> Basic</label>
<label><input type="radio" name="plan" value="pro" checked> Pro</label>
<label><input type="radio" name="plan" value="enterprise"> Enterprise</label>
Key difference: checkboxes are independent; radio buttons with the same name form a group where only one can be selected.
File Upload with Filter
<input type="file" id="avatar" name="avatar"
accept="image/png, image/jpeg, image/webp">
<!-- Multiple files -->
<input type="file" id="docs" name="docs"
accept=".pdf,.doc,.docx" multiple>
<!-- Camera capture on mobile -->
<input type="file" accept="image/*" capture="environment">
Date and Number Pickers
<!-- Date -->
<input type="date" id="birthday" name="birthday"
min="1900-01-01" max="2026-12-31">
<!-- Time -->
<input type="time" id="appt" name="appt"
min="08:00" max="18:00" step="900">
<!-- Range slider -->
<input type="range" id="volume" name="volume"
min="0" max="100" step="5" value="50">
<!-- Color picker -->
<input type="color" id="brand" name="brand" value="#3b82f6">
Hidden Input
Send data with the form that the user doesn't see.
<input type="hidden" name="user_id" value="12345">
<input type="hidden" name="referrer" value="google">
<input type="hidden" name="csrf_token" value="abc123">
Warning: Hidden inputs are visible in the page source. Never store sensitive values like passwords or API keys in them. Use server-side state instead.
🎯 Autocomplete Values Cheatsheet
| Value | Use for |
|---|---|
name | Full name. |
email | Email address. |
tel | Phone number. |
street-address | Street address. |
address-level2 | City / town. |
postal-code | ZIP / postal code. |
country | Country. |
cc-number | Credit card number. |
cc-exp | Card expiry date. |
cc-csc | Card security code. |
current-password | Existing password (login). |
new-password | New password (signup). |
⚠️ Common Mistakes
- Using
type="text"for email, phone, or numbers. You lose built-in validation, mobile keyboards, and autofill. - Missing
nameattribute. The input isn't sent to the server. Every input that needs to be submitted needs aname. - Missing
idwhen there's a label. Theforattribute on the label needs a matchingidon the input. - Using a placeholder instead of a label. Placeholders aren't accessible. Always pair inputs with a real
<label>. - Not setting
autocomplete. Users expect browsers to fill name, email, and address. Correct autocomplete values speed up forms dramatically. - Using the same
namefor unrelated checkboxes. Checkboxes with the same name form a group — usually that's what you want, but not always. - Relying only on client-side validation. Always validate on the server too. Client validation is UX, not security.
♿ Accessibility Notes
- Every input needs a label. Use
<label for="id">matching the input'sid. Screen readers announce the label when the field is focused. - Placeholders are not labels. They disappear when the user types and aren't announced consistently by screen readers.
- Mark required fields semantically and visually. Use
required(semantic) and a visible asterisk (visual). - Group radio buttons and checkboxes. Wrap them in
<fieldset>with a<legend>so screen readers announce the group. - Announce validation errors. Use
aria-live="polite"on the error container so screen readers announce the message. - Use the correct
typefor the input. It changes the mobile keyboard, which is a massive usability win for touch users. - Test with keyboard only. Tab through the form. Focus should be visible and the order should match the visual layout.
❓ Frequently Asked Questions
What is the HTML <input> tag?
The <input> element is a void element that creates an interactive control for forms. Its behavior is determined by the type attribute — text, email, number, date, file, checkbox, radio, and 20+ others.
What is the most common input type?
type="text" is the most common, but type="email", type="tel", type="number", type="date", and type="password" are all essential. Each triggers a specific mobile keyboard and built-in validation.
What is the difference between id and name?
name is the key sent to the server when the form submits. id is a unique identifier used by CSS, JavaScript, and labels (for= attribute). Every input needs both if it's part of a form and has a label.
What does the required attribute do?
required tells the browser the field must be filled before the form can submit. The browser shows a native error message and blocks submission if the field is empty.
What is the difference between checkbox and radio?
Checkboxes allow selecting multiple options independently. Radio buttons allow selecting only one option from a group. Radios with the same name attribute form a group.