Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. HTML
  3. Reference
  4. Global attributes
  5. autofocus

HTML autofocus 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.

Theautofocusglobal attribute is a Boolean attribute indicating whether the element should be focused on page load or, if it is nested inside a<dialog> orpopover 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:Theautofocus attribute applies to all elements, not just form controls. For example, it might be used on acontenteditable area.

Note:On page load, if aURI fragment identifier is specified and identifies an element, the element with theautofocus attribute does not receive focus via theautofocus 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. Whenautofocus is assigned, screen-readers "teleport" their user to the form control without warning them beforehand.

Use careful consideration for accessibility when applying theautofocus 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

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2026 Movatter.jp