The Wayback Machine - https://web.archive.org/web/20240926160051/https://www.geeksforgeeks.org/html-placeholder-attribute/
Open In App

HTML placeholder Attribute

Last Updated : 29 Aug, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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

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-textarea

HTML Placeholder Attribute with Textarea Example output

HTML placeholder Attribute Related Questions

1. How to use placeholder attribute in HTML ?

Here the placeholder attribute is used to define a hint of what value has to be entered on the input and textarea field.

2. How to align Placeholder Text in HTML ?

To align we can use text-align property to set the text alignment in the placeholder.

3. When to use the placeholder attribute and the label Element ?

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.



Previous Article
Next Article

Similar Reads

HTML | <textarea> placeholder Attribute
The <textarea> placeholder attribute in HTML is used to specify the expected value to be displayed before user input in textarea element. Syntax: <textarea placeholder="text"> Attribute Value: This attribute contains single value text which is the initial string to be displayed before user input. Example 1: This example uses <textare
2 min read
HTML | <input> placeholder Attribute
The <input> placeholder attribute in HTML is used to specify the expected value to be displayed before user input in the input element. Syntax: <input placeholder="text"> 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 use placeholder attribute in HTML ?
We know that the placeholder attribute is used to define a hint of what value has to be entered on the input and textarea field. This attribute is used for a better understanding of form structure. It contains a string value that represents the short hint that describes the expected value of an input field/text area. The short hint is displayed in
1 min read
When to use the placeholder attribute and the label Element ?
The placeholder attribute and the <label> serve different purposes in providing hints and information for form fields. placeholder Attribute:Input Format Guidance: Use placeholder to provide a brief example or format hint inside text, email, or password fields. Helpful for indicating the expected input without cluttering the form.Non-essentia
1 min read
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 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 | 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 Text placeholder Property
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 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
Placeholder vs Value Attributes in HTML
Placeholder Attribute:The placeholder attribute specifies a short hint that describes the expected value of an input field/textarea. The short hint is revealed in the field before the user enters a value. It is just a temporary hint and has nothing to do with logical executions in the backend. Syntax: <input placeholder = "text"> <textarea
3 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 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
How to set Placeholder Value for Input Type Date in HTML?
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 href attribute is different from src attribute in HTML ?
In HTML5, the href and src attributes play distinct roles in defining paths or URLs, each associated with specific HTML elements. The href attribute, commonly found in an anchor (<a>) elements, points to the destination of hyperlinks, facilitating navigation. The src attribute, used with elements like <img> and <script>, specifies
1 min read
React Suite DatePicker Usage Placeholder
React Suite is a front-end UI library built on top of React that lets us many pre-built components to our react application. It is a developer-friendly library and is a great base for building scalable and beautiful websites and applications. In this article, we will be seeing React Suite DatePicker Usage Placeholder. The DatePicker component is us
3 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 make a placeholder for a 'select' box?
There is no placeholder attribute in 'select' tag but it can make the placeholder for a 'select' box. There are many ways to create the placeholder for a 'select' box. Example 1: C/C++ Code <!DOCTYPE html> <html> <head> <title>make placeholder</title> <style> body { border:black; justify-content: center; text-ali
1 min read
SASS | Placeholder Selectors
Placeholder is another special kind of selector. It is used when you are writing your own SASS library. Its work is very similar to mixin without arguments. Placeholder selector starts with a % sign. Syntax: %( name_of_selector ) { property: value; ... } Placeholder selectors are excluded in the compilation of the SASS file ( This defines the main
2 min read
React Suite Placeholder Component
React Suite is a popular front-end library with a set of React components that are designed for the middle platform and back-end products. Placeholder component allows the user to display the initial state before the component loaded. We can use the following approach in ReactJS to use the React Suite Placeholder Component. Placeholder.Paragraph Pr
3 min read
Semantic-UI | Placeholder
Semantic UI is an open-source framework that uses CSS and jQuery to build great user interfaces. It is the same as a bootstrap for use and has great different elements to use to make your website look more amazing. It uses a class to add CSS to the elements. A placeholder is used to reserve space for content that soon will appear in a layout. Below
3 min read
CSS :placeholder-shown Selector
The CSS :placeholder-shown pseudo-class selects the input element or textarea element that is having placeholder text. The main difference between :placeholder-shown and ::placeholder is that :placeholder-shown is for selecting the input itself when the placeholder text is being shown whereas ::placeholder is about giving style to the placeholder t
1 min read
How to create a mixin for placeholder in SASS ?
Mixin is one of the best features of SASS, which works like a function. You can create mixins for repeated CSS properties and then include those mixins using @include in your CSS class. Approach: We create a mixin, we are using @content which let us inject the whole CSS code block inside the mixin, that block replaces @content inside mixin. We use
2 min read
How to set an image placeholder for amp-anim in Google AMP ?
If you want to embed an animation on your AMP webpage then you can do so with this tag. It helps the developer to embed animations, gif, webp, etc in your web platform. It is really a very useful tag as having animation on your website really make it tacky and good-looking. Setup: To use amp-anim in your AMP webpage, you have to import this script.
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. <link rel=”stylesheet” href=”http://code.jquery.com/mobile/1.4.5/jquery.m
1 min read
Vue.js Placeholder using filters
Vue.JS filters are a functionality provided by Vue components that let you apply formatting and transformations to any part of your template dynamic data. The filter property of the component is an object. A single filter is a function that accepts a value and returns another value. The returned value is the one that’s actually printed in the Vue.j
3 min read
How to make only placeholder italics in tailwind CSS ?
Frankly speaking, there is no build-in method to make placeholder italic in Tailwind CSS. So you have to customize your utilities class and that is the main perks of Tailwind CSS that separates it from other CSS Framework like bootstrap, foundation etc. Tailwind provides sets of utility classes out of the box, but many times you run into a situatio
3 min read
ReactJS Semantic UI Placeholder Element
Semantic UI is a modern framework used in developing seamless designs for the website. It gives the user a lightweight experience with its components. It uses the predefined CSS, JQuery language to incorporate in different frameworks. In this article we will know how to use Placeholder element in ReactJS Semantic UI. Placeholder element is used to
2 min read
jQWidgets jqxComboBox placeHolder Property
jQWidgets is a JavaScript framework for making web-based applications for PC and mobile devices. It is a very powerful and optimized framework, platform-independent, and widely supported. The jqxComboBox is used to represent a jQuery combobox widget that contains an input field with auto-complete functionality and a list of selectable items display
2 min read