1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
<header><h1>autofocus</h1></header><div class="section-content">
<p>The <code>autofocus</code> <a href="../global_attributes">global attribute</a> is a Boolean attribute indicating that an element should be focused on page load, or when the <a href="../element/dialog"><code><dialog></code></a> that it is part of is displayed.</p> <div class="code-example">
<p class="example-header"><span class="language-name">html</span></p>
<pre data-signature="amYlInUO+/VG9gclExnWwHUIb8Trq8dDc150BeZ2rKw=" data-language="html"><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>input</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>q<span class="token punctuation">"</span></span> <span class="token attr-name">autofocus</span> <span class="token punctuation">/></span></span>
</pre>
</div> <p>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.</p> <div class="notecard note" id="sect1"> <p><strong>Note:</strong> The <code>autofocus</code> attribute applies to all elements, not just form controls. For example, it might be used on a <a href="contenteditable">contenteditable</a> area.</p> </div>
</div>
<h2 id="accessibility_considerations">Accessibility considerations</h2>
<div class="section-content">
<p>Automatically focusing a form control can confuse visually-impaired people using screen-reading technology and people with cognitive impairments. When <code>autofocus</code> is assigned, screen-readers "teleport" their user to the form control without warning them beforehand.</p> <p>Use careful consideration for accessibility when applying the <code>autofocus</code> 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.</p>
</div>
<h2 id="specifications">Specifications</h2>
<div class="_table"><table class="standard-table">
<thead><tr><th scope="col">Specification</th></tr></thead>
<tbody><tr><td><a href="https://html.spec.whatwg.org/multipage/interaction.html#dom-fe-autofocus">HTML Standard <br><small># dom-fe-autofocus</small></a></td></tr></tbody>
</table></div>
<h2 id="browser_compatibility">Browser compatibility</h2>
<div class="_table"><table>
<thead>
<tr id="bct-browser-type">
<th></th>
<th colspan="6">Desktop</th>
<th colspan="6">Mobile</th>
</tr>
<tr id="bct-browsers">
<th></th>
<th>Chrome</th>
<th>Edge</th>
<th>Firefox</th>
<th>Internet Explorer</th>
<th>Opera</th>
<th>Safari</th>
<th>WebView Android</th>
<th>Chrome Android</th>
<th>Firefox for Android</th>
<th>Opera Android</th>
<th>Safari on IOS</th>
<th>Samsung Internet</th>
</tr>
</thead>
<tbody><tr>
<th><code>autofocus</code></th>
<td class="bc-supports-yes">79<details><summary>1–79</summary>Supported for the <code><button></code>, <code><input></code>, <code><select></code>, and <code><textarea></code> elements.</details>
</td>
<td class="bc-supports-yes">79<details><summary>12–79</summary>Supported for the <code><button></code>, <code><input></code>, <code><select></code>, and <code><textarea></code> elements.</details>
</td>
<td class="bc-supports-yes"><details><summary>1</summary>Supported for the <code><button></code>, <code><input></code>, <code><select></code>, and <code><textarea></code> elements.</details></td>
<td class="bc-supports-yes"><details><summary>10</summary>Supported for the <code><button></code>, <code><input></code>, <code><select></code>, and <code><textarea></code> elements.</details></td>
<td class="bc-supports-yes">66<details><summary>≤12.1–66</summary>Supported for the <code><button></code>, <code><input></code>, <code><select></code>, and <code><textarea></code> elements.</details>
</td>
<td class="bc-supports-yes"><details><summary>4</summary>Supported for the <code><button></code>, <code><input></code>, <code><select></code>, and <code><textarea></code> elements.</details></td>
<td class="bc-supports-yes">79<details><summary>≤37–79</summary>Supported for the <code><button></code>, <code><input></code>, <code><select></code>, and <code><textarea></code> elements.</details>
</td>
<td class="bc-supports-yes">79<details><summary>18–79</summary>Supported for the <code><button></code>, <code><input></code>, <code><select></code>, and <code><textarea></code> elements.</details>
</td>
<td class="bc-supports-yes"><details><summary>4</summary>Supported for the <code><button></code>, <code><input></code>, <code><select></code>, and <code><textarea></code> elements.</details></td>
<td class="bc-supports-yes">57<details><summary>≤12.1–57</summary>Supported for the <code><button></code>, <code><input></code>, <code><select></code>, and <code><textarea></code> elements.</details>
</td>
<td class="bc-supports-yes"><details><summary>3.2</summary>Supported for the <code><button></code>, <code><input></code>, <code><select></code>, and <code><textarea></code> elements.</details></td>
<td class="bc-supports-yes">12.0<details><summary>1.0–12.0</summary>Supported for the <code><button></code>, <code><input></code>, <code><select></code>, and <code><textarea></code> elements.</details>
</td>
</tr></tbody>
</table></div><div class="_attribution">
<p class="_attribution-p">
© 2005–2023 MDN contributors.<br>Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.<br>
<a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autofocus" class="_attribution-link">https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autofocus</a>
</p>
</div>
|