How do I auto-hide placeholder text upon focus using css or jquery?

LondonGuy picture LondonGuy · Mar 14, 2012 · Viewed 298.6k times · Source

This is done automatically for every browser except Chrome.

I'm guessing I have to specifically target Chrome.

Any solutions?

If not with CSS, then with jQuery?

Kind regards.

Answer

Rob Fletcher picture Rob Fletcher · Sep 3, 2012

Edit: All browsers support now

input:focus::placeholder {
  color: transparent;
}
<input type="text" placeholder="Type something here!">

Firefox 15 and IE 10+ also supports this now. To expand on Casey Chu's CSS solution:

input:focus::-webkit-input-placeholder { color:transparent; }
input:focus:-moz-placeholder { color:transparent; } /* FF 4-18 */
input:focus::-moz-placeholder { color:transparent; } /* FF 19+ */
input:focus:-ms-input-placeholder { color:transparent; } /* IE 10+ */