summaryrefslogtreecommitdiff
path: root/devdocs/html/global_attributes%2Fautofocus.html
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
committerCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
commit754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch)
treef1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/html/global_attributes%2Fautofocus.html
new repository
Diffstat (limited to 'devdocs/html/global_attributes%2Fautofocus.html')
-rw-r--r--devdocs/html/global_attributes%2Fautofocus.html68
1 files changed, 68 insertions, 0 deletions
diff --git a/devdocs/html/global_attributes%2Fautofocus.html b/devdocs/html/global_attributes%2Fautofocus.html
new file mode 100644
index 00000000..e7b5c5b0
--- /dev/null
+++ b/devdocs/html/global_attributes%2Fautofocus.html
@@ -0,0 +1,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>&lt;dialog&gt;</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">&lt;</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">/&gt;</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>&lt;button&gt;</code>, <code>&lt;input&gt;</code>, <code>&lt;select&gt;</code>, and <code>&lt;textarea&gt;</code> elements.</details>
+</td>
+<td class="bc-supports-yes">79<details><summary>12–79</summary>Supported for the <code>&lt;button&gt;</code>, <code>&lt;input&gt;</code>, <code>&lt;select&gt;</code>, and <code>&lt;textarea&gt;</code> elements.</details>
+</td>
+<td class="bc-supports-yes"><details><summary>1</summary>Supported for the <code>&lt;button&gt;</code>, <code>&lt;input&gt;</code>, <code>&lt;select&gt;</code>, and <code>&lt;textarea&gt;</code> elements.</details></td>
+<td class="bc-supports-yes"><details><summary>10</summary>Supported for the <code>&lt;button&gt;</code>, <code>&lt;input&gt;</code>, <code>&lt;select&gt;</code>, and <code>&lt;textarea&gt;</code> elements.</details></td>
+<td class="bc-supports-yes">66<details><summary>≤12.1–66</summary>Supported for the <code>&lt;button&gt;</code>, <code>&lt;input&gt;</code>, <code>&lt;select&gt;</code>, and <code>&lt;textarea&gt;</code> elements.</details>
+</td>
+<td class="bc-supports-yes"><details><summary>4</summary>Supported for the <code>&lt;button&gt;</code>, <code>&lt;input&gt;</code>, <code>&lt;select&gt;</code>, and <code>&lt;textarea&gt;</code> elements.</details></td>
+<td class="bc-supports-yes">79<details><summary>≤37–79</summary>Supported for the <code>&lt;button&gt;</code>, <code>&lt;input&gt;</code>, <code>&lt;select&gt;</code>, and <code>&lt;textarea&gt;</code> elements.</details>
+</td>
+<td class="bc-supports-yes">79<details><summary>18–79</summary>Supported for the <code>&lt;button&gt;</code>, <code>&lt;input&gt;</code>, <code>&lt;select&gt;</code>, and <code>&lt;textarea&gt;</code> elements.</details>
+</td>
+<td class="bc-supports-yes"><details><summary>4</summary>Supported for the <code>&lt;button&gt;</code>, <code>&lt;input&gt;</code>, <code>&lt;select&gt;</code>, and <code>&lt;textarea&gt;</code> elements.</details></td>
+<td class="bc-supports-yes">57<details><summary>≤12.1–57</summary>Supported for the <code>&lt;button&gt;</code>, <code>&lt;input&gt;</code>, <code>&lt;select&gt;</code>, and <code>&lt;textarea&gt;</code> elements.</details>
+</td>
+<td class="bc-supports-yes"><details><summary>3.2</summary>Supported for the <code>&lt;button&gt;</code>, <code>&lt;input&gt;</code>, <code>&lt;select&gt;</code>, and <code>&lt;textarea&gt;</code> elements.</details></td>
+<td class="bc-supports-yes">12.0<details><summary>1.0–12.0</summary>Supported for the <code>&lt;button&gt;</code>, <code>&lt;input&gt;</code>, <code>&lt;select&gt;</code>, and <code>&lt;textarea&gt;</code> elements.</details>
+</td>
+</tr></tbody>
+</table></div><div class="_attribution">
+ <p class="_attribution-p">
+ &copy; 2005&ndash;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>