HTML <input> autofocusAttribute

HTML input 标签参考手册HTML <input> Tag

Example

Set the "First name" input field to automatically get 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>

Try it Yourself »

Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

Internet Explorer 10, Firefox, Opera, Chrome, and Safari support the autofocus attribute.

Note:Internet Explorer 9 and earlier versions do not support the autofocus attribute of the <input> tag.


Definition and Usage

The autofocus attribute is a boolean attribute.

The autofocus attribute specifies that the <input> element should automatically get focus when the page loads.


Difference between HTML 4.01 and HTML5

The autofocus attribute is a new attribute in HTML5.


Difference between HTML and XHTML

In XHTML, attribute minimization is forbidden, and the autofocus attribute must be defined as <input autofocus="autofocus" />.


Syntax

<input autofocus>


HTML input 标签参考手册HTML <input> Tag Other Extensions