HTML5 Forms Reference

HTML Input Types

Everything every front-end developer should know — every type, every attribute, every edge case, in one interactive reference.

01 · Introduction

One element, twenty-two behaviors

The <input> element is the workhorse of HTML forms — a single element whose behavior, appearance and validation rules are entirely determined by its type attribute.

Before HTML5, developers relied on type="text" plus JavaScript to fake everything else: e-mail checks, date pickers, sliders. HTML5 moved those responsibilities into the browser itself, giving every device a native, accessible, and often mobile-optimized control for free.

Picking the right type is not a cosmetic choice. It changes the keyboard shown on mobile, the validation the browser performs before your JavaScript ever runs, and what assistive technology tells a screen-reader user about the field.

Why the type attribute matters
01
Native validation

Browsers enforce format rules before submission — no library required.

02
Contextual keyboards

Mobile devices swap in numeric pads, e-mail symbols, or URL keys automatically.

03
Built-in UI

Date pickers, color swatches and sliders ship with the browser — zero JS.

04
Accessibility for free

Semantic types are announced correctly by screen readers out of the box.

02 · Text Inputs

Single-line text

Six types that all render as a text box, but each carries its own validation, keyboard and semantics.

text

default

The baseline free-form text field. No format validation — use it for names, titles or anything without a predictable pattern.

HTML
<label for="name">Full name</label>
<input type="text" id="name" name="name"
  placeholder="Ada Lovelace" required>

email

validated

Requires a valid name@domain pattern before the form can submit, and triggers the @ keyboard on mobile.

HTML
<input type="email" id="email"
  placeholder="you@example.com"
  multiple required>

password

masked

Masks every character as it's typed. Pair it with minlength and a pattern for strength rules.

HTML
<input type="password" id="pwd"
  minlength="8" autocomplete="new-password"
  required>

search

semantic

Visually similar to text, but adds a native clear (×) button in most browsers and tells assistive tech this is a search field.

HTML
<input type="search" id="q"
  placeholder="Search…"
  aria-label="Search docs">

tel

no format

Shows a numeric phone keypad on mobile. It does not validate format by default — use pattern for country-specific rules.

HTML
<input type="tel" id="phone"
  pattern="[0-9+()\- ]{7,}"
  placeholder="+1 (555) 000-0000">

url

validated

