How to clear an input field on focus with CSS?

To clear an input field, first create an input filed. To clear, use the onfocus attribute. Let us see with two examples.

Create an Input Field

First, use the input type to create an input field in a form on a web page ?


Clear the Input Field on Focus

To clear the input field, use the onfocus attribute.


Clear an Input Field on Focus

The following is the code to clear an input field on focus ?




   

Clearing an input field on focus example

Click on the above field to clear its value

Clear Input Fields

Let us see an example with multiple input fields. For all of them, we have used the onfocus attribute ?

Example




   


   
Updated on: 2023-11-16T15:34:07+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements