Last Updated : 22 Feb, 2025
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.
ExampleTip: Run this code, without using the autofocus attribute.
HTML
<!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: HTML input autofocus Attribute Supported Browsers
The browser supported by HTML <input>autofocus Attribute are listed below:
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.autofocus
attribute on a page to avoid unexpected behavior.RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4