HTML/CSS Making a textbox with text that is grayed out, and disappears when I click to enter info, how?

Ibn Ali al-Turki picture Ibn Ali al-Turki · Jan 13, 2011 · Viewed 193.6k times · Source

How do I make a textbox that has a grayed out content, and when I click on it to enter text, the grayed out portion, it disappears and allows me to enter the desired text?

Example:

A "First Name" text box. The words "First Name" are inside the text box grayed out, when I click, those words disappear and I write my name in it.

Answer

Psytronic picture Psytronic · Jan 13, 2011

Chrome, Firefox, IE10 and Safari support the html5 placeholder attribute

<input type="text" placeholder="First Name:" />

In order to get a more cross browser solution you'll need to use some javascript, there are plenty of pre-made solutions out there, though I don't know any off the top of my head.

http://www.w3schools.com/tags/att_input_placeholder.asp