HTMLElement: autofocus property

The autofocus property of the HTMLElement interface represents a boolean value reflecting the autofocus HTML global attribute, which indicates whether the control should be focused when the page loads, or when dialog or popover become shown if specified in an element inside <dialog> elements or elements whose popover attribute is set.

Only one form-associated element inside a document, or a <dialog> element, or an element whose popover attribute is set, can have this attribute specified. If there are several, the first element with the attribute set inserted, usually the first such element on the page, gets the initial focus.

Note: Setting this property doesn't set the focus to the associated element: it merely tells the browser to focus to it when the element is inserted in the document. Setting it after the insertion, that is most of the time after the document load, has no visible effect.

Value

A boolean value.

Specifications

Specification
HTML
# dom-fe-autofocus

Browser compatibility

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
autofocus

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
Has more compatibility info.