Open In App

HTML input autofocus Attribute

Last Updated : 22 Feb, 2025
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Share
Report
News Follow

The autofocus attribute in HTML is used to specify that a particular form element (like an input field, textarea, or select dropdown) should automatically receive focus when the page is loaded, allowing the user to start interacting with it immediately without needing to click on it.

Syntax

<input autofocus>

Note: It is a Boolean Attribute means it doesn’t need any value.

Example

Tip: Run this code, without using the autofocus attribute.

<!DOCTYPE html>

<html>
<head>
<title>
   HTML input autofocus Attribute
        </title>
</head>
<body style="text-align:center">
<h1 style="color: green;">
   GeeksforGeeks
        </h1>
<h2> HTML input autofocus Attribute</h2> 
    Name:
        <input autofocus="" type="text"/>
<br/>
<br/>
<!-- Assign id to the Button. -->
<button id="GFG">
   Submit
        </button>
<br/>
</body>
</html>

Output:

Screenshot-from-2023-07-03-18-28-31.png

HTML input autofocus Attribute

Supported Browsers

The browser supported by HTML <input>autofocus Attribute are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari

Important Points About AutoFocus Attribute

  • autofocus is a simple, effective way to improve the user experience by directing the user’s attention to a specific form element immediately upon page load.
  • Only one element should have the autofocus attribute on a page to avoid unexpected behavior.
  • It enhances usability, especially in forms and interactive elements, but should be used with care, especially with accessibility considerations in mind.

Next Article

Similar Reads

three90RightbarBannerImg