Placeholder to a Textbox
In HTML, placeholder attribute is used in TextBox or input elements to provide a short hint or example text about the value of the input field.
Placeholder text is displayed in the input box that gives users guidance on what kind of information is expected in the input field.
To add a placeholder to a textbox, you need to define 'placeholder' attribute to an input element.
How to Create a Placeholder Input Box
1. Create an HTML <input>
element.
2. Add type="text"
(type attribute with value 'text') to the <input>
element. Type attribute value is set to 'text' to define the input element as a TextBox input box.
3. Add placeholder="Type your first name"
(placeholder attribute with value 'Type your first name') to the <input>
element. Placeholder attribute value is set to 'Type your first name' to give users guidance on what kind of information is expected in the TextBox input field.
A label <label>First Name:</label>
has been added before the input element.
Have a look at the following example:
Example of DateTime Input Box
Output of the above code example
Example of Placeholder Input Box in a Webpage
As you begin typing, the placeholder text will disappear.