Home  >  Article  >  Web Front-end  >  How to specify in HTML that an element automatically gets focus when the page loads?

How to specify in HTML that an element automatically gets focus when the page loads?

WBOY
WBOYforward
2023-09-10 22:37:021254browse

How to specify in HTML that an element automatically gets focus when the page loads?

Use the autofocus attribute to specify that an element should automatically gain focus when the page is loaded in HTML -

Example h2>

You can try running the following code to learn how to implement the 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(&#39;Welcome!&#39;)">Result</button>
   </body>
</html>

The above is the detailed content of How to specify in HTML that an element automatically gets focus when the page loads?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete