autofocus HTML global attribute

Baseline Widely available

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

The autofocus global attribute is a Boolean attribute indicating 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.

html
<input name="q" autofocus />

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: The autofocus attribute applies to all elements, not just form controls. For example, it might be used on a contenteditable area.

Note: On page load, if a URI fragment identifier is specified and identifies an element, the element with the autofocus attribute does not receive focus via the autofocus attribute. Generally, the element indicated by the fragment receives focus instead.

Accessibility concerns

Automatically focusing a form control can confuse visually-impaired people using screen-reading technology and people with cognitive impairments. When autofocus is assigned, screen-readers "teleport" their user to the form control without warning them beforehand.

Use careful consideration for accessibility when applying the autofocus attribute. Automatically focusing on a control can cause the page to scroll on load. The focus can also cause dynamic keyboards to display on some touch devices. While a screen reader will announce the label of the form control receiving focus, the screen reader will not announce anything before the label, and the sighted user on a small device will equally miss the context created by the preceding content.

Specifications

Specification
HTML
# the-autofocus-attribute

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 the <button>, <input>, <select>, and <textarea> elements.
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 the <button>, <input>, <select>, and <textarea> elements.
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 the <button>, <input>, <select>, and <textarea> elements.
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 the <button>, <input>, <select>, and <textarea> elements.
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 the <button>, <input>, <select>, and <textarea> elements.
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 the <button>, <input>, <select>, and <textarea> elements.
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 the <button>, <input>, <select>, and <textarea> elements.
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 the <button>, <input>, <select>, and <textarea> elements.
Opera Android – Full support
Opera Android 57 (Release date: 2020-03-30)
footnote Full support
Safari on iOS – Full support
Safari on iOS 16.4 (Release date: 2023-03-27)
footnote
footnote If there's no hardware keyboard connected, then the autofocus attribute has no effect (for example, the focus event doesn't fire and the element does not match the :focus selector).
Samsung Internet – Partial support
Samsung Internet 1 – 11.2 (Release date: 2013-04-27)
footnote Partial support
footnote Supported for the <button>, <input>, <select>, and <textarea> elements.
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 the <button>, <input>, <select>, and <textarea> elements.
WebView Android – Full support
WebView Android 79 (Release date: 2019-12-17)
footnote Full support
WebView on iOS – Full support
WebView on iOS 16.4 (Release date: 2023-03-27)
footnote
footnote If there's no hardware keyboard connected, then the autofocus attribute has no effect (for example, the focus event doesn't fire and the element does not match the :focus selector).

Legend

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

Full support
Full support
Partial support
Partial support
See implementation notes.
Has more compatibility info.