Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML input autofocus attribute

HTML autofocus attribute

HTML input Tag Reference HTML tag

Example

Set the "First name" input field to automatically get focus when the page loads:

  First name:

  Last name:

 

Try it »


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 tag.


Definition and Usage

The autofocus attribute is a boolean attribute.

The autofocus attribute specifies that when the page loads, the element should automatically get focus.


Differences between HTML 4.01 and HTML5

The autofocus attribute is new in HTML5.


Differences between HTML and XHTML

In XHTML, attribute minimization is forbidden, and the autofocus attribute must be defined as .


Syntax


HTML input Tag Reference HTML tag