HTML DOM Input Text placeholder property

The HTML DOM Input Text placeholder property is used for setting or returning the placeholder attribute value of an input text field. The placeholder property is used for giving the web page users a hint about the input element by showing a text inside the input field before the user inputs anything. The placeholder text is greyed by default and isn’t submitted to the form unlike the value property.


Following is the syntax for −

Setting the placeholder property −

textObject.placeholder = text

Here, text represents the placeholder text specifying the hint for the user about the text field.


Let us look at an example for the input Text placeholder property −

<!DOCTYPE html>
<h1>Input Text placeholder property</h1>
USERNAME: <input type="text" id="USR" placeholder="....">
<p>Change the placeholder text of the above field by clicking the below button</p>
<button onclick="changeHolder()">CHANGE</button>
   function changeHolder() {
      document.getElementById("USR").placeholder = "Enter your username here..";


This will produce the following output −

Placeholder changed successfully −