Master Code
On The Go

Learn. Practice. Build.

Home › Code Snippets › HTML Snippets › Reference › <input>

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
textGeneric text input. Default.Standard
emailEmail addresses. Validates format.@ visible
passwordMasked text.Standard
telPhone numbers.Dial pad
urlWeb addresses. Validates URL..com key
searchSearch boxes with a clear button.Search key
numberNumeric input with steppers.Numeric
rangeSlider between min and max.Slider UI
dateDate picker.Date picker
timeTime picker.Time picker
datetime-localDate and time.Combined picker
monthMonth and year.Month picker
weekWeek and year.Week picker
colorColor picker.Color wheel
fileFile upload.File picker
checkboxMultiple-choice toggle.Toggle
radioSingle-choice from a group.Radio
hiddenInvisible data sent with the form.—
submit / reset / buttonButton variants.—

⚙️ Attributes Reference

Attribute Purpose
typeThe control type. Default is text.
nameThe key sent to the server. Required for form submission.
idUnique identifier. Required for labels to work.
valueThe initial value.
placeholderHint text. Disappears when typing.
requiredField cannot be empty.
disabledCannot be edited or submitted.
readonlyCannot be edited but is submitted.
min / maxRange limits for number, date, range.
minlength / maxlengthText length limits.
patternRegex validation.
stepIncrement step for number/range.
autocompleteAutofill hint (name, email, tel, etc.).
autofocusFocus this field on page load.
multipleAllow multiple values (email, file).
acceptFile type filter for type="file".
checkedPre-select a checkbox or radio.
1

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.

2

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.

3

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.

4

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">
5

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">
6

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
nameFull name.
emailEmail address.
telPhone number.
street-addressStreet address.
address-level2City / town.
postal-codeZIP / postal code.
countryCountry.
cc-numberCredit card number.
cc-expCard expiry date.
cc-cscCard security code.
current-passwordExisting password (login).
new-passwordNew password (signup).

⚠️ Common Mistakes

♿ Accessibility Notes

❓ 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.

🎯 What's Next?

← All HTML Reference