Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change placeholder color on focus?

How to change the color of placeholder when focus the input field? I use this CSS code to set the default color, but how to change it on focus?

::placeholder { color: blue; }
like image 700
Davide Avatar asked Nov 01 '12 18:11

Davide


People also ask

How can I change placeholder color?

<input type="text" placeholder="A red placeholder text..">

How do I change placeholder text in focus?

$('input'). focus(function() { $(this). attr('placeholder', 'enter your email address...') }).

What is the placeholder color?

Note: In most browsers, the appearance of placeholder text is a translucent or light gray color by default.

How do you style a placeholder text?

Use the ::placeholder pseudo-element to style your placeholder text in an <input> or <textarea> form element. Most modern browsers support this, but for older browsers, vendor prefixes will be required.


2 Answers

Try this, this should work :

input::-webkit-input-placeholder {
    color: #999;
}
input:focus::-webkit-input-placeholder {
    color: red;
}

/* Firefox < 19 */
input:-moz-placeholder {
    color: #999;
}
input:focus:-moz-placeholder {
    color: red;
}

/* Firefox > 19 */
input::-moz-placeholder {
    color: #999;
}
input:focus::-moz-placeholder {
    color: red;
}

/* Internet Explorer 10 */
input:-ms-input-placeholder {
    color: #999;
}
input:focus:-ms-input-placeholder {
    color: red;
}

Here is an example : http://jsfiddle.net/XDutj/27/

like image 101
Pranav 웃 Avatar answered Oct 07 '22 23:10

Pranav 웃


This works for me:

input:focus::placeholder {
  color: blue;
}
like image 11
David Villegas Avatar answered Oct 08 '22 00:10

David Villegas