HTML placeholder Attribute

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 3 Examples
Forms & Validation

Introduction

The placeholder attribute shows hint text inside an empty <input> or <textarea>. It gives users a short example or format cue — like “Enter your username” or 555-123-4567 — and disappears when they type. It is not a label: always pair placeholders with a real <label>. Placeholder text is not submitted with the form (unlike value). Use it with pattern for format examples, and set element.placeholder in JavaScript when hints change dynamically.

What You’ll Learn

01

Hint text

Empty field.

02

input

Text fields.

03

textarea

Multi-line.

04

Not label

Use both.

05

.placeholder

JS property.

06

vs value

Not submitted.

Purpose of placeholder Attribute

The primary purpose of placeholder is to improve form usability with a visual hint about what to enter or how to format input. A phone field might show 555-123-4567; a search box might show Search products….

Placeholders supplement labels — they do not replace them. Once the user starts typing, the hint vanishes, so critical field names must live in an associated <label>. For validation rules, use pattern, minlength, or helper text outside the field.

💡
Placeholder is not form data

Only value (what the user entered) is submitted. Placeholder text never appears in the POST body — it is display-only.

📝 Syntax

Add placeholder with a string hint on input or textarea:

placeholder.html
<label for="username">Username:</label>
<input
  type="text"
  id="username"
  name="username"
  placeholder="Enter your username">

<label for="bio">Bio:</label>
<textarea id="bio" placeholder="Tell us about yourself…"></textarea>

Syntax Rules

  • Value is a plain text string shown when the field is empty.
  • Valid on input (most text-entry types) and textarea.
  • Not valid on select, button, checkbox, or radio.
  • Disappears when the user types; reappears if the field is cleared.
  • Always include a <label for="…"> — do not use placeholder as the only label.
  • JavaScript: input.placeholder = "New hint".
  • Pair with pattern when showing an example format (placeholder = hint, pattern = rule).

💎 Values

The placeholder attribute accepts any text string:

  • placeholder="Enter your username" — Descriptive hint.
  • placeholder="555-123-4567" — Format example for phone.
  • placeholder="Search…" — Search box cue.
  • placeholder="Describe your issue…" — Multi-line textarea hint.
placeholder-examples.html
<input type="email" placeholder="you@example.com">
<input type="search" placeholder="Search docs…">
<textarea placeholder="Your message here"></textarea>

⚡ Quick Reference

ConceptBehaviorSubmitted?
placeholderHint when emptyNo
valueActual field contentYes
<label>Accessible field nameN/A
input.placeholderJS read/write hintN/A
With patternHint + validation rulepattern validates value
textareaMulti-line hintsNo (hint only)

Applicable Elements

Element / typeSupported?Notes
<input type="text">YesMost common
email, password, tel, url, searchYesText-entry types
number, date, timeYesBrowser-dependent display
<textarea>YesMulti-line hints
checkbox, radio, fileNoNot applicable
<select>, <button>NoUse first option or button text

placeholder vs label vs value

Attribute / elementPurposeWhen visible
placeholderHint / exampleOnly when field is empty
<label>Field name (required for a11y)Always visible
valuePre-filled or user dataWhile field has content
patternValidation regexNot visible (rule only)

Examples Gallery

Login form hints, dynamic placeholder in JavaScript, and textarea placeholder text.

👀 Live Preview

Username field with placeholder — type to see the hint disappear:

The label stays visible; placeholder is only a hint inside the empty field.

Example — Login form with placeholders

Hints on username and password fields with proper labels:

login-placeholder.html
<form>
  <label for="username">Username:</label>
  <input type="text" id="username" name="username"
    placeholder="Enter your username">

  <label for="password">Password:</label>
  <input type="password" id="password" name="password"
    placeholder="Enter your password">

  <button type="submit">Submit</button>
</form>
Try It Yourself

How It Works

Placeholders show inside empty fields. Labels remain visible for accessibility. Only typed values are submitted — not the placeholder text.

Dynamic Values with JavaScript

Change the hint when context changes:

dynamic-placeholder.html
<input type="text" id="dynamicField">

<script>
  document.getElementById("dynamicField").placeholder = "Search by product name…";
</script>
Try It Yourself

How It Works

The placeholder IDL property accepts a string. Updating it changes the hint immediately without affecting value.

Example — Textarea placeholder

Multi-line hint for a message or feedback field:

textarea-placeholder.html
<label for="message">Your message:</label>
<textarea
  id="message"
  name="message"
  rows="4"
  placeholder="Describe your issue in detail…"></textarea>
Try It Yourself

How It Works

textarea uses the same placeholder attribute. Keep the <label> for the field name; use placeholder for an optional example of what to write.

♿ Accessibility

  • Never replace labels — Placeholder is not exposed as the field name to assistive tech the way a <label> is.
  • Low contrast risk — Placeholder text is often light gray; do not put essential instructions only in placeholder.
  • Disappears on input — Users may forget the hint after typing; repeat important format rules outside the field.
  • Associate labels — Use for / id on every input and textarea.
  • Do not pre-fill with placeholder — Use value for real default data, not placeholder.

🧠 How placeholder Works

1

Field is empty

No value yet.

Empty
2

Hint displayed

placeholder text.

Cue
3

User types

Hint hides.

value
=

Better UX

With real labels.

Browser Support

The placeholder attribute on input and textarea is supported in all modern browsers.

HTML5 Forms · Fully supported

Universal placeholder support

Hint text works on inputs and textareas in every major browser.

99% Browser support
Google Chrome Fully supported
Full support
Mozilla Firefox Fully supported
Full support
Apple Safari Fully supported
Full support
Microsoft Edge Fully supported
Full support
Internet Explorer IE 10+ supported
Full support
Opera Fully supported
Full support
placeholder attribute 99% supported

Bottom line: Safe for form hints on input and textarea in all modern browsers.

💡 Best Practices

✅ Do

  • Always pair placeholder with a visible <label>
  • Use short, helpful examples (email, phone format)
  • Combine with pattern when showing format examples
  • Update input.placeholder when context changes in JS
  • Keep placeholder text concise

❌ Don’t

  • Use placeholder as the only field label
  • Put critical instructions only in placeholder
  • Confuse placeholder with value
  • Use placeholder on select or button
  • Rely on placeholder for validation (use pattern, required)

Conclusion

The placeholder attribute shows hint text in empty input and textarea fields — a simple way to guide users without replacing proper labels.

Keep labels visible, use placeholders for short examples, and remember that only value is submitted with the form.

Key Takeaways

Knowledge Unlocked

Five truths every developer should know about placeholder

Bookmark these before building forms.

5
Core concepts
📝 02

input + textarea

Supported.

Scope
🏷️ 03

Need label

Always.

A11y
04

.placeholder

JS update.

API
05

Not value

Not submitted.

Gotcha

❓ Frequently Asked Questions

It displays hint text inside an empty input or textarea. The hint disappears when the user types. It is not submitted with the form.
No. Always use a <label>. Placeholder text vanishes on input and is not a reliable accessible name for the field.
value is real data (pre-filled or typed) that gets submitted. placeholder is temporary hint text shown only when the field is empty.
Yes. textarea uses the same placeholder attribute as input for multi-line hints.
element.placeholder = "New hint text" on the input or textarea element.
Yes on input and textarea in all modern browsers (IE 10+).

Improve form usability

Practice the placeholder attribute on login forms, dynamic hints, and textareas in the Try It editor.

Try placeholder demo →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful