Skip to main content
autofocus attribute | autofocus property

Provides a way to direct a user to a specific field when a document loads. This can provide both direction and convenience for a user, reducing the need to click or tab to a field when a page opens. This attribute is true when present on an element, and false when missing.

This property is read/write.

HTML5 A vocabulary and associated APIs for HTML and XHTML, Section Internet Explorer 10



<element autofocus="ptr" ... >


object.autofocus = ptr
ptr = object.autofocus


Property values

Type: boolean

Returns true if the attribute has been set or is present on the element.

Standards information


Only one control in a document can have autofocus specified. If more than one element has the attribute, only the first one in the page will get the focus when the page opens. This is a boolean attribute, requiring only the presence of the attribute to be true.

The following example shows a field that will receive focus when a page opens.

Note  For more code samples, see Form controls part 1 and Form controls part 2: validation on the Windows Internet Explorer sample site.


<input name="email" type="text" placeholder=" " autofocus />

See also