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. In most of the browsers, placeholder texts are usually aligned in left. The selector uses text-align property to set the text alignment in the placeholder.
This selector can change browser to browser. For example:
- For Chrome, Mozilla, and Opera Browsers:
::placeholder
- For Internet Explorer:
:-ms-input-placeholder
Example 1: This example describes only placeholder alignment, it does not align placeholder value.
<!DOCTYPE html> <html> <head> <title>Change Placeholder alignment</title> <style> input[type="email"]::placeholder { /* Firefox, Chrome, Opera */ text-align: center; } input[type="text"]::placeholder { /* Firefox, Chrome, Opera */ text-align: right; } input[type="tel"]::placeholder { /* Firefox, Chrome, Opera */ text-align: left; } input[type="email"]:-ms-input-placeholder { /* Internet Explorer 10-11 */ text-align: center; } input[type="email"]::-ms-input-placeholder { /* Microsoft Edge */ text-align: center; } body { text-align:center; } h1 { color:green; } </style> </head> <body> <h1>GeeksforGeeks</h1> <h3>Placeholder Text Alignment</h3> <p>Center Aligned<br><input type="email" placeholder="Email"></p><br> <p>Right Aligned<br><input type="text" placeholder="Name"></p><br> <p>Left Aligned<br><input type="tel" placeholder="Phone Number"></p> </body> </html> |
Output:

Example 2: This example describes the placeholder and placeholder value align.
<!DOCTYPE html> <html> <head> <title>Change Placeholder alignment</title> <style> input[type="email"]{ text-align: center; } input[type="text"] { text-align: right; } input[type="tel"] { text-align: left; } body { text-align:center; } h1 { color:green; } </style> </head> <body> <h1>GeeksforGeeks</h1> <h3>Placeholder Text Alignment</h3> <p>Center Aligned<br><input type="email" placeholder="Email"></p><br> <p>Right Aligned<br><input type="text" placeholder="Name"></p><br> <p>Left Aligned<br><input type="tel" placeholder="Phone Number"></p> </body> </html> |
Output:

Recommended Posts:
- HTML | DOM Input Text placeholder Property
- Difference between align-content and align-items
- How to change the placeholder text using jQuery?
- Differences between HTML <center> Tag and CSS "text-align: center;" Property
- HTML | DOM Input URL placeholder Property
- HTML | placeholder Attribute
- HTML | DOM Textarea placeholder Property
- HTML | DOM Input Email Placeholder Property
- HTML | DOM Input Password placeholder Property
- HTML | DOM Input Number placeholder Property
- HTML | DOM Input Search placeholder Property
- HTML | <textarea> placeholder Attribute
- HTML | <input> placeholder Attribute
- How to set placeholder value for input type date in HTML 5 ?
- CSS | text-align Property
- CSS | text-align-last Property
- How to vertically align text inside a flexbox using CSS?
- How to align button to right side of text box in Bootstrap?
- How to Align <legend> Tag Text to Center ?
- How to Vertically Align Text Next to an Image using CSS ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


