How to specify that the element should automatically get focus when the page loads in HTML?

HTMLWeb DevelopmentFront End Technology

Use the autofocus attribute to specify that the element should get focus automatically on page load in HTML −

Example

You can try to run the following code to learn how to implement autofocus attribute in HTML −

<!DOCTYPE html>
<html>
   <body>
      <p>Click on the below button to generate an alert box.</p>
      <button type = "button" autofocus onclick = "alert('Welcome!')">Result</button>
   </body>
</html>
raja
Published on 13-Mar-2018 16:15:42
Advertisements