Codectionary / Developer documentation / HTML

<input>

The <input> element creates interactive form controls for collecting user data. Its behavior changes dramatically based on the type attribute — a single element can become a text field, checkbox, radio button, date picker, file uploader, and more. It is a void (self-closing) element with no closing tag or child content.

Syntax

<input type="text" name="fieldname" placeholder="Enter value">

Examples

Common Input Types

A few of the most frequently used input types.

<input type="text" placeholder="Name">
<input type="email" placeholder="Email">
<input type="password" placeholder="Password">
<input type="number" placeholder="Age">
<input type="date">

Checkbox and Radio Buttons

Using inputs for multiple-choice selections.

<label><input type="checkbox" name="subscribe" checked> Subscribe to newsletter</label>

<label><input type="radio" name="plan" value="free"> Free</label>
<label><input type="radio" name="plan" value="pro"> Pro</label>

Input Validation Attributes

Using built-in HTML validation without JavaScript.

<input type="email" required placeholder="you@example.com">
<input type="text" minlength="3" maxlength="20" pattern="[A-Za-z]+" placeholder="Letters only">
<input type="number" min="1" max="100" step="1">

Attributes

  • type (string): Determines the input's behavior: text, email, password, number, checkbox, radio, date, file, etc.
  • name (string): Identifies the field when the form data is submitted
  • value (string): The input's current or default value
  • placeholder (string): Hint text shown when the field is empty
  • required (boolean): Marks the field as mandatory for form submission
  • disabled (boolean): Disables the input and excludes it from form submission

Best practices

  • Always pair an <input> with a <label> using matching for and id attributes
  • Use the most specific type available (email, tel, date, number) to get built-in validation and the right mobile keyboard
  • Use the name attribute consistently — it is what actually gets sent to the server, not the id
  • Rely on built-in validation attributes (required, pattern, min, max) before reaching for JavaScript
  • Never use placeholder text as a replacement for a proper label — it disappears once the user starts typing

At a glance

Purpose
Structure and meaning for web content
File extension
.html · .htm
Runs in
Web browsers
Usually used with
CSS and JavaScript

Specifications & further reading

Related HTML documentation