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.
<element autofocus="ptr" ... >
object.autofocus = ptr ptr = object.autofocus
Returns true if the attribute has been set or is present on the element.
- HTML5 A vocabulary and associated APIs for HTML and XHTML, Section 18.104.22.168
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.