Since March 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
The autofocus global attribute is a Boolean attribute indicating that an element should be focused on page load, or when the <dialog> that it is part of is displayed.
<input name="q" autofocus />
No more than one element in the document or dialog may have the autofocus attribute. If applied to multiple elements the first 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.
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.
| Specification |
|---|
| HTML> # dom-fe-autofocus> |
| 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 |
791–79Supported for the<button>, <input>, <select>, and <textarea> elements. |
7912–79Supported for the<button>, <input>, <select>, and <textarea> elements. |
1101–110Supported for the<button>, <input>, <select>, and <textarea> elements. |
66≤12.1–66Supported for the<button>, <input>, <select>, and <textarea> elements. |
15.44–15.4Supported for the<button>, <input>, <select>, and <textarea> elements. |
7918–79Supported for the<button>, <input>, <select>, and <textarea> elements. |
1104–110Supported for the<button>, <input>, <select>, and <textarea> elements. |
57≤12.1–57Supported for the<button>, <input>, <select>, and <textarea> elements. |
16.4If there's no hardware keyboard connected, then theautofocus attribute has no effect (for example, the focus event doesn't fire and the element does not match the :focus selector). |
12.01.0–12.0Supported for the<button>, <input>, <select>, and <textarea> elements. |
794.4–79Supported for the<button>, <input>, <select>, and <textarea> elements. |
16.4If there's no hardware keyboard connected, then theautofocus attribute has no effect (for example, the focus event doesn't fire and the element does not match the :focus selector). |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/autofocus