Coding Hubs School of AI – Best AI & Full Stack Courses in Delhi NCR | 100% Placement
Limited Offer: Get 50% OFF on AI & Full Stack Courses
📞 Call Now: +91 8448811540
Back to HTML Notes
Topic #704

Input Types

The type attribute is what actually defines an <input>'s behavior — HTML5 defines over 20 values, each with its own native browser UI, keyboard, and validation rules.

Syntax

<input type="value-from-the-table-below" name="...">

The Full Reference

TypeUse forFull details
textGeneral single-line texttext-input
emailEmail addresses, with built-in format validationemail-input
passwordMasked, sensitive textpassword-input
numberNumeric values meant for actual mathnumber-input
dateCalendar datesdate-input
timeClock timestime-input
fileUploading a filefile-input
checkboxIndependent on/off choicescheckbox
radioOne choice from a groupradio-button
hiddenData submitted with the form, never shown or edited by the user—
telPhone numbers — brings up a numeric keypad on mobile, but no strict format validation—
urlWeb addresses, with built-in URL format validation—
searchSearch boxes — may show a native "clear" icon—
colorA native color picker—
rangeA slider between a min and max value—
month / weekA specific month or week, rather than a full date—

Real-World Example

<input type="tel" name="phone" placeholder="+91 12345 67890">
<input type="url" name="portfolio" placeholder="https://yourportfolio.com">
<input type="color" name="brand-color" value="#185FA5">

Three specialized input types in one snippet — each brings a genuinely different native UI and keyboard experience with zero extra JavaScript.

Common Mistakes

  • Defaulting to type="text" for everything, missing out on free built-in validation and better mobile keyboards
  • Using type="number" for values that aren't actually meant for math, like phone numbers or postal codes — see number-input for why

Best Practices

  • Always pick the most specific type available for the actual data being collected
  • Test how each type's native UI looks on both desktop and mobile — they can differ noticeably

Accessibility Considerations

Native input types come with correct roles and keyboard behavior built in for assistive technology — a real advantage over reimplementing the same behavior with plain text inputs and custom JavaScript.

SEO Considerations

No direct ranking effect.

Browser & Modern HTML Notes

Older browsers that don't recognize a specific type (rare today) simply fall back to treating the field as type="text" — a safe, graceful degradation built into the spec.

Mini Practice

  1. Build a form with a tel, a url, and a color input, and compare their native UI on your device.
  2. Identify the correct input type for: a coupon code, a birthdate, and a profile photo upload.

Related HTML Notes

Want to go beyond the notes?

Join Coding Hubs School of AI's HTML course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available
💬 Talk to Advisor
1
WhatsApp

Latest from Our Blog

Insights on AI, Data Science, Full Stack & Career

View All Articles →