English العربية Português Japanese

HTML Input Types Reference

The <input> element's type attribute determines the appearance and behavior of the input field. HTML provides 20+ input types covering text, numeric, date, selection, button, and other scenarios.

Text Input Types

Text input types are used to collect various forms of textual information:

HTML
<form>
  <label>Username: <input type="text" name="username" placeholder="Enter username"></label><br>
  <label>Password: <input type="password" name="password" placeholder="At least 6 characters"></label><br>
  <label>Email: <input type="email" name="email" placeholder="you@example.com"></label><br>
  <label>Phone: <input type="tel" name="phone" placeholder="13800138000"></label><br>
  <label>Website: <input type="url" name="website" placeholder="https://"></label><br>
  <label>Search: <input type="search" name="q" placeholder="Search keywords"></label>
</form>
▶ Try It Yourself

Numeric Input Types

Numeric input types let users select or enter numbers and color values:

HTML
<form>
  <label>Quantity (1-10): <input type="number" name="qty" min="1" max="10" value="1"></label><br>
  <label>Volume: <input type="range" name="volume" min="0" max="100" value="50"></label><br>
  <label>Theme Color: <input type="color" name="theme" value="#ff6600"></label>
</form>

<!-- range and number sync (requires JS) -->
<input type="range" id="slider" min="0" max="100" value="50">
<input type="number" id="numDisplay" min="0" max="100" value="50">
<script>
  const slider = document.getElementById('slider');
  const num = document.getElementById('numDisplay');
  slider.addEventListener('input', () => num.value = slider.value);
  num.addEventListener('input', () => slider.value = num.value);
</script>
▶ Try It Yourself

Date and Time Input Types

Date and time input types let users quickly pick dates through a calendar or time picker:

HTML
<form>
  <label>Date: <input type="date" name="date"></label><br>
  <label>Time: <input type="time" name="time"></label><br>
  <label>Date + Time: <input type="datetime-local" name="datetime"></label><br>
  <label>Month: <input type="month" name="month"></label><br>
  <label>Week: <input type="week" name="week"></label>
</form>

Selection Input Types

Selection input types let users pick from multiple options:

HTML
<form>
  <p>Hobbies (multiple selections allowed):</p>
  <label><input type="checkbox" name="hobby" value="reading"> Reading</label>
  <label><input type="checkbox" name="hobby" value="music"> Music</label>
  <label><input type="checkbox" name="hobby" value="sports"> Sports</label>

  <p>Gender (single selection):</p>
  <label><input type="radio" name="gender" value="male"> Male</label>
  <label><input type="radio" name="gender" value="female"> Female</label>

  <p>Upload avatar (images only):</p>
  <input type="file" name="avatar" accept="image/png, image/jpeg, image/gif">
</form>

Button Input Types

Button input types are used to trigger form actions:

HTML
<form action="/submit" method="post">
  <label>Name: <input type="text" name="name"></label><br>

  <!-- Submit button -->
  <input type="submit" value="Submit Form">

  <!-- Reset button -->
  <input type="reset" value="Reset">

  <!-- Generic button -->
  <input type="button" value="Click Me" onclick="alert('Hello!')">

  <!-- Image button -->
  <input type="image" src="btn-submit.png" alt="Submit">
</form>

Hidden and Special Inputs

type="hidden" fields are not displayed on the page but are submitted with the form. They are commonly used for passing metadata such as user IDs and CSRF tokens:

HTML
<form action="/update-profile" method="post">
  <!-- Invisible to users, but submitted with the form -->
  <input type="hidden" name="user_id" value="12345">
  <input type="hidden" name="token" value="abc123xyz">

  <label>Nickname: <input type="text" name="nickname"></label>
  <input type="submit" value="Save">
</form>
💡 Note: Hidden inputs are commonly used to pass user IDs, tokens, and other data that users don't need to see. However, this data is still visible to users (view the source code). Therefore, never use hidden fields to store sensitive information — real security validation should be done server-side.

Complete Input Type Reference Table

Type Description Common Attributes
textSingle-line textplaceholder, maxlength, pattern
passwordPassword (masked display)placeholder, maxlength
emailEmail addressplaceholder, multiple
telTelephone numberplaceholder, pattern
urlURL / web addressplaceholder
searchSearch boxplaceholder
numberNumeric inputmin, max, step
rangeRange slidermin, max, step
colorColor picker
dateDate pickermin, max, step
timeTime pickermin, max, step
datetime-localLocal date + timemin, max
monthMonth pickermin, max
weekWeek pickermin, max
checkboxCheckbox (multi-select)checked
radioRadio buttonchecked
fileFile uploadaccept, multiple
submitSubmit buttonvalue, formaction
resetReset buttonvalue
buttonGeneric buttonvalue, onclick
imageImage buttonsrc, alt
hiddenHidden fieldvalue

📖 Summary

📝 Exercises

  1. Registration Form: Create a "Sign Up" form containing 5+ input types: text (username), email, password, date (birthday), radio (gender), checkbox (hobbies), file (avatar upload), submit, and reset.
  2. Range Sync: Create a range slider and a number input that sync their values in real time. Range: 0–100, step: 5.
100%