How to create a label inside an <input> element?

collimarco picture collimarco · Apr 23, 2009 · Viewed 191.8k times · Source

I would like to insert a descriptive text inside an input element that disappers when the user click on it.

I know it is a very common trick, but I do not know how to do that..

What is the simplest/better solution?

Answer

Rich Bradshaw picture Rich Bradshaw · Mar 18, 2010

If you're using HTML5, you can use the placeholder attribute.

<input type="text" name="user" placeholder="Username">