How to add placeholder to a textbox in an HTML page

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.

Live Code Playground

In the following HTML code editor, you can practice the above code by adding more input boxes with placeholder attribute. Click on the 'Run Code' button to render the code; the rendered page will be displayed in the following HTML Code Output frame. Practice until you become comfortable and proficient with your code.

HTML logo HTML Online Editor
HTML Code Output