HTMLElement: autofocus property

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since February 2023.

The autofocus property of the HTMLElement interface represents a boolean value reflecting the autofocus HTML global attribute. This indicates whether the element should be focused on page load or, if it is nested inside a <dialog> or popover element, when the <dialog> or popover is shown.

Only one element inside a document, <dialog> element, or popover may have this attribute specified. If applied to multiple elements, the first focusable one will receive 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

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
autofocus
Chrome – Partial support
Chrome 1 – 78 (Release date: 2008-12-11)
footnote Partial support
footnote Supported for HTMLButtonElement, HTMLInputElement, HTMLSelectElement, and HTMLTextAreaElement.
Chrome – Full support
Chrome 79 (Release date: 2019-12-10)
footnote Full support
Edge – Partial support
Edge 12 – 18 (Release date: 2015-07-29)
footnote Partial support
footnote Supported for HTMLButtonElement, HTMLInputElement, HTMLSelectElement, and HTMLTextAreaElement.
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Partial support
Firefox 1 – 109 (Release date: 2004-11-09)
footnote Partial support
footnote Supported for HTMLButtonElement, HTMLInputElement, HTMLSelectElement, and HTMLTextAreaElement.
Firefox – Full support
Firefox 110 (Release date: 2023-02-14)
footnote Full support
Opera – Partial support
Opera 12.1 – 65 (Release date: 2012-11-20)
footnote Partial support
footnote Supported for HTMLButtonElement, HTMLInputElement, HTMLSelectElement, and HTMLTextAreaElement.
Opera – Full support
Opera 66 (Release date: 2020-01-07)
footnote Full support
Safari – Partial support
Safari 4 – 15.3 (Release date: 2009-06-08)
footnote Partial support
footnote Supported for HTMLButtonElement, HTMLInputElement, HTMLSelectElement, and HTMLTextAreaElement.
Safari – Full support
Safari 15.4 (Release date: 2022-03-14)
footnote Full support
Chrome Android – Partial support
Chrome Android 18 – 78 (Release date: 2012-06-27)
footnote Partial support
footnote Supported for HTMLButtonElement, HTMLInputElement, HTMLSelectElement, and HTMLTextAreaElement.
Chrome Android – Full support
Chrome Android 79 (Release date: 2019-12-17)
footnote Full support
Firefox for Android – Partial support
Firefox for Android 4 – 109 (Release date: 2011-03-29)
footnote Partial support
footnote Supported for HTMLButtonElement, HTMLInputElement, HTMLSelectElement, and HTMLTextAreaElement.
Firefox for Android – Full support
Firefox for Android 110 (Release date: 2023-02-14)
footnote Full support
Opera Android – Partial support
Opera Android 12.1 – 56 (Release date: 2012-10-09)
footnote Partial support
footnote Supported for HTMLButtonElement, HTMLInputElement, HTMLSelectElement, and HTMLTextAreaElement.
Opera Android – Full support
Opera Android 57 (Release date: 2020-03-30)
footnote Full support
Safari on iOS – Partial support
Safari on iOS 3.2 – 15.3 (Release date: 2010-04-03)
footnote Partial support
footnote Supported for HTMLButtonElement, HTMLInputElement, HTMLSelectElement, and HTMLTextAreaElement.
Safari on iOS – Full support
Safari on iOS 15.4 (Release date: 2022-03-14)
footnote Full support
Samsung Internet – Partial support
Samsung Internet 1 – 11.2 (Release date: 2013-04-27)
footnote Partial support
footnote Supported for HTMLButtonElement, HTMLInputElement, HTMLSelectElement, and HTMLTextAreaElement.
Samsung Internet – Full support
Samsung Internet 12 (Release date: 2020-06-19)
footnote Full support
WebView Android – Partial support
WebView Android 4.4 – 78 (Release date: 2013-12-09)
footnote Partial support
footnote Supported for HTMLButtonElement, HTMLInputElement, HTMLSelectElement, and HTMLTextAreaElement.
WebView Android – Full support
WebView Android 79 (Release date: 2019-12-17)
footnote Full support
WebView on iOS – Partial support
WebView on iOS 3.2 – 15.3 (Release date: 2010-04-03)
footnote Partial support
footnote Supported for HTMLButtonElement, HTMLInputElement, HTMLSelectElement, and HTMLTextAreaElement.
WebView on iOS – Full support
WebView on iOS 15.4 (Release date: 2022-03-14)
footnote Full support

Legend

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

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