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 #705

Text Input

<input type="text"> is the default, general-purpose single-line text field — the baseline every other text-like input type builds on.

Syntax

<input type="text" name="fullname" maxlength="100">

Basic Example

<label for="fullname">Full Name</label>
<input type="text" id="fullname" name="fullname" maxlength="100" required>

Browser output: a plain single-line text box; on mobile, it typically brings up the standard alphabetic keyboard.

How It Works

type="text" accepts any character with no built-in format validation at all — unlike email or url, the browser won't reject anything based on shape. Any real validation needs pattern, maxlength/minlength, or server-side checks.

Important Attributes

AttributePurpose
maxlength / minlengthCharacter count limits
patternA regex the value must match — see pattern
placeholderHint text — see placeholder

Real-World Example

<label for="coupon">Coupon Code</label>
<input type="text" id="coupon" name="coupon" maxlength="12" pattern="[A-Z0-9]{4,12}" placeholder="e.g. SAVE20">

A promo code field — plain text, but with a length cap and a pattern restricting it to uppercase letters and digits.

Common Mistakes

  • Using type="text" for data that has a more specific, purpose-built type available (email, phone, URL) — missing free validation and better mobile keyboards
  • Relying only on maxlength for validation when the actual requirement is about content/format, not just length

Best Practices

  • Reserve plain text for genuinely free-form text with no more specific type available
  • Add maxlength where a real limit exists (like a database column size)

Accessibility Considerations

Same as any input — a correctly associated <label> is essential; type="text" carries no special accessibility behavior of its own beyond that baseline.

SEO Considerations

No direct ranking effect.

Browser & Modern HTML Notes

type="text" is also what browsers fall back to for any unrecognized or unsupported type value, making it the safest possible default.

Mini Practice

  1. Build a text input for a username, with a maxlength of 20.
  2. Identify a field currently using type="text" that should really use a more specific type instead.

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 →