autofocus is a boolean attribute and it makes sure that an element will get focus automatically as soon as page loads, unless the user overrides it.
This attribute can only be defined by one form-associated component in a document. If there are multiple elements with
autofocus attribute, the initial focus will be given to the first element with the set of attributes inserted, usually the first such element on the page.
You can use this attribute on
Setting this property doesn’t set the focus to the associated element: it merely tells the browser to focus on it when the element is inserted in the document. Setting it after the insertion, which is most of the time after the document load, has no visible effect.
<button type="button" autofocus>Click Me!</button> <input type="text" name="name" autofocus> <textarea autofocus> the textarea autofocus example. </textarea> <select autofocus> <option value="value1">Value 1</option> <option value="value2">Value 2</option> </select>