20

Say I have an input box with default text "name" in it. I would like for the user to click the box, the text stays in the box until the user starts to type.

I am not looking for code to clear the input box after focusing it.

Thanks!

Jordan Clifton
  • 321
  • 1
  • 3
  • 10

2 Answers2

51

It's placeholder attribute

<input type="text" placeholder="Type your name">
alexndm
  • 2,899
  • 5
  • 24
  • 25
1

What you are trying to do depends on the version of the browser you are targeting. If the customer uses a browser that support html5 then the answer from @alexndm will work. However if you are targeting a mass audience with number of browser version.

This article here will show how to do it the old way, i.e. using javascript. How do I get placeholder text in firefox and other browsers that don't support the html5 tag option?

Note: the OP of the post I linked also have html5 in case you need it.

Community
  • 1
  • 1
Steven
  • 974
  • 6
  • 18