How to clear the input field

Learn how to clear the input field when it gains focus.

Click the input field to clear its content:

Clear the input field when it gains focus

<!-- Replace the current value of the input field with an empty string when the input field gains focus -->
<input type="text" onfocus="this.value=''" value="Blabla">

Try It Yourself

Use the button to clear the input field

<button onclick="document.getElementById('myInput').value = ''">Clear input field</button>
<input type="text" value="Blabla" id="myInput">

Try It Yourself

Related Pages

Tutorial:HTML Form