HTML <input> Tag

Beginner
7 min read
Updated: Oct 2026
5 examples
Live preview

Definition and Usage

The <input> element creates an interactive form control. Its look and behavior change with type (text, email, password, checkbox, radio, number, file, submit, and more).

Always pair fields with a <label>, give submitted controls a name, and place them inside a <form> when you need form submission. For multi-line text use <textarea>; for option lists use <select>.

Baseline · Widely available.

Core <input> support is stable across browsers since about July 2015. Some newer types and attributes vary by browser.

Obsolete type.

Do not use type="datetime" (UTC date-time). Prefer datetime-local, or separate date / time fields.

HTML Syntax

syntax.html
<input type=" text" name="field" id="field">

<input> is a void element (no end tag, no children). Connect a label with for/id, or wrap the input inside the label.

Attributes

Many attributes exist; these are the ones beginners use most. Exact support depends on type:

AttributeDescriptionTry it
typeControl kind: text (default), email, password, checkbox, radio, number, submit, …Try it
nameForm field name submitted with the valueTry it
valueInitial value (or button label for submit)Try it
placeholderHint shown when empty — not a replacement for a labelTry it
requiredMust have a value before the form can submitTry it
disabled / readonlyDisable interaction, or allow focus but block editsCommon flags
checkedInitial on state for checkbox / radioTry it
min / max / stepNumeric and date/time constraintsTry it
autocompleteAutofill hints (e.g. email, current-password)Try it
listPoints to a <datalist> id for suggestionsSee datalist

Global Attributes

The <input> tag also supports the Global Attributes in HTML (especially id for labels).

Live Preview

Switch common type values and interact with a real control.

Real <input>. Apply a type, then type or click the control.

Control

type="text" — single-line text field (default).

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Text Input with Label

Connect label[for] to input[id] for accessible clicking and focus.

HTML
<label for="username">Username</label>
<input
  type="text"
  id="username"
  name="username"
  placeholder="e.g. mari"
  autocomplete="username"
>
Try It Yourself

How It Works

  1. Give the input an id. Match it with label for="…".
  2. Set type="text" (or omit type — text is the default).
  3. Add name so the value can be submitted with the form.
  4. Use placeholder as a hint only — keep a real visible label.

Example 2 — Email and Password

Specialized types unlock mobile keyboards and basic validation.

HTML
<label for="email">Email</label>
<input type="email" id="email" name="email" autocomplete="email" required>

<label for="pwd">Password</label>
<input
  type="password"
  id="pwd"
  name="password"
  autocomplete="current-password"
  required
>
Try It Yourself

How It Works

  1. type="email" expects an email-shaped value and can show an email keyboard.
  2. type="password" obscures characters as you type.
  3. autocomplete helps browsers and password managers fill fields correctly.
  4. required blocks empty submit until the fields are filled.

Example 3 — Checkbox and Radio

Checkboxes toggle independently; radios share a name for one choice.

HTML
<label>
  <input type="checkbox" name="newsletter" value="yes" checked>
  Subscribe to newsletter
</label>

<p>Plan:</p>
<label>
  <input type="radio" name="plan" value="free" checked> Free
</label>
<label>
  <input type="radio" name="plan" value="pro"> Pro
</label>
Try It Yourself

How It Works

  1. Checkbox: on/off for one option; unchecked boxes are usually omitted from submit.
  2. Radio group: same name, different value — only one can be selected.
  3. checked sets the starting state.
  4. Wrapping in <label> (or using for/id) makes the text clickable.

Example 4 — Number with Constraints

Use min, max, step, and required for numeric fields.

HTML
<label for="qty">Quantity (1–10)</label>
<input
  type="number"
  id="qty"
  name="qty"
  min="1"
  max="10"
  step="1"
  value="1"
  required
>
Try It Yourself

How It Works

  1. type="number" is for numeric values (often with spinner UI).
  2. min / max set the allowed range.
  3. step controls valid increments (here whole numbers).
  4. Browser validation runs on submit when constraints or required fail.

Example 5 — Submit Control

An input type="submit" sends the form. Prefer a <button type="submit"> when you need richer content inside the control.

HTML
<form action="/search" method="get">
  <label for="q">Search</label>
  <input type="search" id="q" name="q">
  <input type="submit" value="Search">
</form>
Try It Yourself

How It Works

  1. Put controls in a <form> with action and method.
  2. type="search" is a text-like field tuned for queries.
  3. type="submit" uses value as the button label.
  4. Avoid type="reset" unless you truly need a wipe-the-form control.

Edge Cases & Pitfalls

Most input bugs come from missing labels, missing name, or the wrong type.

a11y

Placeholder is not a label

Placeholders disappear while typing. Always provide a visible <label>.

submit

No name → not submitted

Fields without name are skipped in normal form encoding (except special button cases).

radio

Shared name for radio groups

Different names create separate groups — users can pick more than one “exclusive” option by mistake.

validation

Client checks are not enough

required, pattern, and type checks help UX — always validate again on the server.

obsolete

Skip type="datetime"

Use datetime-local, date, and/or time instead of the obsolete UTC datetime type.

Browser Support

The <input> element is core HTML everywhere. Basic types are universal; some newer types (week, month, color details) and attributes vary.

✓ Baseline · Widely available

<input>

Widely available since about July 2015 (and much earlier for classic types). Chrome, Firefox, Safari, Edge, and Opera all support form inputs. Check caniuse when you rely on less common types.

98% Core input support (approx.)
Google Chrome All modern
Full support
Mozilla Firefox All modern
Full support
Apple Safari All modern
Full support
Microsoft Edge All modern
Full support
Opera All modern
Full support
Samsung Internet All modern
Full support
Internet Explorer Classic types · limited HTML5
Partial
<input> Widely supported

Bottom line: Safe for everyday forms. Progressive-enhance newer types; always keep usable fallbacks and server-side validation.

Key Takeaways

  • Role: <input> builds single-value form controls; type chooses the widget.
  • Label + name: associate a label, and set name for submission.
  • Void element: no end tag — configure with attributes only.
  • Validate twice: browser constraints help users; servers must still check data.

One line: a good <input> has the right type, a real label, and a name.

Default CSS Settings

Appearance depends heavily on type and the browser’s form controls. A simplified idea for text-like inputs:

default.css
input {
  display: inline-block;
  font: inherit;
  /* widget chrome comes from the user agent */
}

Checkboxes, radios, ranges, and file pickers use different native widgets. Style carefully so focus outlines stay visible for keyboard users.

Frequently Asked Questions

The input element creates a form control so users can enter or choose data — text, email, password, checkboxes, radio buttons, numbers, files, and more — depending on the type attribute.
Yes. input has a start tag only — no end tag and no child content. Configure it with attributes.
If you omit type, the browser uses text — a single-line text field.
Use a label with for matching the input’s id, or wrap the control inside the label. Placeholder is not a substitute for a visible label.
name is the key submitted with the form as a name/value pair. Without name, most controls are not included in form submission.
Usually no. Reset buttons often erase filled forms by accident. Prefer clear, intentional UI for discarding edits.

Next: ins

Mark inserted text in documents and changelogs.

ins tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

14 people found this page helpful