How to put a phrase inside a form field and it disappear when clicking inside the field?

5

I would like to know how to put a phrase inside a form field, and it disappears when you click inside the field.

Can it be in CSS? What do you do this for?

    
asked by anonymous 10.12.2015 / 15:49

2 answers

8

There is a property in HTML5 called placeholder that does what you want.

<input type="text" placeholder="Digite seu nome" />
    
10.12.2015 / 15:51
1

You can use the placeholder, as stated, or use js and clear the field whenever you click on it.

<input type="text" id="input" value="Value" onClick="func()"/>
<script>
    var func= function(){
        var elem = document.getElementById("input");
        elem.value = "";
    }
</script>
    
10.12.2015 / 19:14