Attribute – Autofocus Attribute


Autofocus Attribute | HTML5

The autofocus attribute is a boolean attribute.

When present, it specifies that the element should automatically get input focus when the page loads.

Only one form element in a document can have the autofocus attribute. It cannot be applied to <input type="hidden">.

Applies to

ElementAttribute
<button>autofocus
<input>autofocus
<select>autofocus
<textarea>autofocus

Example

<form> <input type="text" name="fname" autofocus> <input type="text" name="lname"> </form>

Compatibility

This is an HTML5 attribute.

More Information:

HTML autofocus Attribute on w3schools.com

<input> autofocus attribute on MDN web docs

This article needs improvement. You can help improve this article. You can also write similar articles and help the community.