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 Standard
# dom-fe-autofocus

Browser compatibility

BCD tables only load in the browser