How To Clear Input Field on Focus

Learn how to clear an input field on focus

Clear Input Field on Focus

Example

<!-- When the input field gets focus, replace its current value with an empty string -->
<input type="text" onfocus="this.value=''" value="Blabla">
Try it Yourself »

Clear Input Field with a Button

Example

<button onclick="document.getElementById('myInput').value = ''">Clear input field</button>
<input type="text" value="Blabla" id="myInput">
Try it Yourself »
Tip: Go to our HTML Form Tutorial to learn more about HTML Forms.