Input Types Reference

Complete guide to HTML input types with examples and browser support

HTML Input Types Overview

HTML input types define the type of data that users can enter in form fields. Each input type provides specific validation, formatting, and user interface elements to improve the user experience and data quality.

<!-- Basic input syntax --> <input type="text" name="username" placeholder="Enter username"> <input type="email" name="email" required> <input type="password" name="password" minlength="8">

Benefits of Using Correct Input Types:

  • Automatic validation and error messages
  • Better mobile keyboard layouts
  • Improved accessibility for screen readers
  • Enhanced user experience

Text Input Types

Basic Text Inputs

text
Single-line text input for general text data
<input type="text" name="username" placeholder="Username">
password
Masked text input for sensitive data
<input type="password" name="password" placeholder="Password">
search
Search input with search-specific styling
<input type="search" name="query" placeholder="Search...">
textarea
Multi-line text input for longer content
<textarea name="message" rows="3" placeholder="Your message"></textarea>

Communication Inputs

email
Email input with automatic validation
<input type="email" name="email" placeholder="[email protected]">
tel
Telephone number input
<input type="tel" name="phone" placeholder="+1 (555) 123-4567">
url
URL input with validation
<input type="url" name="website" placeholder="https://example.com">

Number and Date Inputs

Numeric Inputs

number
Numeric input with spinner controls
<input type="number" name="age" min="1" max="120" placeholder="Age">
range
Slider input for selecting from a range
<input type="range" name="volume" min="0" max="100" value="50">

Date & Time Inputs

date
Date picker input
<input type="date" name="birthday">
time
Time picker input
<input type="time" name="appointment">
datetime-local
Date and time picker (local timezone)
<input type="datetime-local" name="meeting">
month
Month and year picker
<input type="month" name="expiry">
week
Week picker input
<input type="week" name="vacation">

Selection and File Inputs

Selection Inputs

checkbox
Multiple selection checkboxes
<input type="checkbox" name="skills" value="html"> HTML


radio
Single selection radio buttons
<input type="radio" name="size" value="small"> Small


select
Dropdown selection menu
<select name="country"><option value="us">United States</option></select>

File & Color Inputs

file
File upload input
<input type="file" name="upload" accept="image/*">
color
Color picker input
<input type="color" name="theme" value="#3b82f6">
hidden
Hidden input for storing data
<input type="hidden" name="csrf_token" value="abc123">
Hidden input (not visible)

Button Types

Note: Button inputs are different from <button> elements. Input buttons are self-closing and have limited styling options.

Button Inputs

submit
Submit button for forms
<input type="submit" value="Submit Form">
reset
Reset button to clear form
<input type="reset" value="Reset Form">
button
Generic button for JavaScript actions
<input type="button" value="Click Me" onclick="alert('Hello!')">
image
Image submit button
<input type="image" src="submit-btn.png" alt="Submit">

Input Attributes and Validation

HTML5 Validation: Modern browsers provide built-in validation for many input types. Use attributes like required, pattern, min, max, and step for enhanced validation.

<!-- Common input attributes --> <input type="email" name="email" required placeholder="Enter your email" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$"> <input type="number" name="age" min="18" max="100" step="1" required> <input type="password" name="password" minlength="8" maxlength="50" required> <input type="text" name="username" autocomplete="username" spellcheck="false">

Common Input Attributes

Essential Attributes

required - Makes the field mandatory

placeholder - Shows hint text

disabled - Disables the input

readonly - Makes input read-only

autocomplete - Controls browser autocomplete

pattern - Regular expression for validation

min/max - Minimum and maximum values

step - Increment step for numeric inputs

accept - File types for file inputs

multiple - Allows multiple selections

Test Your Knowledge

1. Which input type automatically validates email addresses?

text
email
url
tel

2. What input type would you use for selecting a single option from multiple choices?

checkbox
radio
select
button