HTML placeholder Attribute
Last Updated :
29 Aug, 2024
HTML 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.
Syntax:
<element placeholder="">
HTML placeholder Attribute Examples
Example 1: HTML <input> placeholder attribute specifies a short hint or example text displayed in an input field before the user enters a value. It helps users understand the expected input format or content.
HTML
<!DOCTYPE html>
<html>
<body>
<h3>
HTML placeholder Attribute Example
</h3>
<!-- HTML placeholder attribute used in input tag -->
<form action=" ">
<label for="First Name">Enter your first name:</label>
<input type="text" name="fname" placeholder="First name">
<br>
<br>
<label for="First Name">Enter your last name:</label>
<input type="text" name="lname" placeholder="Last name">
<br>
<br>
<input type="submit" value="Submit">
</form>
</body>
</html>
Output: In this example, we demonstrate placeholder attributes in input elements. Two text input fields for first and last names. Placeholder text guides user input, improving form usability.

HTML placeholder Attribute Example Output
Example 2: HTML <textarea> placeholder attribute is used to specify the expected value to be displayed before user input in textarea element.
HTML
<!DOCTYPE html>
<html>
<body>
<h3>
HTML placeholder Attribute Example
</h3>
<!-- HTML placeholder attribute used in textarea tag -->
<textarea rows="4" cols="50"
placeholder="Describe yourself here...">
</textarea>
</body>
</html>
Output: In this example we demonstrates placeholder attribute in textarea elements. We have a text area with in which user can write their introduction

HTML Placeholder Attribute with Textarea Example output
HTML placeholder Attribute Related Questions
Here the placeholder attribute is used to define a hint of what value has to be entered on the input and textarea field.
To align we can use text-align property to set the text alignment in the placeholder.
The placeholder attribute and the <label> serve different purposes in providing hints and information for form fields.
Supported Browsers:
HTML placeholder Attribute – FAQs
Does the placeholder attribute disappear on focus?
The placeholder text disappears when the user starts typing or when the field gains focus, depending on the browser.
Can you use the placeholder attribute for required fields?
Yes, you can use the placeholder attribute to provide a hint for required fields, but it does not replace the required attribute, which enforces form validation.
Does the placeholder attribute support multiple lines in <textarea>?
No, the placeholder attribute does not support multiple lines directly; it appears as a single line until the user starts typing.
Does the placeholder attribute affect form submission?
No, the placeholder text is not submitted as part of the form data; it is only a visual hint for the user.
Can the placeholder attribute include HTML tags?
No, the placeholder attribute only supports plain text. HTML tags within the placeholder attribute will be rendered as plain text.