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

placeholder

The placeholder attribute shows light hint text inside an empty field — but it is not a substitute for a real <label>, no matter how tempting that shortcut looks.

Syntax

<input type="text" placeholder="e.g. Aman Sharma">

Basic Example

<label for="name">Full Name</label>
<input type="text" id="name" name="name" placeholder="e.g. Aman Sharma">

Browser output: light gray example text sits inside the empty field — the moment the user types anything at all, that hint text disappears completely, with nothing left behind to remind them what the field was for.

How It Works

placeholder is purely a temporary hint — it is never submitted as the field's value, and it is not announced the same reliable way a real <label> is by every screen reader.

Important Attributes

AttributePurpose
placeholderExample/hint text, visible only while the field is empty

Real-World Example

<label for="phone">Phone Number</label>
<input type="tel" id="phone" name="phone" placeholder="e.g. +91 12345 67890">

Used correctly here — a real, always-visible label states what the field is, and the placeholder adds a helpful formatting example on top of it.

Why placeholder Is Not a Label

placeholder<label>
Visible once typing starts?No — disappears entirelyYes — always visible
Reliable screen reader support?Inconsistent — some announce it, some don't, and never as reliably as a real labelYes — the standard, guaranteed mechanism
Expands the clickable target?NoYes

Common Mistakes

  • Using placeholder alone, with no real <label>, as a way to "save space" — this is one of the most common, most damaging form accessibility mistakes on the web
  • Low-contrast placeholder text that's genuinely hard to read for users with low vision
  • Putting critical instructions only in the placeholder, which vanish the instant a user starts typing and can no longer be referenced

Best Practices

  • Always pair placeholder with a real, visible <label> — never use it as a replacement
  • Use placeholder text specifically for a format example, not for essential instructions

Accessibility Considerations

This is a core accessibility topic — a field styled to look clean with only a placeholder and no visible label frequently fails basic accessibility checks and confuses users the moment they start typing and the hint disappears.

SEO Considerations

No direct ranking effect.

Browser & Modern HTML Notes

Default placeholder styling (light gray text) is intentionally low-contrast by browsers to distinguish it from real entered content — a further reason it should never carry information a user genuinely needs to keep referring back to.

Mini Practice

  1. Fix a field that only has a placeholder by adding a real, visible <label>.
  2. Write a good placeholder example (not an instruction) for a "Course Search" field that already has a proper label.

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 →