Skip to content

HTML Input Types Tutorial for Beginners

HTML input types control what kind of data users can enter in a form. In this lesson, you will learn common HTML input types, HTML5 input types, mobile-friendly inputs, validation attributes, accessibility tips, and best practices for building user-friendly forms.

What Are HTML Input Types?

HTML input types are values of the type attribute used with the <input> element. They tell the browser what kind of data the user should enter, such as text, email, password, number, date, file, or color.

<input type="text" name="username" />
<input type="email" name="email" />
<input type="password" name="password" />

HTML Input Types Cheatsheet

The following table shows the most commonly used HTML input types beginners should know.

Input Type Example Purpose
text <input type="text" name="username" /> Collects single-line text.
email <input type="email" name="email" /> Collects email addresses with basic validation.
password <input type="password" name="password" /> Hides typed characters.
number <input type="number" name="age" /> Collects numeric values.
tel <input type="tel" name="phone" /> Collects phone numbers.
url <input type="url" name="website" /> Collects website URLs.
search <input type="search" name="query" /> Creates search fields.
date <input type="date" name="dob" /> Provides a date picker.
file <input type="file" name="resume" /> Uploads files.
checkbox <input type="checkbox" name="agree" /> Allows true or false selection.
radio <input type="radio" name="level" value="beginner" /> Selects one option from a group.
range <input type="range" min="0" max="100" /> Creates a slider control.
color <input type="color" name="themeColor" /> Opens a color picker.
hidden <input type="hidden" name="userId" value="101" /> Stores hidden form data.
submit <input type="submit" value="Submit" /> Submits the form.

Basic HTML Input Example

The <input> element is usually combined with a <label> for better accessibility and usability.

<form action="/signup" method="post">
  <label for="username">Username</label>
  <input id="username" name="username" type="text" required />

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

  <button type="submit">Create Account</button>
</form>

Text, Email, and Password Inputs

These are the most common input types used in login, registration, and contact forms.

<input type="text" name="fullName" placeholder="Enter your name" />

<input type="email" name="email" placeholder="name@example.com" required />

<input type="password" name="password" minlength="8" required />

Number, Date, and Time Inputs

HTML5 added useful input types for numbers, dates, times, months, and weeks.

<input type="number" name="age" min="1" max="120" />

<input type="date" name="birthday" />

<input type="time" name="meetingTime" />

<input type="datetime-local" name="appointment" />

<input type="month" name="billingMonth" />

<input type="week" name="courseWeek" />

Checkbox and Radio Inputs

Use checkboxes when users can select multiple options. Use radio buttons when users must choose only one option from a group.

Checkbox Example

<label>
  <input type="checkbox" name="skills" value="html" />
  HTML
</label>

<label>
  <input type="checkbox" name="skills" value="css" />
  CSS
</label>

Radio Example

<fieldset>
  <legend>Choose your experience level</legend>

  <label>
    <input type="radio" name="level" value="beginner" />
    Beginner
  </label>

  <label>
    <input type="radio" name="level" value="advanced" />
    Advanced
  </label>
</fieldset>

File, Color, and Range Inputs

These input types provide native browser controls for file uploads, color selection, and slider-style values.

<input type="file" name="profilePhoto" accept="image/*" />

<input type="color" name="brandColor" value="#0d6efd" />

<input type="range" name="volume" min="0" max="100" value="50" />

Mobile-Friendly HTML Input Types

Choosing the correct input type improves mobile form usability because mobile browsers show a keyboard that matches the expected data.

Use Case Recommended Input Mobile Benefit
Email address <input type="email" autocomplete="email" /> Shows email-friendly keyboard with @.
Phone number <input type="tel" autocomplete="tel" /> Shows phone keypad.
Website URL <input type="url" autocomplete="url" /> Shows URL-friendly keyboard.
Search box <input type="search" name="q" /> Shows search keyboard and search behavior.
Numeric code <input inputmode="numeric" pattern="[0-9]{6}" /> Shows numeric keyboard for OTP or PIN.
Decimal amount <input inputmode="decimal" name="price" /> Shows decimal-friendly keyboard.
Date selection <input type="date" name="dob" /> Shows native date picker.
Time selection <input type="time" name="time" /> Shows native time picker.

Input Validation Attributes

Validation attributes help browsers check user input before submitting a form.

<input
  type="text"
  name="username"
  minlength="3"
  maxlength="20"
  pattern="[A-Za-z0-9_]{3,20}"
  required
/>

<input
  type="number"
  name="quantity"
  min="1"
  max="10"
/>
  • required: makes a field mandatory.
  • minlength and maxlength: control text length.
  • min and max: control numeric or date range.
  • pattern: validates text using a regular expression.
  • step: controls number increments.

Autocomplete and Inputmode

The autocomplete attribute helps browsers fill known user data. The inputmode attribute improves mobile keyboard behavior.

<input
  type="email"
  name="email"
  autocomplete="email"
/>

<input
  type="text"
  name="otp"
  inputmode="numeric"
  pattern="[0-9]{6}"
  autocomplete="one-time-code"
/>

Accessible HTML Inputs

Accessible input fields help users with screen readers, keyboards, and assistive tools. Always connect labels to inputs when possible.

<label for="firstName">First Name</label>
<input id="firstName" name="firstName" type="text" autocomplete="given-name" />
  • Use <label> with matching for and id.
  • Use <fieldset> and <legend> for radio and checkbox groups.
  • Use helpful error messages near invalid fields.
  • Do not rely only on placeholder text as the field label.
  • Use correct input types to improve browser and assistive technology support.

SEO-Friendly and User-Friendly Input Forms

Input fields do not directly rank a page, but clean and user-friendly forms improve page quality, accessibility, conversions, and overall user experience.

  • Use clear labels and helpful instructions.
  • Keep forms short and easy to complete.
  • Use the right input type for each field.
  • Use mobile-friendly input types for better usability.
  • Avoid hiding important content behind a form.
  • Use descriptive button text such as Create Account or Send Message.

Common HTML Input Type Mistakes

  • Using type="text" for every field.
  • Using placeholder text instead of labels.
  • Missing name attributes on inputs.
  • Using number for phone numbers instead of tel.
  • Forgetting mobile-friendly input types.
  • Using pattern validation without helpful instructions.
  • Relying only on client-side validation for sensitive data.

Key Takeaways

  • HTML input types define what kind of data users can enter.
  • Common input types include text, email, password, number, date, and file.
  • Use email, tel, url, search, and inputmode for better mobile forms.
  • Use validation attributes like required, pattern, minlength, and maxlength.
  • Always connect labels to inputs for better accessibility.
  • Good input choices improve usability, mobile experience, accessibility, and conversions.

Pro Tip

For mobile-friendly forms, use type="email" for emails, type="tel" for phone numbers, and inputmode="numeric" for OTP or PIN fields.