files/en-us/web/html/reference/global_attributes/autofocus/index.md
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 {{htmlelement("dialog")}} or popover element, when the <dialog> or popover is shown.
<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
autofocusattribute 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
autofocusattribute does not receive focus via theautofocusattribute. Generally, the element indicated by the fragment receives focus instead.
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}}
{{Compat}}