0
0
HtmlConceptBeginner · 3 min read

What is Placeholder in HTML: Definition and Usage

In HTML, the placeholder attribute provides a short hint inside an input field that describes the expected value. This hint disappears when the user starts typing, helping users understand what to enter without extra labels.
⚙️

How It Works

The placeholder attribute works like a light note inside a text box. Imagine you have a form asking for your email. Instead of just an empty box, the placeholder shows a faint example like "you@example.com". This helps users know what kind of information to type.

When you click or tap inside the input box, the placeholder text disappears so you can type your own answer. It’s like a sticky note that vanishes when you start writing. This makes forms easier and faster to fill out.

💻

Example

This example shows a simple text input with a placeholder that tells the user to enter their name.

html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Placeholder Example</title>
</head>
<body>
  <form>
    <label for="name">Name:</label>
    <input type="text" id="name" name="name" placeholder="Enter your full name">
  </form>
</body>
</html>
Output
A web page with a form showing a label 'Name:' and a text box containing faint text 'Enter your full name' that disappears when typing starts.
🎯

When to Use

Use the placeholder attribute when you want to give users a quick hint about what to type in a form field without cluttering the page with extra text. It’s great for simple instructions like examples of email, phone number, or date format.

However, placeholders should not replace labels because they disappear once typing starts. Always keep labels visible for accessibility and clarity. Placeholders are best for short, helpful hints that improve user experience.

Key Points

  • The placeholder attribute shows a hint inside input fields.
  • The hint disappears when the user types.
  • It helps users understand what to enter quickly.
  • Always use labels along with placeholders for clarity and accessibility.
  • Best for short examples or format hints in forms.

Key Takeaways

The placeholder attribute shows a short hint inside input fields to guide users.
Placeholder text disappears when the user starts typing in the field.
Always pair placeholders with visible labels for better accessibility.
Use placeholders for simple examples or format hints, not full instructions.