freeCodeCamp/guide/english/html/attributes/autofocus-attribute/index.md

919 B

title
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

Element Attribute
<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