A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/html/html-input-autofocus-attribute/ below:

HTML input autofocus Attribute - GeeksforGeeks

HTML input autofocus Attribute

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.

Example

Tip: 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:

Important Points About AutoFocus Attribute

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