The Wayback Machine - https://web.archive.org/web/20240829163259/https://www.geeksforgeeks.org/html-dom-input-text-placeholder-property/
Open In App

HTML | DOM Input Text placeholder Property

Last Updated : 26 Aug, 2022
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

The Input Text Placeholder property in HTML DOM is used to set or return the value of the placeholder attribute of a text field. The placeholder attribute specifies the short hint that describes the expected value of an input field. The short hint is displayed in the field before the user enters a value.

Syntax: 

  • It returns the Input Text Placeholder property.
textObject.placeholder
  • It is used to set Input Text Placeholder property.
textObject.placeholder = text

Property Value: It contains single value text which is used to define a short hint that describe a expected value of the Text Field.
Return Value: It returns a string value which represented a short hint that describes the expected value of the Text Field.

Example 1: This example illustrates how to return Input Text Placeholder property.  

HTML




<!DOCTYPE html>
<html>
<head>
    <title>
        HTML DOM Input Text Placeholder Property
    </title>
</head>
<body style="text-align:center;">
    <h1>GeeksForGeeks</h1>
    <h2>DOM Input Text placeholder Property</h2>
    <input type="text" id="text_id" placeholder="GeeksForGeeks">
    <br><br>
    <button onclick="myGeeks()">Click Here!</button>
    <p id="GFG" style="font-size:25px;"></p>
 
     
    <!-- script to return the placeholder Property-->
    <script>
        function myGeeks() {
            var txt = document.getElementById("text_id").placeholder;
            document.getElementById("GFG").innerHTML = txt;
        }
    </script>
</body>
</html>


Output: 
Before Clicking the Button: 

After Clicking the Button: 

Example 2: This example illustrate how to set Input Text Placeholder Property. 

HTML




<!DOCTYPE html>
<html>
<head>
    <title>
        HTML DOM Input Text Placeholder Property
    </title>
</head>
<body style="text-align:center;">
    <h1>GeeksForGeeks</h1>
    <h2>DOM Input Text placeholder Property</h2>
    <input type="text" id="text_id" placeholder="GeeksForGeeks">
    <br><br>
    <button onclick="myGeeks()">Click Here!</button>
    <p id="GFG" style="font-size:20px;"></p>
 
     
    <!-- script to set the placeholder Property-->
    <script>
        function myGeeks() {
            var txt = document.getElementById("text_id").placeholder
                    = "HelloGeeks";
                     
            document.getElementById("GFG").innerHTML
                    = "The value of the placeholder attribute "
                      + "was changed to " + txt;
        }
    </script>
</body>
</html>


Output: 
Before Clicking the Button: 

After Clicking the Button: 

Supported Browsers: The browser supported by DOM Input Text placeholder property are listed below: 

  • Google Chrome 1 and above
  • Edge 12 and above
  • Firefox 1 and above
  • Opera
  • Safari 1 and above


Similar Reads

