0

I have your basic input with a placeholder. I have the placeholder text color as a light gray. However, when I click inside the input and type something, the color stays the same. Is there a way I can change the color of the text when something is type and when it is not typed?

<input type="text" placeholder="Your Name">

1 Answer 1

2

Unfortunately there is no native way just yet to do this that covers all the browsers. You can use vendor specific css rules however as seen in this jsfiddle.

::-webkit-input-placeholder {
   color: red;
}

:-moz-placeholder { /* Firefox 18- */
   color: red;  
}

::-moz-placeholder {  /* Firefox 19+ */
   color: red;  
}

:-ms-input-placeholder {  
   color: red;  
}
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the input. Appreciate it. Would jQuery be the best solution?
It depends on how important supporting old versions of Firefox and IE are. If it's important, then yeah you could use a modernizer class and a small jQuery function to fake one with your own styles. Use any of the solutions on google - it seems everyone and their dog has made a jQuery placeholder plugin. If you're only supporting latest versions of browsers, then vendor specific css rules like the above is fine.
Great! Thanks for taking time out to help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.