Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

How to change an HTML5 input's placeholder color with CSS?

Placeholder in a hint for the element, but I want to change the input’s placeholder color. The default color is fine, but isn’t appealing. I would like to change it using jQuery.

The following is my HTML form code:

<form action="/cgi-bin/html5.cgi" method="get">
    Enter email : <input type="email" name="newinput" placeholder="disabled"/>
    <input type="submit" value="submit" />
</form>



1 Answer
Amit D

HTML5 introduced a new attribute called placeholder. This attribute on <input> and <textarea> elements provides a hint to the user of what can be entered in the field.

Here’s an example showing what a placeholder is. The hint to email i.e. [email protected] is placeholder here:

You can try to run the following code to learn how to use placeholder attribute:

<!DOCTYPE HTML>
<html>
   <body>
      <form action="/cgi-bin/html5.cgi" method="get">
         Enter email : <input type="email" name="newinput" placeholder="disabled"/>
         <input type="submit" value="submit" />
      </form>
   </body>  
</html>

Live Demo

To change the input placeholder color, use CSS.

<!DOCTYPE HTML>
<html>
   <style>
      ::-webkit-input-placeholder { /* WebKit, Blink, Edge */
        color:   #7F0D10;
      }
      :-moz-placeholder { /* Mozilla Firefox 4 to 18 */
        color:    #7F0D10;
        opacity:  1;
      }
      ::-moz-placeholder { /* Mozilla Firefox 19+ */
        color:   #7F0D10;
        opacity:  1;
      }
   </style>
   <body>
      <form action="/cgi-bin/html5.cgi" method="get">
         Enter email : <input type="email" name="newinput" placeholder="disabled"/>
         <input type="submit" value="submit" />
      </form>
   </body>
</html>

Live Demo

Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.