HTML | DOM Input URL placeholder Property
The DOM Input URL placeholder Property is used to set or return the value of the Placeholder attribute of a URL Field.The placeholder attribute specifies a short hint as a text in the input field that describes the expected value. Syntax: It is used to return the placeholder property. urlObject.placeholder It is used to set the placeholder property
2 min read
HTML | DOM Input Email Placeholder Property
The DOM Input Email Placeholder Property is used to set or return the value of a placeholder attribute of an Email Field. The placeholder attribute specifies a short hint that describes the expected value of a input field / textarea. The short hint is displayed in the field before the user enters a value. Syntax: It is used to return the placeholde
2 min read
HTML | DOM Input Password placeholder Property
The DOM Input Password Placeholder Property is used to set or return the value of the Placeholder attribute of a Password Field. The placeholder attribute specifies a short hint that describes the expected value of an input field . The short hint is displayed in the field before the user enters a value. Syntax: It is used to return the placeholder
2 min read
HTML | DOM Input Number placeholder Property
The DOM Input Number placeholder Property in HTML DOM is used to set or return the value of the placeholder attribute of a number field. The placeholder attribute specifies the short hint that describes the expected value of an input field. The short hint is displayed in the field before the user enters a value. Syntax: It returns the Input number
2 min read
HTML | DOM Input Search placeholder Property
The DOM Input Search placeholder Property in HTML DOM is used to set or return the value of the placeholder attribute of a search field. The placeholder attribute specifies the short hint that describes the expected value of an input field. The short hint is displayed in the field before the user enters a value. Syntax: It returns the placeholder p
2 min read
HTML DOM Input Tel placeholder Property
The input tel placeholder property in HTML DOM is used to set or return the value of the placeholder attribute of an input tel field. The placeholder attribute specifies the short hint that describes the expected value of an input field. The short hint is displayed in the field before the user enters a value. Syntax: It returns the input tel placeh
2 min read
How to style Placeholder Text in an Input Field ?
Styling placeholder text in an input field in CSS involves using the ::placeholder pseudo-element. This allows you to apply styles specifically to the placeholder text within the input. Note: The ::placeholder pseudo-element is used to target and style the placeholder text. Syntax:/* Styling placeholder text with a different color */ input::placeho
1 min read
HTML | DOM Textarea placeholder Property
The DOM Textarea placeHolder Property is used to set or return the value of the placeholder attribute of a textarea field. It specifies a short hint that describes the expected value of an input field / textarea. A short message or hint displayed before entering value in textarea. Syntax: It is used to Return the placeholder property. textareaObjec
2 min read
HTML | &lt;input&gt; placeholder Attribute
The &lt;input&gt; placeholder attribute in HTML is used to specify the expected value to be displayed before user input in the input element. Syntax: &lt;input placeholder="text"&gt; Attribute Values: This attribute contains a single value text which specifies a short hint that describes the expected value of the input field. Example: This Example
1 min read
How to set placeholder value for input type date in HTML 5 ?
To set a placeholder value for the input type date in HTML5, use the placeholder attribute. The placeholder attribute doesn't work well with input type "date." Use onfocus="(this.type='date')" for a custom placeholder, enabling a date selection dropdown. Using OnfocusThe On-focus approach changes the input type from text to date when the field gain
2 min read
How to align Placeholder Text in HTML ?
The placeholder attribute specifies a short hint that describes the expected value of an input field/text area. The short hint is displayed in the field before the user enters a value. In most of the browsers, placeholder texts are usually aligned on the left. The selector uses the text-align property to set the text alignment in the placeholder. T
2 min read
HTML | DOM Input Text value Property
The Input Text value property in HTML DOM is used to set or return the value of a value attribute of the input field. The value attribute specifies the initial value of the input Text Field. It contains the default value or the user types. Syntax: It returns the Input Text value property. textObject.valueIt is used to set the Input Text value prope
2 min read
HTML | DOM Input Text size Property
The Input Text size Property in HTML DOM is used to set or return the value of the size attribute of an Input Text Field. The size attribute is used to define the width of a text field. Its default value is 20. Syntax: It returns the Input Text size property.textObject.sizeIt is used to set the Input Text size property.textObject.size = number Prop
2 min read
HTML | DOM Input Text readOnly Property
The Input Text readOnly property in HTML DOM is used to set or return whether a text field should be read-only or not. It means that a user can not modify or changes the content already present in a particular element (However, a user can tab to it, highlight it, and copy the text from it) whereas a JavaScript can be used to change the read-only va
2 min read
HTML | DOM Input Text pattern Property
The Input Text pattern Property in HTML DOM is used to set or return the pattern attribute of an text field. It is used to specify the regular expression on which the input elements value is checked. Use the global title attribute to describe the pattern for helping the user. Syntax: It returns the Input Text pattern property.textObject.patternIt i
2 min read
HTML | DOM Input Text required Property
The Input Text required Property in HTML DOM is used to set or return whether Input Text Field should be filled or not when submitting the form. This property is used to reflect the HTML required attribute. Syntax: It returns the Input text required property.textObject.requiredIt is used to set the Input text required property.textObject.required =
2 min read
HTML DOM Input Text defaultValue Property
The Input Text defaultValue Property in HTML DOM is used to set or return the default value of the Text Field. This property is used to reflect the HTML value attribute. The main difference between the default value and value is that the default value indicate the default value and the value contains the current value after making some changes. Thi
2 min read
HTML | DOM Input Text name Property
The DOM Input Text name Property in HTML DOM is used to set or return the value of name attribute of a Textfield. The name attribute is required for each input field. If the name attribute is not specified in an input field then the data of that field would not be sent at all. Syntax: It returns the Input Text name property.textObject.nameIt is use
2 min read
HTML | DOM Input Text maxLength Property
The DOM Input Text maxLength Property in HTML DOM is used to set or return the value of maxlength attribute of a Text Input Field. It specifies the maximum number of characters that have been allowed in the text field. The default value of Input Text maxLength property is 524288. Syntax: It returns the Input Text maxLength property.textObject.maxLe
2 min read
HTML | DOM Input Text form Property
The DOM Input Text form Property in HTML DOM is used to return the reference of form containing the input Text field. It is a read-only property that returns the form object on success. Syntax: textObject.form Return Values: It returns a string value which specify the reference of the form containing the Input Text field. Example: This example illu
1 min read
HTML | DOM Input Text disabled Property
The DOM Input Text disabled Property is used to set or return the whether the Input Text Field must be disabled or not. A disabled Text Field is un-clickable and unusable. It is a boolean attribute and used to reflect the HTML Disabled attribute. It is usually rendered in grey color by default in all the Browsers.Syntax: It returns the disabled pro
2 min read
HTML | DOM Input Text autofocus Property
The DOM Input Text autofocus Property in HTML DOM is used to set or return whether the Input Text Field should get focus when the page loads. It reflects the HTML autofocus attribute. Syntax: It returns the autofocus property.textObject.autofocusIt is used to set the autofocus property.textObject.autofocus = "true|false" Property Values: true: It s
2 min read
HTML | DOM Input Text autocomplete Property
The DOM Input Text autocomplete Property in HTML DOM is used to set or return the value of the autocomplete attribute of an Input Text field. The autocomplete attribute is used to specify whether the autocomplete attribute has “on” or “off” value. When the autocomplete attribute is set to on the browser will automatically complete the values base o
2 min read
HTML DOM Input Text minLength Property
The HTML DOM Input Text minLength property in HTML DOM is used to set or return the value of the minlength attribute of a Text Input Field. It specifies the minimum number of characters that have been allowed in the text field. The default value of the Input Email minLength property is 524288. Syntax: It returns the Input Text minLength property.te
2 min read
HTML DOM Input Text list Property
The input Text list property in HTML DOM is used to return a reference to the datalist element that contains an input text field. Syntax: textObject.list.id Return Value: It returns a string value that represents the value of the id attribute of the datalist element. Example: Below HTML code used to return the input text list property. C/C++ Code
1 min read
HTML DOM Input Text type Property
The Input Text type Property in HTML DOM is used to return the type of form element of the text field. It always returns the text for an Input text field. Syntax:  textObject.typeReturn Value: It returns a string value that represents the type of form element the input text field is. Below program illustrates the text type property in HTML DOM: Exa
1 min read
Change an HTML5 input placeholder color with CSS
The placeholder selector in the CSS pseudo-element is used to design the placeholder text by changing the text color and it allows to modify the style of the text. In most of the browsers, the placeholder (inside the input tag) is of grey color. In order to change the color of this placeholder, non-standard ::placeholder selectors can be used, whic
2 min read
How to create a Placeholder Input using jQuery Mobile ?
jQuery Mobile is a web based technology used to make responsive content that can be accessed on all smartphones, tablets and desktops. In this article, we will be creating a Placeholder Input using jQuery Mobile. Approach: Add jQuery Mobile scripts needed for your project. &lt;link rel=”stylesheet” href=”http://code.jquery.com/mobile/1.4.5/jquery.m
1 min read
Bulma Input Placeholder
The Bulma placeholder is used to place the asking input from the user i.e. it is the short hint for users that describes the expected value of an input field. For example - if you want to get email Id from the user, then add placeholder to write email id. In input field, we use placeholder using html placeholder attribute. Bulma Placeholder Class:
1 min read
How to change the placeholder text using jQuery?
The placeholder text is the text output for the user what is that input for. Like in HTML, we use Name as an input field and place a text inside that space i.e. Enter your name. Like shown in the below image: Name: So we want a button or some event that will change that placeholder text into some other text. To do that we have 2 methods that are de
3 min read
Article Tags :