Requires a full, valid URL including scheme (https://) and shows the .com-friendly keyboard on mobile.

HTML
<input type="url" id="site"
  placeholder="https://yoursite.com">
03 · Number & Date

Numeric & temporal values

Native pickers and steppers that guarantee a machine-readable value — no date-parsing library required.

number

stepper

Restricts input to numeric values and adds increment/decrement arrows. Combine with min, max and step.

HTML
<input type="number" id="qty"
  min="1" max="10" step="1"
  value="1">

range

imprecise

A visual slider for approximate values where the exact number is less important than the position — volume, brightness, price filters.

HTML
<input type="range" id="budget"
  min="0" max="100" value="60">

date

picker

Opens a native calendar picker and always submits an unambiguous YYYY-MM-DD value regardless of locale display.

HTML
<input type="date" id="dob"
  max="2015-01-01">

time

picker

A native hour/minute picker, submitted in 24-hour HH:MM format regardless of the locale shown to the user.

HTML
<input type="time" id="slot"
  step="900">

month

picker

Captures a year and month only — ideal for expiry dates or billing periods where a specific day doesn't apply.

HTML
<input type="month" id="expiry"
  min="2024-01">

week

picker

Captures an ISO week number within a year — useful for weekly reports, sprints, or shift scheduling.

HTML
<input type="week" id="sprint">

datetime-local

picker

Combines date and time into a single control, without timezone conversion — the value is local to whatever the user selects.

HTML
<input type="datetime-local"
  id="start" step="60">
04 · Selection

Choices & media

Controls for picking one option, many options, a color, or a file from disk.

checkbox

multi

An independent on/off toggle. Group several under one name to collect multiple selections.

HTML
<input type="checkbox" id="news"
  name="news" checked>
<label for="news">Email updates</label>

radio

single

Mutually exclusive options. Every radio in the group must share the same name so only one can be selected.

HTML
<input type="radio" id="m"
  name="plan" checked>
<label for="m">Monthly</label>

color

picker

Opens the OS-native color picker and always returns a lowercase 6-digit hex value like #4f8cff.

HTML
<input type="color" id="accent"
  value="#4f8cff">

file

upload

Opens the OS file picker. Restrict formats with accept, and allow multiple files with the multiple attribute.

HTML
<input type="file" id="avatar"
  accept="image/*">
05 · Action Inputs

Buttons & hidden values

Types that trigger behavior or travel silently with the form instead of collecting typed input.

submit

action

Submits the enclosing form. A form's first submit button also fires when the user presses Enter inside any text field.

HTML
<input type="submit"
  value="Create account">

reset

action

Clears every field in the form back to its default value. Use sparingly — it's a common source of accidental data loss.

HTML
<input type="reset"
  value="Clear form">

button

no default

Does nothing on its own — no submit, no reset. Exists purely as a hook for your own JavaScript event listener.

HTML
<input type="button"
  value="Preview" onclick="…">

image

graphical submit

A submit button rendered as an image, and it also reports the x/y coordinates the user clicked — a legacy pattern, rarely needed today.

[ image-based submit button ]
HTML
<input type="image"
  src="pay.svg" alt="Pay now">

hidden

invisible

Never rendered, never focusable — carries data like a CSRF token or session ID silently to the server on submit.

[ carries csrf_token silently ]
HTML
<input type="hidden"
  name="csrf_token" value="…">
06 · In Practice

A real registration form

Every input type above, working together in one realistic sign-up flow.

Create your account

Join the reference — no spam, ever.

Between 1 and 50 seats.

07 · Common Mistakes

What goes wrong — and why

Small choices that silently break validation, accessibility, or mobile UX.

Wrong
<input type="text" placeholder="Email">
Correct
<input type="email" placeholder="Email">

Why it matters: using text for an email field loses native format validation and the @ keyboard on mobile — you end up rebuilding both in JavaScript.

Wrong
<input type="text" placeholder="Full name">
Correct
<label for="name">Full name</label>
<input type="text" id="name">

Why it matters: a placeholder is not a label. It disappears once typing starts and is often skipped by screen readers — always pair a real <label> with a matching id.

Wrong
<input type="number" id="phone">
Correct
<input type="tel" id="phone">

Why it matters: type="number" strips leading zeros and adds stepper arrows that make no sense for a phone number. Use tel instead, which keeps the string intact.

Wrong
<input type="checkbox" id="terms">
I agree to the terms
Correct
<input type="checkbox" id="terms">
<label for="terms">I agree to the terms</label>

Why it matters: loose text next to a checkbox isn't clickable and isn't announced as its label. Wrapping it in a proper <label> expands the tappable area and fixes both.

08 · Cheat Sheet

Every input type, at a glance

The complete reference table — bookmark this section.

Every HTML input type, its purpose, an example, and browser support
Input TypePurposeExampleBrowser Support
textFree-form single-line text<input type="text">Universal
emailValidated email address<input type="email">Universal
passwordMasked sensitive text<input type="password">Universal
searchSearch field with clear button<input type="search">Universal
telPhone number, numeric keypad<input type="tel">Universal
urlValidated web address<input type="url">Universal
numberNumeric value with stepper<input type="number">Universal
rangeApproximate value via slider<input type="range">Universal
dateCalendar date picker<input type="date">No Safari <14.1
timeHour and minute picker<input type="time">No Safari <14.1
monthMonth and year picker<input type="month">No Firefox/Safari
weekISO week picker<input type="week">No Firefox/Safari
datetime-localCombined date & time picker<input type="datetime-local">No Safari <14.1
checkboxIndependent on/off toggle<input type="checkbox">Universal
radioSingle choice within a group<input type="radio">Universal
colorNative color picker<input type="color">Universal
fileLocal file upload<input type="file">Universal
submitSubmits the enclosing form<input type="submit">Universal
resetResets form to default values<input type="reset">Universal
buttonGeneric, script-driven button<input type="button">Universal
imageGraphical submit button<input type="image">Universal
hiddenInvisible data carried on submit<input type="hidden">Universal
09 · Best Practices

Beyond the type attribute

Choosing the right type is step one — these habits make forms genuinely usable.

Accessibility

Every input needs a linked <label>, a logical tab order, and enough color contrast on borders and focus rings for low-vision users.

Validation

Use native required, pattern and min/max as your first line of defense, then mirror the same rules on the server.

UX

Show inline errors next to the field that caused them, keep placeholder text as a hint rather than a label, and never disable paste on password fields.

Semantic HTML

Reach for the most specific type available before writing custom JavaScript — the browser's built-in behavior is usually more robust than a hand-rolled version.

Mobile Experience

The right type and inputmode summon the correct keyboard automatically — test every field on a real device, not just resized desktop Chrome.

Autocomplete

Set accurate autocomplete values (email, new-password, tel) so browsers and password managers can assist reliably.