HTML input autofocus attribute
Examples
Setting "First name" input field automatically get the focus when the page loads:
<form action="demo_form.html">
First name: <input type="text" name="fname" autofocus><br>
Last name: <input type="text" name="lname"><br>
<input type="submit">
</form>
First name: <input type="text" name="fname" autofocus><br>
Last name: <input type="text" name="lname"><br>
<input type="submit">
</form>
try it"
Browser Support
Internet Explorer 10, Firefox, Opera, Chrome and Safari support autofocus attribute.
Note: 9 and earlier versions of Internet Explorer do not support autofocus attribute <input> tag.
Definition and Usage
autofocus attribute is a Boolean attribute.
Autofocus attribute specifies when the page loads <input> element should automatically get focus.
Differences between HTML 4.01 and HTML5
autofocus attribute is new in HTML5 attributes.
Differences between HTML and XHTML
In XHTML, prohibit attribute minimization, autofocus attribute must be defined as <input autofocus = "autofocus" />.
grammar
<input autofocus>
HTML <input> tag