The placeholder attribute
The placeholder attribute specifies a hint in the HTML input field of a form.
This hint is needed to indicate to the user what exactly should be entered in this field. The hint itself will be located in the input field, but, unlike the attribute value, it will disappear automatically when trying to enter text.
Applies to tags input, textarea.
You can apply CSS styles to the placeholder tooltip using the placeholder pseudo-element.
Example
Let's set the input field to have a hint of placeholder:
<input type="text" placeholder="enter name">
:
Example . The value attribute is the same as placeholder
And here let's set both the placeholder hint and the value attribute for the input field. If you delete the contents of the value attribute, you'll see the hint hidden underneath it:
<input type="text" placeholder="enter name" value="Ivan">
:
See also
-
attribute
value,
which sets the default value for the input field -
pseudo-element
placeholder,
which sets styles for the tooltip -
pseudo-class
placeholder-shown,
which sets styles for the input field with a hint