What is a placeholder attribute in HTML?

In this shot, we will learn about the placeholder attribute in HTML.

A placeholder attribute is used to hint to the user what to enter in the input field.

It can be used in search boxes on web pages. It gives suggestions like “try binary trees” or “search for courses”, etc. to the user to enter.

We can use the placeholder attribute in many scenarios like “Enter email”, “Enter mobile number”, etc.

Syntax

<input placeholder="text">

The text will be displayed to the user until they enter data into the search box.

Example

In the following example, we use an input element to take input from the user. We give the user hints about what to search in the search box by providing the placeholder “Try binary trees”.

Example of placeholder attribute
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources