Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to change the color of the ::placeholder of an <input> element back to its default color

As you can see in the second input field which has no CSS applied to it, the default placeholder color (atleast for me on chrome) is grey. However, when I change the color back to "initial" (which should be its default color) on the first input field, it becomes black. I have also tried to use "unset", but that didnt work either. How can I make the color return to its default color???

.inp1::placeholder {
  color: red;
}
.inp1:hover::placeholder,
.inp1:focus::placeholder {
  color: initial;
}
<input class="inp1" type="text" placeholder="Search">

<input class="inp2" type="text" placeholder="Search">

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This seems to be an issue with Chrome, Firefox behaves properly with keyword initial, you can use keyword revert

.inp1::placeholder {
  color: red;
}
.inp1:hover::placeholder,
.inp1:focus::placeholder {
  color: revert;
}
<input class="inp1" type="text" placeholder="Search">

<input class="inp2" type="text" placeholder="Search">
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading