What is Placeholder in HTML: Definition and Usage
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.
<!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>
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
placeholderattribute 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.