CINXE.COM

HTML Standard

<!DOCTYPE html><html class=split lang=en-US-x-hixie><script src=/link-fixup.js defer=""></script><meta charset=utf-8><meta content="width=device-width, initial-scale=1, shrink-to-fit=no" name=viewport><title>HTML Standard</title><meta content=#3c790a name=theme-color><meta content="light dark" name=color-scheme><link rel=stylesheet href=https://resources.whatwg.org/standard-shared-with-dev.css crossorigin=""><link rel=stylesheet href=https://resources.whatwg.org/standard.css crossorigin=""><link rel=stylesheet href=https://resources.whatwg.org/spec.css crossorigin=""><link rel=icon href=https://resources.whatwg.org/logo.svg crossorigin=""><link rel=stylesheet href=/styles.css crossorigin=""><script> function toggleStatus(div) { div.parentNode.classList.toggle('wrapped'); } function setLinkFragment(link) { link.hash = location.hash; } </script><body> <script defer="" crossorigin="" src=/html-dfn.js></script> <header id=head class="head with-buttons"> <a href=https://whatwg.org/ class=logo><img width=100 alt=WHATWG crossorigin="" class=darkmode-aware src=https://resources.whatwg.org/logo.svg height=100></a> <hgroup><h1 class=allcaps>HTML</h1><p id=living-standard>Living Standard — Last Updated <span class=pubdate>22 November 2024</span></hgroup> </header> <nav><a href=microdata.html>← 5 Microdata</a> — <a href=./>Table of Contents</a> — <a href=dnd.html>6.11 Drag and drop →</a></nav><ol class=toc><li id=toc-editing><a href=interaction.html#editing><span class=secno>6</span> User interaction</a><ol><li><a href=interaction.html#the-hidden-attribute><span class=secno>6.1</span> The <code>hidden</code> attribute</a><li><a href=interaction.html#page-visibility><span class=secno>6.2</span> Page visibility</a><ol><li><a href=interaction.html#the-visibilitystateentry-interface><span class=secno>6.2.1</span> The <code>VisibilityStateEntry</code> interface</a></ol><li><a href=interaction.html#inert-subtrees><span class=secno>6.3</span> Inert subtrees</a><ol><li><a href=interaction.html#modal-dialogs-and-inert-subtrees><span class=secno>6.3.1</span> Modal dialogs and inert subtrees</a><li><a href=interaction.html#the-inert-attribute><span class=secno>6.3.2</span> The <code>inert</code> attribute</a></ol><li><a href=interaction.html#tracking-user-activation><span class=secno>6.4</span> Tracking user activation</a><ol><li><a href=interaction.html#user-activation-data-model><span class=secno>6.4.1</span> Data model</a><li><a href=interaction.html#user-activation-processing-model><span class=secno>6.4.2</span> Processing model</a><li><a href=interaction.html#user-activation-gated-apis><span class=secno>6.4.3</span> APIs gated by user activation</a><li><a href=interaction.html#the-useractivation-interface><span class=secno>6.4.4</span> The <code>UserActivation</code> interface</a><li><a href=interaction.html#user-activation-user-agent-automation><span class=secno>6.4.5</span> User agent automation</a></ol><li><a href=interaction.html#activation><span class=secno>6.5</span> Activation behavior of elements</a><ol><li><a href=interaction.html#the-toggleevent-interface><span class=secno>6.5.1</span> The <code>ToggleEvent</code> interface</a></ol><li><a href=interaction.html#focus><span class=secno>6.6</span> Focus</a><ol><li><a href=interaction.html#introduction-8><span class=secno>6.6.1</span> Introduction</a><li><a href=interaction.html#data-model><span class=secno>6.6.2</span> Data model</a><li><a href=interaction.html#the-tabindex-attribute><span class=secno>6.6.3</span> The <code>tabindex</code> attribute</a><li><a href=interaction.html#focus-processing-model><span class=secno>6.6.4</span> Processing model</a><li><a href=interaction.html#sequential-focus-navigation><span class=secno>6.6.5</span> Sequential focus navigation</a><li><a href=interaction.html#focus-management-apis><span class=secno>6.6.6</span> Focus management APIs</a><li><a href=interaction.html#the-autofocus-attribute><span class=secno>6.6.7</span> The <code>autofocus</code> attribute</a></ol><li><a href=interaction.html#assigning-keyboard-shortcuts><span class=secno>6.7</span> Assigning keyboard shortcuts</a><ol><li><a href=interaction.html#introduction-9><span class=secno>6.7.1</span> Introduction</a><li><a href=interaction.html#the-accesskey-attribute><span class=secno>6.7.2</span> The <code>accesskey</code> attribute</a><li><a href=interaction.html#keyboard-shortcuts-processing-model><span class=secno>6.7.3</span> Processing model</a></ol><li><a href=interaction.html#editing-2><span class=secno>6.8</span> Editing</a><ol><li><a href=interaction.html#contenteditable><span class=secno>6.8.1</span> Making document regions editable: The <code>contenteditable</code> content attribute</a><li><a href=interaction.html#making-entire-documents-editable:-the-designmode-idl-attribute><span class=secno>6.8.2</span> Making entire documents editable: the <code>designMode</code> getter and setter</a><li><a href=interaction.html#best-practices-for-in-page-editors><span class=secno>6.8.3</span> Best practices for in-page editors</a><li><a href=interaction.html#editing-apis><span class=secno>6.8.4</span> Editing APIs</a><li><a href=interaction.html#spelling-and-grammar-checking><span class=secno>6.8.5</span> Spelling and grammar checking</a><li><a href=interaction.html#writing-suggestions><span class=secno>6.8.6</span> Writing suggestions</a><li><a href=interaction.html#autocapitalization><span class=secno>6.8.7</span> Autocapitalization</a><li><a href=interaction.html#autocorrection><span class=secno>6.8.8</span> Autocorrection</a><li><a href=interaction.html#input-modalities:-the-inputmode-attribute><span class=secno>6.8.9</span> Input modalities: the <code>inputmode</code> attribute</a><li><a href=interaction.html#input-modalities:-the-enterkeyhint-attribute><span class=secno>6.8.10</span> Input modalities: the <code>enterkeyhint</code> attribute</a></ol><li><a href=interaction.html#find-in-page><span class=secno>6.9</span> Find-in-page</a><ol><li><a href=interaction.html#introduction-10><span class=secno>6.9.1</span> Introduction</a><li><a href="interaction.html#interaction-with-details-and-hidden=until-found"><span class=secno>6.9.2</span> Interaction with <code>details</code> and <code>hidden=until-found</code></a><li><a href=interaction.html#interaction-with-selection><span class=secno>6.9.3</span> Interaction with selection</a></ol><li><a href=interaction.html#close-requests-and-close-watchers><span class=secno>6.10</span> Close requests and close watchers</a><ol><li><a href=interaction.html#close-requests><span class=secno>6.10.1</span> Close requests</a><li><a href=interaction.html#close-watcher-infrastructure><span class=secno>6.10.2</span> Close watcher infrastructure</a><li><a href=interaction.html#the-closewatcher-interface><span class=secno>6.10.3</span> The <code>CloseWatcher</code> interface</a></ol></ol></ol><h2 id=editing><span class=secno>6</span> <dfn>User interaction</dfn><a href=#editing class=self-link></a></h2> <h3 id=the-hidden-attribute><span class=secno>6.1</span> The <code id=the-hidden-attribute:attr-hidden><a href=#attr-hidden>hidden</a></code> attribute<a href=#the-hidden-attribute class=self-link></a></h3><div class="mdn-anno wrapped"><button onclick=toggleStatus(this) class=mdn-anno-btn><b title="Support in one engine only." class=less-than-two-engines-flag>⚠</b><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/hidden title="The hidden global attribute is an enumerated attribute indicating that the browser should not render the contents of the element. For example, it can be used to hide elements of the page that can't be used until the login process has been completed.">Global_attributes/hidden</a><p class=less-than-two-engines-text>Support in one engine only.<div class=support><span class="firefox no"><span>Firefox</span><span>No</span></span><span class="safari no"><span>Safari</span><span>No</span></span><span class="chrome yes"><span>Chrome</span><span>102+</span></span><hr><span class="opera no"><span>Opera</span><span>No</span></span><span class="edge_blink yes"><span>Edge</span><span>102+</span></span><hr><span class="edge unknown"><span>Edge (Legacy)</span><span>?</span></span><span class="ie no"><span>Internet Explorer</span><span>No</span></span><hr><span class="firefox_android unknown"><span>Firefox Android</span><span>?</span></span><span class="safari_ios unknown"><span>Safari iOS</span><span>?</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android unknown"><span>WebView Android</span><span>?</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android unknown"><span>Opera Android</span><span>?</span></span></div></div><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/hidden title="The hidden global attribute is an enumerated attribute indicating that the browser should not render the contents of the element. For example, it can be used to hide elements of the page that can't be used until the login process has been completed.">Global_attributes/hidden</a><p class=all-engines-text>Support in all current engines.<div class=support><span class="firefox yes"><span>Firefox</span><span>4+</span></span><span class="safari yes"><span>Safari</span><span>5.1+</span></span><span class="chrome yes"><span>Chrome</span><span>10+</span></span><hr><span class="opera unknown"><span>Opera</span><span>?</span></span><span class="edge_blink yes"><span>Edge</span><span>79+</span></span><hr><span class="edge yes"><span>Edge (Legacy)</span><span>12+</span></span><span class="ie yes"><span>Internet Explorer</span><span>11</span></span><hr><span class="firefox_android unknown"><span>Firefox Android</span><span>?</span></span><span class="safari_ios unknown"><span>Safari iOS</span><span>?</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android yes"><span>WebView Android</span><span>4+</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android unknown"><span>Opera Android</span><span>?</span></span></div></div></div> <p>All <a id=the-hidden-attribute:html-elements href=infrastructure.html#html-elements>HTML elements</a> may have the <dfn data-dfn-for=html-global id=attr-hidden data-dfn-type=element-attr><code>hidden</code></dfn> content attribute set. The <code id=the-hidden-attribute:attr-hidden-2><a href=#attr-hidden>hidden</a></code> attribute is an <a id=the-hidden-attribute:enumerated-attribute href=common-microsyntaxes.html#enumerated-attribute>enumerated attribute</a> with the following keywords and states:</p> <table><thead><tr><th>Keyword <th>State <th>Brief description <tbody><tr><td><dfn data-dfn-for=html-global/hidden id=attr-hidden-hidden data-dfn-type=attr-value><code>hidden</code></dfn> <td rowspan=2><dfn id=attr-hidden-hidden-state>hidden</dfn> <td rowspan=2>Will not be rendered. <tr><td>(the empty string) <tr><td><dfn data-dfn-for=html-global/hidden id=attr-hidden-until-found data-dfn-type=attr-value><code>until-found</code></dfn> <td><dfn id=attr-hidden-until-found-state>hidden until found</dfn> <td>Will not be rendered, but content inside will be accessible to <a href=#find-in-page-2 id=the-hidden-attribute:find-in-page-2>find-in-page</a> and <a href=browsing-the-web.html#navigate-fragid id=the-hidden-attribute:navigate-fragid>fragment navigation</a>. </table> <p>The attribute's <i id=the-hidden-attribute:missing-value-default><a href=common-microsyntaxes.html#missing-value-default>missing value default</a></i> is the <dfn id=attr-hidden-not-hidden-state>not hidden</dfn> state, and its <i id=the-hidden-attribute:invalid-value-default><a href=common-microsyntaxes.html#invalid-value-default>invalid value default</a></i> is the <a href=#attr-hidden-hidden-state id=the-hidden-attribute:attr-hidden-hidden-state>hidden</a> state.</p> <p>When an element has the <code id=the-hidden-attribute:attr-hidden-3><a href=#attr-hidden>hidden</a></code> attribute in the <a href=#attr-hidden-hidden-state id=the-hidden-attribute:attr-hidden-hidden-state-2>hidden</a> state, it indicates that the element is not yet, or is no longer, directly relevant to the page's current state, or that it is being used to declare content to be reused by other parts of the page as opposed to being directly accessed by the user. User agents should not render elements that are in the <a href=#attr-hidden-hidden-state id=the-hidden-attribute:attr-hidden-hidden-state-3>hidden</a> state. This requirement may be implemented indirectly through the style layer. For example, a web browser could implement these requirements <a href=rendering.html#hiddenCSS>using the rules suggested in the Rendering section</a>.</p> <p>When an element has the <code id=the-hidden-attribute:attr-hidden-4><a href=#attr-hidden>hidden</a></code> attribute in the <a href=#attr-hidden-until-found-state id=the-hidden-attribute:attr-hidden-until-found-state>hidden until found</a> state, it indicates that the element is hidden like the <a href=#attr-hidden-hidden-state id=the-hidden-attribute:attr-hidden-hidden-state-4>hidden</a> state but the content inside the element will be accessible to <a href=#find-in-page-2 id=the-hidden-attribute:find-in-page-2-2>find-in-page</a> and <a href=browsing-the-web.html#navigate-fragid id=the-hidden-attribute:navigate-fragid-2>fragment navigation</a>. When these features attempt to scroll to a target which is in the element's subtree, the user agent will remove the <code id=the-hidden-attribute:attr-hidden-5><a href=#attr-hidden>hidden</a></code> attribute in order to reveal the content before scrolling to it. In addition to removing the <code id=the-hidden-attribute:attr-hidden-6><a href=#attr-hidden>hidden</a></code> attribute, an event named <code id=the-hidden-attribute:event-beforematch><a href=indices.html#event-beforematch>beforematch</a></code> is also fired on the element before the <code id=the-hidden-attribute:attr-hidden-7><a href=#attr-hidden>hidden</a></code> attribute is removed.</p> <p>Web browsers will use 'content-visibility: hidden' instead of 'display: none' when the <code id=the-hidden-attribute:attr-hidden-8><a href=#attr-hidden>hidden</a></code> attribute is in the <a href=#attr-hidden-until-found-state id=the-hidden-attribute:attr-hidden-until-found-state-2>hidden until found</a> state, as specified in the <a href=rendering.html#hiddenCSS>Rendering section</a>.</p> <div class=note> <p>Because this attribute is typically implemented using CSS, it's also possible to override it using CSS. For instance, a rule that applies 'display: block' to all elements will cancel the effects of the <a href=#attr-hidden-hidden-state id=the-hidden-attribute:attr-hidden-hidden-state-5>hidden</a> state. Authors therefore have to take care when writing their style sheets to make sure that the attribute is still styled as expected. In addition, legacy user agents which don't support the <a href=#attr-hidden-until-found-state id=the-hidden-attribute:attr-hidden-until-found-state-3>hidden until found</a> state will have 'display: none' instead of 'content-visibility: hidden', so authors are encouraged to make sure that their style sheets don't change the 'display' or 'content-visibility' properties of <a href=#attr-hidden-until-found-state id=the-hidden-attribute:attr-hidden-until-found-state-4>hidden until found</a> elements.</p> <p>Since elements with the <code id=the-hidden-attribute:attr-hidden-9><a href=#attr-hidden>hidden</a></code> attribute in the <a href=#attr-hidden-until-found-state id=the-hidden-attribute:attr-hidden-until-found-state-5>hidden until found</a> state use 'content-visibility: hidden' instead of 'display: none', there are two caveats of the <a href=#attr-hidden-until-found-state id=the-hidden-attribute:attr-hidden-until-found-state-6>hidden until found</a> state that make it different from the <a href=#attr-hidden-hidden-state id=the-hidden-attribute:attr-hidden-hidden-state-6>hidden</a> state:</p> <ol><li><p>The element needs to be affected by <a id=the-hidden-attribute:layout-containment href=https://drafts.csswg.org/css-contain/#containment-layout data-x-internal=layout-containment>layout containment</a> in order to be revealed by find-in-page. This means that if the element in the <a href=#attr-hidden-until-found-state id=the-hidden-attribute:attr-hidden-until-found-state-7>hidden until found</a> state has a 'display' value of 'none', 'contents', or 'inline', then the element will not be revealed by find-in-page.<li><p>The element will still have a <a href=https://drafts.csswg.org/css2/#propdef-visibility id="the-hidden-attribute:'visibility'" data-x-internal="'visibility'">generated box</a> when in the <a href=#attr-hidden-until-found-state id=the-hidden-attribute:attr-hidden-until-found-state-8>hidden until found</a> state, which means that borders, margin, and padding will still be rendered around the element.</ol> </div> <div class=example> <p>In the following skeletal example, the attribute is used to hide the web game's main screen until the user logs in:</p> <pre><code class='html'> <c- p>&lt;</c-><c- f>h1</c-><c- p>&gt;</c->The Example Game<c- p>&lt;/</c-><c- f>h1</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>section</c-> <c- e>id</c-><c- o>=</c-><c- s>&quot;login&quot;</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>h2</c-><c- p>&gt;</c->Login<c- p>&lt;/</c-><c- f>h2</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>form</c-><c- p>&gt;</c-> ... <c- c>&lt;!-- calls login() once the user&apos;s credentials have been checked --&gt;</c-> <c- p>&lt;/</c-><c- f>form</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>script</c-><c- p>&gt;</c-> <c- a>function</c-> login<c- p>()</c-> <c- p>{</c-> <c- c1>// switch screens</c-> document<c- p>.</c->getElementById<c- p>(</c-><c- t>&apos;login&apos;</c-><c- p>).</c->hidden <c- o>=</c-> <c- kc>true</c-><c- p>;</c-> document<c- p>.</c->getElementById<c- p>(</c-><c- t>&apos;game&apos;</c-><c- p>).</c->hidden <c- o>=</c-> <c- kc>false</c-><c- p>;</c-> <c- p>}</c-> <c- p>&lt;/</c-><c- f>script</c-><c- p>&gt;</c-> <c- p>&lt;/</c-><c- f>section</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>section</c-> <c- e>id</c-><c- o>=</c-><c- s>&quot;game&quot;</c-> <c- e>hidden</c-><c- p>&gt;</c-> ... <c- p>&lt;/</c-><c- f>section</c-><c- p>&gt;</c-></code></pre> </div> <p>The <code id=the-hidden-attribute:attr-hidden-10><a href=#attr-hidden>hidden</a></code> attribute must not be used to hide content that could legitimately be shown in another presentation. For example, it is incorrect to use <code id=the-hidden-attribute:attr-hidden-11><a href=#attr-hidden>hidden</a></code> to hide panels in a tabbed dialog, because the tabbed interface is merely a kind of overflow presentation — one could equally well just show all the form controls in one big page with a scrollbar. It is similarly incorrect to use this attribute to hide content just from one presentation — if something is marked <code id=the-hidden-attribute:attr-hidden-12><a href=#attr-hidden>hidden</a></code>, it is hidden from all presentations, including, for instance, screen readers.</p> <p>Elements that are not themselves <code id=the-hidden-attribute:attr-hidden-13><a href=#attr-hidden>hidden</a></code> must not <a id=the-hidden-attribute:hyperlink href=links.html#hyperlink>hyperlink</a> to elements that are <code id=the-hidden-attribute:attr-hidden-14><a href=#attr-hidden>hidden</a></code>. The <code>for</code> attributes of <code id=the-hidden-attribute:the-label-element><a href=forms.html#the-label-element>label</a></code> and <code id=the-hidden-attribute:the-output-element><a href=form-elements.html#the-output-element>output</a></code> elements that are not themselves <code id=the-hidden-attribute:attr-hidden-15><a href=#attr-hidden>hidden</a></code> must similarly not refer to elements that are <code id=the-hidden-attribute:attr-hidden-16><a href=#attr-hidden>hidden</a></code>. In both cases, such references would cause user confusion.</p> <p>Elements and scripts may, however, refer to elements that are <code id=the-hidden-attribute:attr-hidden-17><a href=#attr-hidden>hidden</a></code> in other contexts.</p> <div class=example> <p>For example, it would be incorrect to use the <code id=the-hidden-attribute:attr-hyperlink-href><a href=links.html#attr-hyperlink-href>href</a></code> attribute to link to a section marked with the <code id=the-hidden-attribute:attr-hidden-18><a href=#attr-hidden>hidden</a></code> attribute. If the content is not applicable or relevant, then there is no reason to link to it.</p> <p>It would be fine, however, to use the ARIA <code id=the-hidden-attribute:attr-aria-describedby><a data-x-internal=attr-aria-describedby href=https://w3c.github.io/aria/#aria-describedby>aria-describedby</a></code> attribute to refer to descriptions that are themselves <code id=the-hidden-attribute:attr-hidden-19><a href=#attr-hidden>hidden</a></code>. While hiding the descriptions implies that they are not useful alone, they could be written in such a way that they are useful in the specific context of being referenced from the elements that they describe.</p> <p>Similarly, a <code id=the-hidden-attribute:the-canvas-element><a href=canvas.html#the-canvas-element>canvas</a></code> element with the <code id=the-hidden-attribute:attr-hidden-20><a href=#attr-hidden>hidden</a></code> attribute could be used by a scripted graphics engine as an off-screen buffer, and a form control could refer to a hidden <code id=the-hidden-attribute:the-form-element><a href=forms.html#the-form-element>form</a></code> element using its <code id=the-hidden-attribute:attr-fae-form><a href=form-control-infrastructure.html#attr-fae-form>form</a></code> attribute.</p> </div> <p>Elements in a section hidden by the <code id=the-hidden-attribute:attr-hidden-21><a href=#attr-hidden>hidden</a></code> attribute are still active, e.g. scripts and form controls in such sections still execute and submit respectively. Only their presentation to the user changes.</p> <div class="mdn-anno wrapped before"><button onclick=toggleStatus(this) class=mdn-anno-btn><b title="Support in all current engines." class=all-engines-flag>✔</b><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/hidden title="The HTMLElement property hidden reflects the value of the element's hidden attribute.">HTMLElement/hidden</a><p class=all-engines-text>Support in all current engines.<div class=support><span class="firefox yes"><span>Firefox</span><span>4+</span></span><span class="safari yes"><span>Safari</span><span>5.1+</span></span><span class="chrome yes"><span>Chrome</span><span>6+</span></span><hr><span class="opera yes"><span>Opera</span><span>11.6+</span></span><span class="edge_blink yes"><span>Edge</span><span>79+</span></span><hr><span class="edge yes"><span>Edge (Legacy)</span><span>12+</span></span><span class="ie yes"><span>Internet Explorer</span><span>11</span></span><hr><span class="firefox_android unknown"><span>Firefox Android</span><span>?</span></span><span class="safari_ios unknown"><span>Safari iOS</span><span>?</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android yes"><span>WebView Android</span><span>3+</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android yes"><span>Opera Android</span><span>12+</span></span></div></div></div><p>The <dfn data-dfn-for=HTMLElement id=dom-hidden data-dfn-type=attribute><code>hidden</code></dfn> getter steps are:</p> <ol><li><p>If the <code id=the-hidden-attribute:attr-hidden-22><a href=#attr-hidden>hidden</a></code> attribute is in the <a href=#attr-hidden-until-found-state id=the-hidden-attribute:attr-hidden-until-found-state-9>hidden until found</a> state, then return "<code id=the-hidden-attribute:attr-hidden-until-found><a href=#attr-hidden-until-found>until-found</a></code>".<li><p>If the <code id=the-hidden-attribute:attr-hidden-23><a href=#attr-hidden>hidden</a></code> attribute is set, then return true.<li><p>Return false.</ol> <p>The <code id=the-hidden-attribute:dom-hidden><a href=#dom-hidden>hidden</a></code> setter steps are:</p> <ol><li><p>If the given value is a string that is an <a id=the-hidden-attribute:ascii-case-insensitive href=https://infra.spec.whatwg.org/#ascii-case-insensitive data-x-internal=ascii-case-insensitive>ASCII case-insensitive</a> match for "<code id=the-hidden-attribute:attr-hidden-until-found-2><a href=#attr-hidden-until-found>until-found</a></code>", then set the <code id=the-hidden-attribute:attr-hidden-24><a href=#attr-hidden>hidden</a></code> attribute to "<code id=the-hidden-attribute:attr-hidden-until-found-3><a href=#attr-hidden-until-found>until-found</a></code>".<li><p>Otherwise, if the given value is false, then remove the <code id=the-hidden-attribute:attr-hidden-25><a href=#attr-hidden>hidden</a></code> attribute.<li><p>Otherwise, if the given value is the empty string, then remove the <code id=the-hidden-attribute:attr-hidden-26><a href=#attr-hidden>hidden</a></code> attribute.<li><p>Otherwise, if the given value is null, then remove the <code id=the-hidden-attribute:attr-hidden-27><a href=#attr-hidden>hidden</a></code> attribute.<li><p>Otherwise, if the given value is 0, then remove the <code id=the-hidden-attribute:attr-hidden-28><a href=#attr-hidden>hidden</a></code> attribute.<li><p>Otherwise, if the given value is NaN, then remove the <code id=the-hidden-attribute:attr-hidden-29><a href=#attr-hidden>hidden</a></code> attribute.<li><p>Otherwise, set the <code id=the-hidden-attribute:attr-hidden-30><a href=#attr-hidden>hidden</a></code> attribute to the empty string.</ol> <p>The <dfn id=ancestor-hidden-until-found-revealing-algorithm>ancestor hidden-until-found revealing algorithm</dfn> is to run the following steps on <var>currentNode</var>:</p> <ol><li> <p>While <var>currentNode</var> has a parent node within the <a id=the-hidden-attribute:flat-tree href=https://drafts.csswg.org/css-scoping/#flat-tree data-x-internal=flat-tree>flat tree</a>:</p> <ol><li> <p>If <var>currentNode</var> has the <code id=the-hidden-attribute:attr-hidden-31><a href=#attr-hidden>hidden</a></code> attribute in the <a href=#attr-hidden-until-found-state id=the-hidden-attribute:attr-hidden-until-found-state-10>hidden until found</a> state, then:</p> <ol><li><p><a href=https://dom.spec.whatwg.org/#concept-event-fire id=the-hidden-attribute:concept-event-fire data-x-internal=concept-event-fire>Fire an event</a> named <code id=the-hidden-attribute:event-beforematch-2><a href=indices.html#event-beforematch>beforematch</a></code> at <var>currentNode</var>.<li><p>Remove the <code id=the-hidden-attribute:attr-hidden-32><a href=#attr-hidden>hidden</a></code> attribute from <var>currentNode</var>.</ol> <li><p>Set <var>currentNode</var> to the parent node of <var>currentNode</var> within the <a id=the-hidden-attribute:flat-tree-2 href=https://drafts.csswg.org/css-scoping/#flat-tree data-x-internal=flat-tree>flat tree</a>.</ol> </ol> <h3 id=page-visibility><span class=secno>6.2</span> Page visibility<a href=#page-visibility class=self-link></a></h3> <p>A <a id=page-visibility:traversable-navigable href=document-sequences.html#traversable-navigable>traversable navigable</a>'s <a id=page-visibility:system-visibility-state href=document-sequences.html#system-visibility-state>system visibility state</a>, including its initial value upon creation, is determined by the user agent. It represents, for example, whether the browser window is minimized, a browser tab is currently in the background, or a system element such as a task switcher obscures the page.</p> <p>When a user-agent determines that the <a id=page-visibility:system-visibility-state-2 href=document-sequences.html#system-visibility-state>system visibility state</a> for <a id=page-visibility:traversable-navigable-2 href=document-sequences.html#traversable-navigable>traversable navigable</a> <var>traversable</var> has changed to <var>newState</var>, it must run the following steps:</p> <ol><li><p>Let <var>navigables</var> be the <a id=page-visibility:inclusive-descendant-navigables href=document-sequences.html#inclusive-descendant-navigables>inclusive descendant navigables</a> of <var>traversable</var>'s <a href=document-sequences.html#nav-document id=page-visibility:nav-document>active document</a>.<li> <p><a href=https://infra.spec.whatwg.org/#list-iterate id=page-visibility:list-iterate data-x-internal=list-iterate>For each</a> <var>navigable</var> of <var>navigables</var> <span class=XXX>in what order?</span>:</p> <ol><li><p>Let <var>document</var> be <var>navigable</var>'s <a href=document-sequences.html#nav-document id=page-visibility:nav-document-2>active document</a>.<li><p><a id=page-visibility:queue-a-global-task href=webappapis.html#queue-a-global-task>Queue a global task</a> on the <a id=page-visibility:user-interaction-task-source href=webappapis.html#user-interaction-task-source>user interaction task source</a> given <var>document</var>'s <a id=page-visibility:concept-relevant-global href=webappapis.html#concept-relevant-global>relevant global object</a> to <a href=#update-the-visibility-state id=page-visibility:update-the-visibility-state>update the visibility state</a> of <var>document</var> with <var>newState</var>.</ol> </ol> <p>A <code id=page-visibility:document><a href=dom.html#document>Document</a></code> has a <dfn data-dfn-for=Document id=visibility-state data-export="">visibility state</dfn>, which is either "<code>hidden</code>" or "<code>visible</code>", initially set to "<code>hidden</code>".</p> <div class="mdn-anno wrapped before"><button onclick=toggleStatus(this) class=mdn-anno-btn><b title="Support in all current engines." class=all-engines-flag>✔</b><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/API/Document/visibilityState title="The Document.visibilityState read-only property returns the visibility of the document, that is in which context this element is now visible. It is useful to know if the document is in the background or an invisible tab, or only loaded for pre-rendering.">Document/visibilityState</a><p class=all-engines-text>Support in all current engines.<div class=support><span class="firefox yes"><span>Firefox</span><span>18+</span></span><span class="safari yes"><span>Safari</span><span>7+</span></span><span class="chrome yes"><span>Chrome</span><span>33+</span></span><hr><span class="opera yes"><span>Opera</span><span>20+</span></span><span class="edge_blink yes"><span>Edge</span><span>79+</span></span><hr><span class="edge yes"><span>Edge (Legacy)</span><span>12+</span></span><span class="ie yes"><span>Internet Explorer</span><span>10+</span></span><hr><span class="firefox_android unknown"><span>Firefox Android</span><span>?</span></span><span class="safari_ios unknown"><span>Safari iOS</span><span>?</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android yes"><span>WebView Android</span><span>4.4.3+</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android yes"><span>Opera Android</span><span>20+</span></span></div></div></div><p>The <dfn data-dfn-for=Document id=dom-document-visibilitystate data-dfn-type=attribute><code>visibilityState</code></dfn> getter steps are to return <a id=page-visibility:this href=https://webidl.spec.whatwg.org/#this data-x-internal=this>this</a>'s <a href=#visibility-state id=page-visibility:visibility-state>visibility state</a>.</p> <div class="mdn-anno wrapped before"><button onclick=toggleStatus(this) class=mdn-anno-btn><b title="Support in all current engines." class=all-engines-flag>✔</b><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/API/Document/hidden title="The Document.hidden read-only property returns a Boolean value indicating if the page is considered hidden or not.">Document/hidden</a><p class=all-engines-text>Support in all current engines.<div class=support><span class="firefox yes"><span>Firefox</span><span>18+</span></span><span class="safari yes"><span>Safari</span><span>7+</span></span><span class="chrome yes"><span>Chrome</span><span>33+</span></span><hr><span class="opera yes"><span>Opera</span><span>12.1+</span></span><span class="edge_blink yes"><span>Edge</span><span>79+</span></span><hr><span class="edge yes"><span>Edge (Legacy)</span><span>12+</span></span><span class="ie yes"><span>Internet Explorer</span><span>10+</span></span><hr><span class="firefox_android unknown"><span>Firefox Android</span><span>?</span></span><span class="safari_ios unknown"><span>Safari iOS</span><span>?</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android yes"><span>WebView Android</span><span>4.4.3+</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android yes"><span>Opera Android</span><span>12.1+</span></span></div></div></div><p>The <dfn data-dfn-for=Document id=dom-document-hidden data-dfn-type=attribute><code>hidden</code></dfn> getter steps are to return true if <a id=page-visibility:this-2 href=https://webidl.spec.whatwg.org/#this data-x-internal=this>this</a>'s <a href=#visibility-state id=page-visibility:visibility-state-2>visibility state</a> is "<code>hidden</code>", otherwise false.</p> <p>To <dfn id=update-the-visibility-state>update the visibility state</dfn> of <code id=page-visibility:document-2><a href=dom.html#document>Document</a></code> <var>document</var> to <var>visibilityState</var>:</p> <ol><li><p>If <var>document</var>'s <a href=#visibility-state id=page-visibility:visibility-state-3>visibility state</a> equals <var>visibilityState</var>, then return.<li><p>Set <var>document</var>'s <a href=#visibility-state id=page-visibility:visibility-state-4>visibility state</a> to <var>visibilityState</var>.<li><p><a href=https://w3c.github.io/performance-timeline/#queue-a-performanceentry id=page-visibility:queue-a-performance-entry data-x-internal=queue-a-performance-entry>Queue</a> a new <code id=page-visibility:visibilitystateentry><a href=#visibilitystateentry>VisibilityStateEntry</a></code> whose <a href=#visibilitystateentry-state id=page-visibility:visibilitystateentry-state>visibility state</a> is <var>visibilityState</var> and whose <a href=#visibilitystateentry-timestamp id=page-visibility:visibilitystateentry-timestamp>timestamp</a> is the <a id=page-visibility:current-high-resolution-time href=https://w3c.github.io/hr-time/#dfn-current-high-resolution-time data-x-internal=current-high-resolution-time>current high resolution time</a> given <var>document</var>'s <a id=page-visibility:concept-relevant-global-2 href=webappapis.html#concept-relevant-global>relevant global object</a>.</p> <li><p>Run the <a id=page-visibility:screen-orientation-change-steps href=https://w3c.github.io/screen-orientation/#dfn-screen-orientation-change-steps data-x-internal=screen-orientation-change-steps>screen orientation change steps</a> with <var>document</var>. <a href=references.html#refsSCREENORIENTATION>[SCREENORIENTATION]</a><li><p>Run the <a id=page-visibility:view-transition-page-visibility-change-steps href=https://drafts.csswg.org/css-view-transitions/#view-transition-page-visibility-change-steps data-x-internal=view-transition-page-visibility-change-steps>view transition page visibility change steps</a> with <var>document</var>.<li> <p>Run any <dfn id=page-visibility-change-steps data-export="">page visibility change steps</dfn> which may be defined in other specifications, with <a href=#visibility-state id=page-visibility:visibility-state-5>visibility state</a> and <var>document</var>.</p> <p class=XXX>It would be better if specification authors sent a pull request to add calls from here into their specifications directly, instead of using the <a href=#page-visibility-change-steps id=page-visibility:page-visibility-change-steps>page visibility change steps</a> hook, to ensure well-defined cross-specification call order. As of the time of this writing the following specifications are known to have <a href=#page-visibility-change-steps id=page-visibility:page-visibility-change-steps-2>page visibility change steps</a>, which will be run in an unspecified order: <cite>Device Posture API</cite> and <cite>Web NFC</cite>. <a href=references.html#refsDEVICEPOSTURE>[DEVICEPOSTURE]</a> <a href=references.html#refsWEBNFC>[WEBNFC]</a></p> <li><p>Fire an event named <code id=page-visibility:event-visibilitychange><a href=indices.html#event-visibilitychange>visibilitychange</a></code> at <var>document</var>, with its <code id=page-visibility:dom-event-bubbles><a data-x-internal=dom-event-bubbles href=https://dom.spec.whatwg.org/#dom-event-bubbles>bubbles</a></code> attribute initialized to true.</ol> <h4 id=the-visibilitystateentry-interface><span class=secno>6.2.1</span> The <code id=the-visibilitystateentry-interface:visibilitystateentry><a href=#visibilitystateentry>VisibilityStateEntry</a></code> interface<a href=#the-visibilitystateentry-interface class=self-link></a></h4><div class="mdn-anno wrapped"><button onclick=toggleStatus(this) class=mdn-anno-btn><b title="Support in one engine only." class=less-than-two-engines-flag>⚠</b><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/API/VisibilityStateEntry title="The VisibilityStateEntry interface provides timings of page visibility state changes, i.e., when a tab changes from the foreground to the background or vice versa.">VisibilityStateEntry</a><p class=less-than-two-engines-text>Support in one engine only.<div class=support><span class="firefox no"><span>Firefox</span><span>No</span></span><span class="safari no"><span>Safari</span><span>No</span></span><span class="chrome yes"><span>Chrome</span><span>115+</span></span><hr><span class="opera unknown"><span>Opera</span><span>?</span></span><span class="edge_blink yes"><span>Edge</span><span>115+</span></span><hr><span class="edge unknown"><span>Edge (Legacy)</span><span>?</span></span><span class="ie no"><span>Internet Explorer</span><span>No</span></span><hr><span class="firefox_android unknown"><span>Firefox Android</span><span>?</span></span><span class="safari_ios unknown"><span>Safari iOS</span><span>?</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android unknown"><span>WebView Android</span><span>?</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android unknown"><span>Opera Android</span><span>?</span></span></div></div></div> <p>The <code id=the-visibilitystateentry-interface:visibilitystateentry-2><a href=#visibilitystateentry>VisibilityStateEntry</a></code> interface exposes visibility changes to the document, from the moment the document becomes active.</p> <div class=example>For example, this allows JavaScript code in the page to examine correlation between visibility changes and paint timing: <pre><code class='js'><c- a>function</c-> wasHiddenBeforeFirstContentfulPaint<c- p>()</c-> <c- p>{</c-> <c- a>const</c-> fcpEntry <c- o>=</c-> performance<c- p>.</c->getEntriesByName<c- p>(</c-><c- u>&quot;first-contentful-paint&quot;</c-><c- p>)[</c-><c- mf>0</c-><c- p>];</c-> <c- a>const</c-> visibilityStateEntries <c- o>=</c-> performance<c- p>.</c->getEntriesByType<c- p>(</c-><c- u>&quot;visibility-state&quot;</c-><c- p>);</c-> <c- k>return</c-> visibilityStateEntries<c- p>.</c->some<c- p>(</c->e <c- p>=&gt;</c-> e<c- p>.</c->startTime <c- o>&lt;</c-> fcpEntry<c- p>.</c->startTime <c- o>&amp;&amp;</c-> e<c- p>.</c->name <c- o>===</c-> <c- u>&quot;hidden&quot;</c-><c- p>);</c-> <c- p>}</c-></code></pre> </div> <p class=note>Since hiding a page can cause throttling of rendering and other user-agent operations, it is common to use visibility changes as an indication that such throttling has occurred. However, other things could also cause throttling in different browsers, such as long periods of inactivity.</p> <pre><code class='idl'>[<c- g>Exposed</c->=(<c- n>Window</c->)] <c- b>interface</c-> <dfn id='visibilitystateentry' data-dfn-type='interface'><c- g>VisibilityStateEntry</c-></dfn> : <a id='the-visibilitystateentry-interface:performanceentry' href='https://w3c.github.io/performance-timeline/#dom-performanceentry' data-x-internal='performanceentry'><c- n>PerformanceEntry</c-></a> { <c- b>readonly</c-> <c- b>attribute</c-> <c- b>DOMString</c-> <a href='#visibilitystateentry-name' id='the-visibilitystateentry-interface:visibilitystateentry-name'><c- g>name</c-></a>; // shadows inherited <a href='https://w3c.github.io/performance-timeline/#dom-performanceentry-name' id='the-visibilitystateentry-interface:performanceentry-name' data-x-internal='performanceentry-name'>name</a> <c- b>readonly</c-> <c- b>attribute</c-> <c- b>DOMString</c-> <a href='#visibilitystateentry-entrytype' id='the-visibilitystateentry-interface:visibilitystateentry-entrytype'><c- g>entryType</c-></a>; // shadows inherited <a href='https://w3c.github.io/performance-timeline/#dom-performanceentry-entrytype' id='the-visibilitystateentry-interface:performanceentry-entrytype' data-x-internal='performanceentry-entrytype'>entryType</a> <c- b>readonly</c-> <c- b>attribute</c-> <c- n>DOMHighResTimeStamp</c-> <a href='#visibilitystateentry-starttime' id='the-visibilitystateentry-interface:visibilitystateentry-starttime'><c- g>startTime</c-></a>; // shadows inherited <a href='https://w3c.github.io/performance-timeline/#dom-performanceentry-starttime' id='the-visibilitystateentry-interface:performanceentry-starttime' data-x-internal='performanceentry-starttime'>startTime</a> <c- b>readonly</c-> <c- b>attribute</c-> <c- b>unsigned</c-> <c- b>long</c-> <a href='#visibilitystateentry-duration' id='the-visibilitystateentry-interface:visibilitystateentry-duration'><c- g>duration</c-></a>; // shadows inherited <a href='https://w3c.github.io/performance-timeline/#dom-performanceentry-duration' id='the-visibilitystateentry-interface:performanceentry-duration' data-x-internal='performanceentry-duration'>duration</a> };</code></pre> <p>The <code id=the-visibilitystateentry-interface:visibilitystateentry-3><a href=#visibilitystateentry>VisibilityStateEntry</a></code> has an associated <a id=the-visibilitystateentry-interface:domhighrestimestamp href=https://w3c.github.io/hr-time/#dom-domhighrestimestamp data-x-internal=domhighrestimestamp><code>DOMHighResTimeStamp</code></a> <dfn id=visibilitystateentry-timestamp>timestamp</dfn>.</p> <p>The <code id=the-visibilitystateentry-interface:visibilitystateentry-4><a href=#visibilitystateentry>VisibilityStateEntry</a></code> has an associated "<code>visible</code>" or "<code>hidden</code>" <dfn id=visibilitystateentry-state>visibility state</dfn>.</p> <p>The <dfn id=visibilitystateentry-name><code>name</code></dfn> getter steps are to return <a id=the-visibilitystateentry-interface:this href=https://webidl.spec.whatwg.org/#this data-x-internal=this>this</a>'s <a href=#visibilitystateentry-state id=the-visibilitystateentry-interface:visibilitystateentry-state>visibility state</a>.</p> <p>The <dfn id=visibilitystateentry-entrytype><code>entryType</code></dfn> getter steps are to return "<code>visibility-state</code>".</p> <p>The <dfn id=visibilitystateentry-starttime><code>startTime</code></dfn> getter steps are to return <a id=the-visibilitystateentry-interface:this-2 href=https://webidl.spec.whatwg.org/#this data-x-internal=this>this</a>'s <a href=#visibilitystateentry-timestamp id=the-visibilitystateentry-interface:visibilitystateentry-timestamp>timestamp</a>.</p> <p>The <dfn id=visibilitystateentry-duration><code>duration</code></dfn> getter steps are to return zero.</p> <h3 id=inert-subtrees><span class=secno>6.3</span> Inert subtrees<a href=#inert-subtrees class=self-link></a></h3> <p class=note>See also <code id=inert-subtrees:the-inert-attribute><a href=#the-inert-attribute>inert</a></code> for an explanation of the attribute of the same name.</p> <p>A node (in particular elements and text nodes) can be <dfn id=inert>inert</dfn>. When a node is <a href=#inert id=inert-subtrees:inert>inert</a>:</p> <ul><li><p>Hit-testing must act as if the <a id="inert-subtrees:'pointer-events'" href=https://drafts.csswg.org/css-ui-4/#pointer-events-control data-x-internal="'pointer-events'">'pointer-events'</a> CSS property were set to 'none'.<li><p>Text selection functionality must act as if the <a id="inert-subtrees:'user-select'" href=https://drafts.csswg.org/css-ui-4/#content-selection data-x-internal="'user-select'">'user-select'</a> CSS property were set to 'none'.<li><p>If it is <a id=inert-subtrees:editable href=https://w3c.github.io/editing/docs/execCommand/#editable data-x-internal=editable>editable</a>, the node behaves as if it were non-editable.<li><p>The user agent should ignore the node for the purposes of <a href=#find-in-page-2 id=inert-subtrees:find-in-page-2>find-in-page</a>.</ul> <p class=note>Inert nodes generally cannot be focused, and user agents do not expose the inert nodes to accessibility APIs or assistive technologies. Inert nodes that are <a href=interactive-elements.html#concept-command id=inert-subtrees:concept-command>commands</a> will become inoperable to users, in the manner described above.</p> <p>User agents may allow the user to override the restrictions on <a href=#find-in-page-2 id=inert-subtrees:find-in-page-2-2>find-in-page</a> and text selection, however.</p> <p>By default, a node is not <a href=#inert id=inert-subtrees:inert-2>inert</a>.</p> <h4 id=modal-dialogs-and-inert-subtrees><span class=secno>6.3.1</span> Modal dialogs and inert subtrees<a href=#modal-dialogs-and-inert-subtrees class=self-link></a></h4> <p>A <code id=modal-dialogs-and-inert-subtrees:document><a href=dom.html#document>Document</a></code> <var>document</var> is <dfn id=blocked-by-a-modal-dialog>blocked by a modal dialog</dfn> <var>subject</var> if <var>subject</var> is the topmost <code id=modal-dialogs-and-inert-subtrees:the-dialog-element><a href=interactive-elements.html#the-dialog-element>dialog</a></code> element in <var>document</var>'s <a id=modal-dialogs-and-inert-subtrees:top-layer href=https://drafts.csswg.org/css-position-4/#document-top-layer data-x-internal=top-layer>top layer</a>. While <var>document</var> is so blocked, every node that is <a id=modal-dialogs-and-inert-subtrees:connected href=https://dom.spec.whatwg.org/#connected data-x-internal=connected>connected</a> to <var>document</var>, with the exception of the <var>subject</var> element and its <a id=modal-dialogs-and-inert-subtrees:flat-tree href=https://drafts.csswg.org/css-scoping/#flat-tree data-x-internal=flat-tree>flat tree</a> descendants, must become <a href=#inert id=modal-dialogs-and-inert-subtrees:inert>inert</a>.</p> <p><var>subject</var> can additionally become <a href=#inert id=modal-dialogs-and-inert-subtrees:inert-2>inert</a> via the <code id=modal-dialogs-and-inert-subtrees:the-inert-attribute><a href=#the-inert-attribute>inert</a></code> attribute, but only if specified on <var>subject</var> itself (i.e., <var>subject</var> escapes inertness of ancestors); <var>subject</var>'s <a id=modal-dialogs-and-inert-subtrees:flat-tree-2 href=https://drafts.csswg.org/css-scoping/#flat-tree data-x-internal=flat-tree>flat tree</a> descendants can become <a href=#inert id=modal-dialogs-and-inert-subtrees:inert-3>inert</a> in a similar fashion.</p> <p class=note>The <code id=modal-dialogs-and-inert-subtrees:the-dialog-element-2><a href=interactive-elements.html#the-dialog-element>dialog</a></code> element's <code id=modal-dialogs-and-inert-subtrees:dom-dialog-showmodal><a href=interactive-elements.html#dom-dialog-showmodal>showModal()</a></code> method causes this mechanism to trigger, by <a href=https://drafts.csswg.org/css-position-4/#add-an-element-to-the-top-layer id=modal-dialogs-and-inert-subtrees:add-an-element-to-the-top-layer data-x-internal=add-an-element-to-the-top-layer>adding</a> the <code id=modal-dialogs-and-inert-subtrees:the-dialog-element-3><a href=interactive-elements.html#the-dialog-element>dialog</a></code> element to its <a id=modal-dialogs-and-inert-subtrees:node-document href=https://dom.spec.whatwg.org/#concept-node-document data-x-internal=node-document>node document</a>'s <a id=modal-dialogs-and-inert-subtrees:top-layer-2 href=https://drafts.csswg.org/css-position-4/#document-top-layer data-x-internal=top-layer>top layer</a>.</p> <h4 id=the-inert-attribute><span class=secno>6.3.2</span> The <dfn><code>inert</code></dfn> attribute<a href=#the-inert-attribute class=self-link></a></h4><div class="mdn-anno wrapped"><button onclick=toggleStatus(this) class=mdn-anno-btn><b title="Support in all current engines." class=all-engines-flag>✔</b><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/inert title="The inert global attribute is a Boolean attribute indicating that the browser will ignore the element. With the inert attribute, all of the element's flat tree descendants (such as modal <dialog>s) that don't otherwise escape inertness are ignored. The inert attribute also makes the browser ignore input events sent by the user, including focus-related events and events from assistive technologies.">Global_attributes/inert</a><p class=all-engines-text>Support in all current engines.<div class=support><span class="firefox yes"><span>Firefox</span><span>112+</span></span><span class="safari yes"><span>Safari</span><span>15.5+</span></span><span class="chrome yes"><span>Chrome</span><span>102+</span></span><hr><span class="opera unknown"><span>Opera</span><span>?</span></span><span class="edge_blink yes"><span>Edge</span><span>102+</span></span><hr><span class="edge unknown"><span>Edge (Legacy)</span><span>?</span></span><span class="ie no"><span>Internet Explorer</span><span>No</span></span><hr><span class="firefox_android unknown"><span>Firefox Android</span><span>?</span></span><span class="safari_ios unknown"><span>Safari iOS</span><span>?</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android unknown"><span>WebView Android</span><span>?</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android unknown"><span>Opera Android</span><span>?</span></span></div></div></div> <p>The <code id=the-inert-attribute:the-inert-attribute><a href=#the-inert-attribute>inert</a></code> attribute is a <a id=the-inert-attribute:boolean-attribute href=common-microsyntaxes.html#boolean-attribute>boolean attribute</a> that indicates, by its presence, that the element and all its <a id=the-inert-attribute:flat-tree href=https://drafts.csswg.org/css-scoping/#flat-tree data-x-internal=flat-tree>flat tree</a> descendants which don't otherwise escape inertness (such as modal dialogs) are to be made <a href=#inert id=the-inert-attribute:inert>inert</a> by the user agent.</p> <p>An inert subtree should not contain any content or controls which are critical to understanding or using aspects of the page which are not in the inert state. Content in an inert subtree will not be perceivable by all users, or interactive. Authors should not specify elements as inert unless the content they represent are also visually obscured in some way. In most cases, authors should not specify the <code id=the-inert-attribute:inert-2><a href=#inert>inert</a></code> attribute on individual form controls. In these instances, the <code id=the-inert-attribute:attr-fe-disabled><a href=form-control-infrastructure.html#attr-fe-disabled>disabled</a></code> attribute is probably more appropriate.</p> <div class=example> <p>The following example shows how to mark partially loaded content, visually obscured by a "loading" message, as inert.</p> <pre><code class='html'><c- p>&lt;</c-><c- f>section</c-> <c- e>aria-labelledby</c-><c- o>=</c-><c- s>s1</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>h3</c-> <c- e>id</c-><c- o>=</c-><c- s>s1</c-><c- p>&gt;</c->Population by City<c- p>&lt;/</c-><c- f>h3</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>div</c-> <c- e>class</c-><c- o>=</c-><c- s>container</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>div</c-> <c- e>class</c-><c- o>=</c-><c- s>loading</c-><c- p>&gt;&lt;</c-><c- f>p</c-><c- p>&gt;</c->Loading...<c- p>&lt;/</c-><c- f>p</c-><c- p>&gt;&lt;/</c-><c- f>div</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>div</c-> <c- e>inert</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>form</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>fieldset</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>legend</c-><c- p>&gt;</c->Date range<c- p>&lt;/</c-><c- f>legend</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>div</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>label</c-> <c- e>for</c-><c- o>=</c-><c- s>start</c-><c- p>&gt;</c->Start<c- p>&lt;/</c-><c- f>label</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>input</c-> <c- e>type</c-><c- o>=</c-><c- s>date</c-> <c- e>id</c-><c- o>=</c-><c- s>start</c-><c- p>&gt;</c-> <c- p>&lt;/</c-><c- f>div</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>div</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>label</c-> <c- e>for</c-><c- o>=</c-><c- s>end</c-><c- p>&gt;</c->End<c- p>&lt;/</c-><c- f>label</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>input</c-> <c- e>type</c-><c- o>=</c-><c- s>date</c-> <c- e>id</c-><c- o>=</c-><c- s>end</c-><c- p>&gt;</c-> <c- p>&lt;/</c-><c- f>div</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>div</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>button</c-><c- p>&gt;</c->Apply<c- p>&lt;/</c-><c- f>button</c-><c- p>&gt;</c-> <c- p>&lt;/</c-><c- f>div</c-><c- p>&gt;</c-> <c- p>&lt;/</c-><c- f>fieldset</c-><c- p>&gt;</c-> <c- p>&lt;/</c-><c- f>form</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>table</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>caption</c-><c- p>&gt;</c->From 20-- to 20--<c- p>&lt;/</c-><c- f>caption</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>thead</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>tr</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>th</c-><c- p>&gt;</c->City<c- p>&lt;/</c-><c- f>th</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>th</c-><c- p>&gt;</c->State<c- p>&lt;/</c-><c- f>th</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>th</c-><c- p>&gt;</c->20-- Population<c- p>&lt;/</c-><c- f>th</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>th</c-><c- p>&gt;</c->20-- Population<c- p>&lt;/</c-><c- f>th</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>th</c-><c- p>&gt;</c->Percentage change<c- p>&lt;/</c-><c- f>th</c-><c- p>&gt;</c-> <c- p>&lt;/</c-><c- f>tr</c-><c- p>&gt;</c-> <c- p>&lt;/</c-><c- f>thead</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>tbody</c-><c- p>&gt;</c-> <c- c>&lt;!-- ... --&gt;</c-> <c- p>&lt;/</c-><c- f>tbody</c-><c- p>&gt;</c-> <c- p>&lt;/</c-><c- f>table</c-><c- p>&gt;</c-> <c- p>&lt;/</c-><c- f>div</c-><c- p>&gt;</c-> <c- p>&lt;/</c-><c- f>div</c-><c- p>&gt;</c-> <c- p>&lt;/</c-><c- f>section</c-><c- p>&gt;</c-></code></pre> <img src=/images/inert-example-loading-section.png width=947 alt="Screenshot of Population by City content with an overlaid loading message which visually obscures the form controls and data table which have not fully rendered, and thus are in the inert state." height=243> <p>The "loading" overlay obscures the inert content, making it visually apparent that the inert content is not presently accessible. Notice that the heading and "loading" text are not descendants of the element with the <code id=the-inert-attribute:inert-3><a href=#inert>inert</a></code> attribute. This will ensure this text is accessible to all users, while the inert content cannot be interacted with by anyone.</p> </div> <div class=note> <p>By default, there is no persistent visual indication of an element or its subtree being inert. Appropriate visual styles for such content is often context-dependent. For instance, an inert off-screen navigation panel would not require a default style, as its off-screen position visually obscures the content. Similarly, a modal <code id=the-inert-attribute:the-dialog-element><a href=interactive-elements.html#the-dialog-element>dialog</a></code> element's backdrop will serve as the means to visually obscure the inert content of the web page, rather than styling the inert content specifically.</p> <p>However, for many other situations authors are strongly encouraged to clearly mark what parts of their document are active and which are inert, to avoid user confusion. In particular, it is worth remembering that not all users can see all parts of a page at once; for example, users of screen readers, users on small devices or with magnifiers, and even users using particularly small windows might not be able to see the active part of a page and might get frustrated if inert sections are not obviously inert.</p> </div> <div class="mdn-anno wrapped before"><button onclick=toggleStatus(this) class=mdn-anno-btn><b title="Support in all current engines." class=all-engines-flag>✔</b><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/inert title="The HTMLElement property inert reflects the value of the element's inert attribute. It is a boolean value that, when present, makes the browser &quot;ignore&quot; user input events for the element, including focus events and events from assistive technologies. The browser may also ignore page search and text selection in the element. This can be useful when building UIs such as modals where you would want to &quot;trap&quot; the focus inside the modal when it's visible.">HTMLElement/inert</a><p class=all-engines-text>Support in all current engines.<div class=support><span class="firefox yes"><span>Firefox</span><span>112+</span></span><span class="safari yes"><span>Safari</span><span>15.5+</span></span><span class="chrome yes"><span>Chrome</span><span>102+</span></span><hr><span class="opera unknown"><span>Opera</span><span>?</span></span><span class="edge_blink yes"><span>Edge</span><span>102+</span></span><hr><span class="edge unknown"><span>Edge (Legacy)</span><span>?</span></span><span class="ie no"><span>Internet Explorer</span><span>No</span></span><hr><span class="firefox_android unknown"><span>Firefox Android</span><span>?</span></span><span class="safari_ios unknown"><span>Safari iOS</span><span>?</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android unknown"><span>WebView Android</span><span>?</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android unknown"><span>Opera Android</span><span>?</span></span></div></div></div><p>The <dfn id=dom-inert><code>inert</code></dfn> IDL attribute must <a id=the-inert-attribute:reflect href=common-dom-interfaces.html#reflect>reflect</a> the content attribute of the same name.</p> <h3 id=tracking-user-activation><span class=secno>6.4</span> Tracking <dfn data-export="">user activation</dfn><a href=#tracking-user-activation class=self-link></a></h3> <p>To prevent abuse of certain APIs that could be annoying to users (e.g., opening popups or vibrating phones), user agents allow these APIs only when the user is actively interacting with the web page or has interacted with the page at least once. This "active interaction" state is maintained through the mechanisms defined in this section.</p> <h4 id=user-activation-data-model><span class=secno>6.4.1</span> Data model<a href=#user-activation-data-model class=self-link></a></h4> <p>For the purpose of tracking user activation, each <code id=user-activation-data-model:window><a href=nav-history-apis.html#window>Window</a></code> <var>W</var> has two relevant values:</p> <ul><li><p>A <dfn id=last-activation-timestamp>last activation timestamp</dfn>, which is either a <code id=user-activation-data-model:domhighrestimestamp><a data-x-internal=domhighrestimestamp href=https://w3c.github.io/hr-time/#dom-domhighrestimestamp>DOMHighResTimeStamp</a></code>, positive infinity (indicating that <var>W</var> has never been activated), or negative infinity (indicating that the activation has been <a href=#consume-user-activation id=user-activation-data-model:consume-user-activation>consumed</a>). Initially positive infinity.<li><p>A <dfn id=last-history-action-activation-timestamp>last history-action activation timestamp</dfn>, which is either a <code id=user-activation-data-model:domhighrestimestamp-2><a data-x-internal=domhighrestimestamp href=https://w3c.github.io/hr-time/#dom-domhighrestimestamp>DOMHighResTimeStamp</a></code> or positive infinity, initially positive infinity.</ul> <p>A user agent also defines a <dfn id=transient-activation-duration>transient activation duration</dfn>, which is a constant number indicating how long a user activation is available for certain <a href=#user-activation-gated-apis>user activation-gated APIs</a> (e.g., for opening popups).</p> <p class=note>The <a href=#transient-activation-duration id=user-activation-data-model:transient-activation-duration>transient activation duration</a> is expected be at most a few seconds, so that the user can possibly perceive the link between an interaction with the page and the page calling the activation-gated API.</p> <p>We then have the following boolean user activation states for <var>W</var>:</p> <dl><dt><dfn id=sticky-activation data-export="">Sticky activation</dfn><dd> <p>When the <a id=user-activation-data-model:current-high-resolution-time href=https://w3c.github.io/hr-time/#dfn-current-high-resolution-time data-x-internal=current-high-resolution-time>current high resolution time</a> given <var>W</var> is greater than or equal to the <a href=#last-activation-timestamp id=user-activation-data-model:last-activation-timestamp>last activation timestamp</a> in <var>W</var>, <var>W</var> is said to have <a href=#sticky-activation id=user-activation-data-model:sticky-activation>sticky activation</a>.</p> <p>This is <var>W</var>'s historical activation state, indicating whether the user has ever interacted in <var>W</var>. It starts false, then changes to true (and never changes back to false) when <var>W</var> gets the very first <a href=#activation-notification id=user-activation-data-model:activation-notification>activation notification</a>.</p> <dt><dfn id=transient-activation data-export="">Transient activation</dfn><dd> <p>When the <a id=user-activation-data-model:current-high-resolution-time-2 href=https://w3c.github.io/hr-time/#dfn-current-high-resolution-time data-x-internal=current-high-resolution-time>current high resolution time</a> given <var>W</var> is greater than or equal to the <a href=#last-activation-timestamp id=user-activation-data-model:last-activation-timestamp-2>last activation timestamp</a> in <var>W</var>, and less than the <a href=#last-activation-timestamp id=user-activation-data-model:last-activation-timestamp-3>last activation timestamp</a> in <var>W</var> plus the <a href=#transient-activation-duration id=user-activation-data-model:transient-activation-duration-2>transient activation duration</a>, then <var>W</var> is said to have <a href=#transient-activation id=user-activation-data-model:transient-activation>transient activation</a>.</p> <p>This is <var>W</var>'s current activation state, indicating whether the user has interacted in <var>W</var> recently. This starts with a false value, and remains true for a limited time after every <a href=#activation-notification id=user-activation-data-model:activation-notification-2>activation notification</a> <var>W</var> gets.</p> <p>The <a href=#transient-activation id=user-activation-data-model:transient-activation-2>transient activation</a> state is considered <dfn id=activation-expiry>expired</dfn> if it becomes false because the <a href=#transient-activation-duration id=user-activation-data-model:transient-activation-duration-3>transient activation duration</a> time has elapsed since the last user activation. Note that it can become false even before the expiry time through an <a href=#consume-user-activation id=user-activation-data-model:consume-user-activation-2>activation consumption</a>.</p> <dt><dfn id=history-action-activation>History-action activation</dfn><dd> <p>When the <a href=#last-history-action-activation-timestamp id=user-activation-data-model:last-history-action-activation-timestamp>last history-action activation timestamp</a> of <var>W</var> is not equal to the <a href=#last-activation-timestamp id=user-activation-data-model:last-activation-timestamp-4>last activation timestamp</a> of <var>W</var>, then <var>W</var> is said to have <a href=#history-action-activation id=user-activation-data-model:history-action-activation>history-action activation</a>.</p> <p>This is a special variant of user activation, used to allow access to certain session history APIs which, if used too frequently, would make it harder for the user to traverse back using <a href=document-lifecycle.html#nav-traversal-ui>browser UI</a>. It starts with a false value, and becomes true whenever the user interacts with <var>W</var>, but is reset to false through <a href=#consume-history-action-user-activation id=user-activation-data-model:consume-history-action-user-activation>history-action activation consumption</a>. This ensures such APIs cannot be used multiple times in a row without an intervening user activation. But unlike <a href=#transient-activation id=user-activation-data-model:transient-activation-3>transient activation</a>, there is no time limit within which such APIs must be used.</p> </dl> <p class=note>The <a href=#last-activation-timestamp id=user-activation-data-model:last-activation-timestamp-5>last activation timestamp</a> and <a href=#last-history-action-activation-timestamp id=user-activation-data-model:last-history-action-activation-timestamp-2>last history-action activation timestamp</a> are retained even after the <code id=user-activation-data-model:document><a href=dom.html#document>Document</a></code> changes its <a id=user-activation-data-model:fully-active href=document-sequences.html#fully-active>fully active</a> status (e.g., after navigating away from a <code id=user-activation-data-model:document-2><a href=dom.html#document>Document</a></code>, or navigating to a cached <code id=user-activation-data-model:document-3><a href=dom.html#document>Document</a></code>). This means <a href=#sticky-activation id=user-activation-data-model:sticky-activation-2>sticky activation</a> state spans multiple navigations as long as the same <code id=user-activation-data-model:document-4><a href=dom.html#document>Document</a></code> gets reused. For the transient activation state, the original <a href=#activation-expiry id=user-activation-data-model:activation-expiry>expiry</a> time remains unchanged (i.e., the state still expires within the <a href=#transient-activation-duration id=user-activation-data-model:transient-activation-duration-4>transient activation duration</a> limit from the original <a href=#activation-triggering-input-event id=user-activation-data-model:activation-triggering-input-event>activation triggering input event</a>). It is important to consider this when deciding whether to base certain things off <a href=#sticky-activation id=user-activation-data-model:sticky-activation-3>sticky activation</a> or <a href=#transient-activation id=user-activation-data-model:transient-activation-4>transient activation</a>.</p> <h4 id=user-activation-processing-model><span class=secno>6.4.2</span> Processing model<a href=#user-activation-processing-model class=self-link></a></h4> <p>When a user interaction causes firing of an <a href=#activation-triggering-input-event id=user-activation-processing-model:activation-triggering-input-event>activation triggering input event</a> in a <code id=user-activation-processing-model:document><a href=dom.html#document>Document</a></code> <var>document</var>, the user agent must perform the following <dfn id=activation-notification>activation notification</dfn> steps <em>before</em> <a href=https://dom.spec.whatwg.org/#concept-event-dispatch id=user-activation-processing-model:concept-event-dispatch data-x-internal=concept-event-dispatch>dispatching</a> the event:</p> <ol><li><p><a id=user-activation-processing-model:assert href=https://infra.spec.whatwg.org/#assert data-x-internal=assert>Assert</a>: <var>document</var> is <a id=user-activation-processing-model:fully-active href=document-sequences.html#fully-active>fully active</a>.<li><p>Let <var>windows</var> be « <var>document</var>'s <a id=user-activation-processing-model:concept-relevant-global href=webappapis.html#concept-relevant-global>relevant global object</a> ».<li><p><a href=https://infra.spec.whatwg.org/#list-extend id=user-activation-processing-model:list-extend data-x-internal=list-extend>Extend</a> <var>windows</var> with the <a href=document-sequences.html#nav-window id=user-activation-processing-model:nav-window>active window</a> of each of <var>document</var>'s <a id=user-activation-processing-model:ancestor-navigables href=document-sequences.html#ancestor-navigables>ancestor navigables</a>.<li><p><a href=https://infra.spec.whatwg.org/#list-extend id=user-activation-processing-model:list-extend-2 data-x-internal=list-extend>Extend</a> <var>windows</var> with the <a href=document-sequences.html#nav-window id=user-activation-processing-model:nav-window-2>active window</a> of each of <var>document</var>'s <a id=user-activation-processing-model:descendant-navigables href=document-sequences.html#descendant-navigables>descendant navigables</a>, filtered to include only those <a href=document-sequences.html#navigable id=user-activation-processing-model:navigable>navigables</a> whose <a href=document-sequences.html#nav-document id=user-activation-processing-model:nav-document>active document</a>'s <a href=https://dom.spec.whatwg.org/#concept-document-origin id=user-activation-processing-model:concept-document-origin data-x-internal=concept-document-origin>origin</a> is <a id=user-activation-processing-model:same-origin href=browsers.html#same-origin>same origin</a> with <var>document</var>'s <a href=https://dom.spec.whatwg.org/#concept-document-origin id=user-activation-processing-model:concept-document-origin-2 data-x-internal=concept-document-origin>origin</a>.<li> <p><a href=https://infra.spec.whatwg.org/#list-iterate id=user-activation-processing-model:list-iterate data-x-internal=list-iterate>For each</a> <var>window</var> in <var>windows</var>:</p> <ol><li><p>Set <var>window</var>'s <a href=#last-activation-timestamp id=user-activation-processing-model:last-activation-timestamp>last activation timestamp</a> to the <a id=user-activation-processing-model:current-high-resolution-time href=https://w3c.github.io/hr-time/#dfn-current-high-resolution-time data-x-internal=current-high-resolution-time>current high resolution time</a>.<li><p><a href=#notify-the-close-watcher-manager-about-user-activation id=user-activation-processing-model:notify-the-close-watcher-manager-about-user-activation>Notify the close watcher manager about user activation</a> given <var>window</var>.</ol> </ol> <p>An <dfn id=activation-triggering-input-event>activation triggering input event</dfn> is any event whose <code id=user-activation-processing-model:dom-event-istrusted><a data-x-internal=dom-event-istrusted href=https://dom.spec.whatwg.org/#dom-event-istrusted>isTrusted</a></code> attribute is true and whose <code id=user-activation-processing-model:dom-event-type><a data-x-internal=dom-event-type href=https://dom.spec.whatwg.org/#dom-event-type>type</a></code> is one of:</p> <ul><li><p>"<code id=user-activation-processing-model:event-keydown><a data-x-internal=event-keydown href=https://w3c.github.io/uievents/#event-type-keydown>keydown</a></code>", provided the key is neither the <kbd>Esc</kbd> key nor a shortcut key reserved by the user agent;<li><p>"<code id=user-activation-processing-model:event-mousedown><a data-x-internal=event-mousedown href=https://w3c.github.io/uievents/#event-type-mousedown>mousedown</a></code>";<li><p>"<code id=user-activation-processing-model:event-pointerdown><a data-x-internal=event-pointerdown href=https://w3c.github.io/pointerevents/#the-pointerdown-event>pointerdown</a></code>", provided the event's <code id=user-activation-processing-model:pointertype><a data-x-internal=pointertype href=https://w3c.github.io/pointerevents/#dom-pointerevent-pointertype>pointerType</a></code> is "<code>mouse</code>";<li><p>"<code id=user-activation-processing-model:event-pointerup><a data-x-internal=event-pointerup href=https://w3c.github.io/pointerevents/#the-pointerup-event>pointerup</a></code>", provided the event's <code id=user-activation-processing-model:pointertype-2><a data-x-internal=pointertype href=https://w3c.github.io/pointerevents/#dom-pointerevent-pointertype>pointerType</a></code> is not "<code>mouse</code>"; or<li><p>"<code id=user-activation-processing-model:event-touchend><a data-x-internal=event-touchend href=https://w3c.github.io/touch-events/#event-touchend>touchend</a></code>".</ul> <p><a href=#activation-consuming-api id=user-activation-processing-model:activation-consuming-api>Activation consuming APIs</a> defined in this and other specifications can <dfn id=consume-user-activation data-export="">consume user activation</dfn> by performing the following steps, given a <code id=user-activation-processing-model:window><a href=nav-history-apis.html#window>Window</a></code> <var>W</var>:</p> <ol><li><p>If <var>W</var>'s <a href=nav-history-apis.html#window-navigable id=user-activation-processing-model:window-navigable>navigable</a> is null, then return.<li><p>Let <var>top</var> be <var>W</var>'s <a href=nav-history-apis.html#window-navigable id=user-activation-processing-model:window-navigable-2>navigable</a>'s <a href=document-sequences.html#nav-top id=user-activation-processing-model:nav-top>top-level traversable</a>.<li><p>Let <var>navigables</var> be the <a id=user-activation-processing-model:inclusive-descendant-navigables href=document-sequences.html#inclusive-descendant-navigables>inclusive descendant navigables</a> of <var>top</var>'s <a href=document-sequences.html#nav-document id=user-activation-processing-model:nav-document-2>active document</a>.<li><p>Let <var>windows</var> be the list of <code id=user-activation-processing-model:window-2><a href=nav-history-apis.html#window>Window</a></code> objects constructed by taking the <a href=document-sequences.html#nav-window id=user-activation-processing-model:nav-window-3>active window</a> of each item in <var>navigables</var>.<li><p><a href=https://infra.spec.whatwg.org/#list-iterate id=user-activation-processing-model:list-iterate-2 data-x-internal=list-iterate>For each</a> <var>window</var> in <var>windows</var>, if <var>window</var>'s <a href=#last-activation-timestamp id=user-activation-processing-model:last-activation-timestamp-2>last activation timestamp</a> is not positive infinity, then set <var>window</var>'s <a href=#last-activation-timestamp id=user-activation-processing-model:last-activation-timestamp-3>last activation timestamp</a> to negative infinity.</ol> <p><a href=#history-action-activation-consuming-api id=user-activation-processing-model:history-action-activation-consuming-api>History-action activation-consuming APIs</a> can <dfn id=consume-history-action-user-activation>consume history-action user activation</dfn> by performing the following steps, given a <code id=user-activation-processing-model:window-3><a href=nav-history-apis.html#window>Window</a></code> <var>W</var>:</p> <ol><li><p>If <var>W</var>'s <a href=nav-history-apis.html#window-navigable id=user-activation-processing-model:window-navigable-3>navigable</a> is null, then return.<li><p>Let <var>top</var> be <var>W</var>'s <a href=nav-history-apis.html#window-navigable id=user-activation-processing-model:window-navigable-4>navigable</a>'s <a href=document-sequences.html#nav-top id=user-activation-processing-model:nav-top-2>top-level traversable</a>.<li><p>Let <var>navigables</var> be the <a id=user-activation-processing-model:inclusive-descendant-navigables-2 href=document-sequences.html#inclusive-descendant-navigables>inclusive descendant navigables</a> of <var>top</var>'s <a href=document-sequences.html#nav-document id=user-activation-processing-model:nav-document-3>active document</a>.<li><p>Let <var>windows</var> be the list of <code id=user-activation-processing-model:window-4><a href=nav-history-apis.html#window>Window</a></code> objects constructed by taking the <a href=document-sequences.html#nav-window id=user-activation-processing-model:nav-window-4>active window</a> of each item in <var>navigables</var>.<li><p><a href=https://infra.spec.whatwg.org/#list-iterate id=user-activation-processing-model:list-iterate-3 data-x-internal=list-iterate>For each</a> <var>window</var> in <var>windows</var>, set <var>window</var>'s <a href=#last-history-action-activation-timestamp id=user-activation-processing-model:last-history-action-activation-timestamp>last history-action activation timestamp</a> to <var>window</var>'s <a href=#last-activation-timestamp id=user-activation-processing-model:last-activation-timestamp-4>last activation timestamp</a>.</ol> <p class=note>Note the asymmetry in the sets of <a href=document-sequences.html#browsing-context id=user-activation-processing-model:browsing-context>browsing contexts</a> in the page that are affected by an <a href=#activation-notification id=user-activation-processing-model:activation-notification>activation notification</a> vs an <a href=#consume-user-activation id=user-activation-processing-model:consume-user-activation>activation consumption</a>: an activation consumption changes (to false) the <a href=#transient-activation id=user-activation-processing-model:transient-activation>transient activation</a> states for all browsing contexts in the page, but an activation notification changes (to true) the states for a subset of those browsing contexts. The exhaustive nature of consumption here is deliberate: it prevents malicious sites from making multiple calls to an <a href=#activation-consuming-api id=user-activation-processing-model:activation-consuming-api-2>activation consuming API</a> from a single user activation (possibly by exploiting a deep hierarchy of <code id=user-activation-processing-model:the-iframe-element><a href=iframe-embed-object.html#the-iframe-element>iframe</a></code>s).</p> <h4 id=user-activation-gated-apis><span class=secno>6.4.3</span> APIs gated by user activation<a href=#user-activation-gated-apis class=self-link></a></h4> <p>APIs that are dependent on user activation are classified into different levels:</p> <dl><dt><dfn id=sticky-activation-gated-api data-lt="sticky activation-gated API" data-export="">Sticky activation-gated APIs</dfn><dd><p>These APIs require the <a href=#sticky-activation id=user-activation-gated-apis:sticky-activation>sticky activation</a> state to be true, so they are blocked until the very first user activation.<dt><dfn id=transient-activation-gated-api data-lt="transient activation-gated API" data-export="">Transient activation-gated APIs</dfn><dd><p>These APIs require the <a href=#transient-activation id=user-activation-gated-apis:transient-activation>transient activation</a> state to be true, but they don't <a href=#consume-user-activation id=user-activation-gated-apis:consume-user-activation>consume</a> it, so multiple calls are allowed per user activation until the transient state <a href=#activation-expiry id=user-activation-gated-apis:activation-expiry>expires</a>.<dt><dfn id=activation-consuming-api data-lt="transient activation-consuming API" data-export="">Transient activation-consuming APIs</dfn><dd><p>These APIs require the <a href=#transient-activation id=user-activation-gated-apis:transient-activation-2>transient activation</a> state to be true, and they <a href=#consume-user-activation id=user-activation-gated-apis:consume-user-activation-2>consume user activation</a> in each call to prevent multiple calls per user activation.<dt><dfn id=history-action-activation-consuming-api data-lt="history-action activation-consuming API" data-export="">History-action activation-consuming APIs</dfn><dd><p>These APIs require the <a href=#history-action-activation id=user-activation-gated-apis:history-action-activation>history-action activation</a> state to be true, and they <a href=#consume-history-action-user-activation id=user-activation-gated-apis:consume-history-action-user-activation>consume history-action user activation</a> in each call to prevent multiple calls per user activation.</dl> <h4 id=the-useractivation-interface><span class=secno>6.4.4</span> The <code id=the-useractivation-interface:useractivation><a href=#useractivation>UserActivation</a></code> interface<a href=#the-useractivation-interface class=self-link></a></h4><div class="mdn-anno wrapped"><button onclick=toggleStatus(this) class=mdn-anno-btn><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/API/UserActivation title="The UserActivation interface allows querying information about a window's user activation state.">UserActivation</a><div class=support><span class="firefox no"><span>Firefox</span><span>No</span></span><span class="safari yes"><span>Safari</span><span>16.4+</span></span><span class="chrome yes"><span>Chrome</span><span>72+</span></span><hr><span class="opera unknown"><span>Opera</span><span>?</span></span><span class="edge_blink yes"><span>Edge</span><span>79+</span></span><hr><span class="edge unknown"><span>Edge (Legacy)</span><span>?</span></span><span class="ie no"><span>Internet Explorer</span><span>No</span></span><hr><span class="firefox_android unknown"><span>Firefox Android</span><span>?</span></span><span class="safari_ios unknown"><span>Safari iOS</span><span>?</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android unknown"><span>WebView Android</span><span>?</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android unknown"><span>Opera Android</span><span>?</span></span></div></div></div> <p>Each <code id=the-useractivation-interface:window><a href=nav-history-apis.html#window>Window</a></code> has an <dfn id=associated-useractivation>associated <code>UserActivation</code></dfn>, which is a <code id=the-useractivation-interface:useractivation-2><a href=#useractivation>UserActivation</a></code> object. Upon creation of the <code id=the-useractivation-interface:window-2><a href=nav-history-apis.html#window>Window</a></code> object, its <a href=#associated-useractivation id=the-useractivation-interface:associated-useractivation>associated <code>UserActivation</code></a> must be set to a <a id=the-useractivation-interface:new href=https://webidl.spec.whatwg.org/#new data-x-internal=new>new</a> <code id=the-useractivation-interface:useractivation-3><a href=#useractivation>UserActivation</a></code> object created in the <code id=the-useractivation-interface:window-3><a href=nav-history-apis.html#window>Window</a></code> object's <a href=webappapis.html#concept-relevant-realm id=the-useractivation-interface:concept-relevant-realm>relevant realm</a>.</p> <pre><code class='idl'>[<c- g>Exposed</c->=<c- n>Window</c->] <c- b>interface</c-> <dfn id='useractivation' data-dfn-type='interface'><c- g>UserActivation</c-></dfn> { <c- b>readonly</c-> <c- b>attribute</c-> <c- b>boolean</c-> <a href='#dom-useractivation-hasbeenactive' id='the-useractivation-interface:dom-useractivation-hasbeenactive'><c- g>hasBeenActive</c-></a>; <c- b>readonly</c-> <c- b>attribute</c-> <c- b>boolean</c-> <a href='#dom-useractivation-isactive' id='the-useractivation-interface:dom-useractivation-isactive'><c- g>isActive</c-></a>; }; <c- b>partial</c-> <c- b>interface</c-> <a id='NavigatorUserActivation-partial' href='system-state.html#navigator'><c- g>Navigator</c-></a> { [<c- g>SameObject</c->] <c- b>readonly</c-> <c- b>attribute</c-> <code id='the-useractivation-interface:useractivation-4'><a href='#useractivation'><c- n>UserActivation</c-></a></code> <a href='#dom-navigator-useractivation' id='the-useractivation-interface:dom-navigator-useractivation'><c- g>userActivation</c-></a>; };</code></pre> <dl class=domintro><dt><code><a href=system-state.html#dom-navigator id=the-useractivation-interface:dom-navigator>navigator</a>.<a href=#dom-navigator-useractivation id=dom-navigator-useractivation-dev>userActivation</a>.<a href=#dom-useractivation-hasbeenactive id=dom-useractivation-hasbeenactive-dev>hasBeenActive</a></code><dd> <p>Returns whether the window has <a href=#sticky-activation id=the-useractivation-interface:sticky-activation>sticky activation</a>.</p> <dt><code><a href=system-state.html#dom-navigator id=the-useractivation-interface:dom-navigator-2>navigator</a>.<a href=#dom-navigator-useractivation id=the-useractivation-interface:dom-navigator-useractivation-2>userActivation</a>.<a href=#dom-useractivation-isactive id=dom-useractivation-isactive-dev>isActive</a></code><dd> <p>Returns whether the window has <a href=#transient-activation id=the-useractivation-interface:transient-activation>transient activation</a>.</p> </dl> <div class="mdn-anno wrapped before"><button onclick=toggleStatus(this) class=mdn-anno-btn><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/API/Navigator/userActivation title="The read-only userActivation property of the Navigator interface returns a UserActivation object which contains information about the current window's user activation state.">Navigator/userActivation</a><div class=support><span class="firefox no"><span>Firefox</span><span>No</span></span><span class="safari yes"><span>Safari</span><span>16.4+</span></span><span class="chrome yes"><span>Chrome</span><span>72+</span></span><hr><span class="opera unknown"><span>Opera</span><span>?</span></span><span class="edge_blink yes"><span>Edge</span><span>79+</span></span><hr><span class="edge unknown"><span>Edge (Legacy)</span><span>?</span></span><span class="ie no"><span>Internet Explorer</span><span>No</span></span><hr><span class="firefox_android unknown"><span>Firefox Android</span><span>?</span></span><span class="safari_ios unknown"><span>Safari iOS</span><span>?</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android unknown"><span>WebView Android</span><span>?</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android unknown"><span>Opera Android</span><span>?</span></span></div></div></div><p>The <dfn data-dfn-for=Navigator id=dom-navigator-useractivation data-dfn-type=attribute><code>userActivation</code></dfn> getter steps are to return <a id=the-useractivation-interface:this href=https://webidl.spec.whatwg.org/#this data-x-internal=this>this</a>'s <a id=the-useractivation-interface:concept-relevant-global href=webappapis.html#concept-relevant-global>relevant global object</a>'s <a href=#associated-useractivation id=the-useractivation-interface:associated-useractivation-2>associated <code>UserActivation</code></a>.</p> <div class="mdn-anno wrapped before"><button onclick=toggleStatus(this) class=mdn-anno-btn><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/API/UserActivation/hasBeenActive title="The read-only hasBeenActive property of the UserActivation interface indicates whether the current window has sticky user activation (see sticky activation).">UserActivation/hasBeenActive</a><div class=support><span class="firefox no"><span>Firefox</span><span>No</span></span><span class="safari yes"><span>Safari</span><span>16.4+</span></span><span class="chrome yes"><span>Chrome</span><span>72+</span></span><hr><span class="opera unknown"><span>Opera</span><span>?</span></span><span class="edge_blink yes"><span>Edge</span><span>79+</span></span><hr><span class="edge unknown"><span>Edge (Legacy)</span><span>?</span></span><span class="ie no"><span>Internet Explorer</span><span>No</span></span><hr><span class="firefox_android unknown"><span>Firefox Android</span><span>?</span></span><span class="safari_ios unknown"><span>Safari iOS</span><span>?</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android unknown"><span>WebView Android</span><span>?</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android unknown"><span>Opera Android</span><span>?</span></span></div></div></div><p>The <dfn data-dfn-for=UserActivation id=dom-useractivation-hasbeenactive data-dfn-type=attribute><code>hasBeenActive</code></dfn> getter steps are to return true if <a id=the-useractivation-interface:this-2 href=https://webidl.spec.whatwg.org/#this data-x-internal=this>this</a>'s <a id=the-useractivation-interface:concept-relevant-global-2 href=webappapis.html#concept-relevant-global>relevant global object</a> has <a href=#sticky-activation id=the-useractivation-interface:sticky-activation-2>sticky activation</a>, and false otherwise.</p> <div class="mdn-anno wrapped before"><button onclick=toggleStatus(this) class=mdn-anno-btn><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/API/UserActivation/hasBeenActive title="The read-only hasBeenActive property of the UserActivation interface indicates whether the current window has sticky user activation (see sticky activation).">UserActivation/hasBeenActive</a><div class=support><span class="firefox no"><span>Firefox</span><span>No</span></span><span class="safari yes"><span>Safari</span><span>16.4+</span></span><span class="chrome yes"><span>Chrome</span><span>72+</span></span><hr><span class="opera unknown"><span>Opera</span><span>?</span></span><span class="edge_blink yes"><span>Edge</span><span>79+</span></span><hr><span class="edge unknown"><span>Edge (Legacy)</span><span>?</span></span><span class="ie no"><span>Internet Explorer</span><span>No</span></span><hr><span class="firefox_android unknown"><span>Firefox Android</span><span>?</span></span><span class="safari_ios unknown"><span>Safari iOS</span><span>?</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android unknown"><span>WebView Android</span><span>?</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android unknown"><span>Opera Android</span><span>?</span></span></div></div></div><p>The <dfn data-dfn-for=UserActivation id=dom-useractivation-isactive data-dfn-type=attribute><code>isActive</code></dfn> getter steps are to return true if <a id=the-useractivation-interface:this-3 href=https://webidl.spec.whatwg.org/#this data-x-internal=this>this</a>'s <a id=the-useractivation-interface:concept-relevant-global-3 href=webappapis.html#concept-relevant-global>relevant global object</a> has <a href=#transient-activation id=the-useractivation-interface:transient-activation-2>transient activation</a>, and false otherwise.</p> <h4 id=user-activation-user-agent-automation><span class=secno>6.4.5</span> User agent automation<a href=#user-activation-user-agent-automation class=self-link></a></h4> <p>For the purposes of user-agent automation and application testing, this specification defines the following <a id=user-activation-user-agent-automation:extension-command href=https://w3c.github.io/webdriver/#dfn-extension-commands data-x-internal=extension-command>extension command</a> for the <cite>Web Driver</cite> specification. It is optional for a user agent to support the following <a id=user-activation-user-agent-automation:extension-command-2 href=https://w3c.github.io/webdriver/#dfn-extension-commands data-x-internal=extension-command>extension command</a>. <a href=references.html#refsWEBDRIVER>[WEBDRIVER]</a></p> <table class=data><thead><tr><th>HTTP Method<th>URI Template<tbody><tr><td>`<code>POST</code>`<td><code>/session/{<var>session id</var>}/window/consume-user-activation</code></table> <p>The <a id=user-activation-user-agent-automation:remote-end-steps href=https://w3c.github.io/webdriver/#dfn-remote-end-steps data-x-internal=remote-end-steps>remote end steps</a> are:</p> <ol><li><p>Let <var>window</var> be <a href=https://w3c.github.io/webdriver/#dfn-current-browsing-context id=user-activation-user-agent-automation:webdriver-current-browsing-context data-x-internal=webdriver-current-browsing-context>current browsing context</a>'s <a id=user-activation-user-agent-automation:active-window href=document-sequences.html#active-window>active window</a>.<li><p>Let <var>consume</var> be true if <var>window</var> has <a href=#transient-activation id=user-activation-user-agent-automation:transient-activation>transient activation</a>; otherwise false.<li><p>If <var>consume</var> is true, then <a href=#consume-user-activation id=user-activation-user-agent-automation:consume-user-activation>consume user activation</a> of <var>window</var>.<li><p>Return <a href=https://w3c.github.io/webdriver/#dfn-success id=user-activation-user-agent-automation:success-value data-x-internal=success-value>success</a> with data <var>consume</var>.</ol> <h3 id=activation><span class=secno>6.5</span> Activation behavior of elements<a href=#activation class=self-link></a></h3> <p>Certain elements in HTML have an <a id=activation:activation-behaviour href=https://dom.spec.whatwg.org/#eventtarget-activation-behavior data-x-internal=activation-behaviour>activation behavior</a>, which means that the user can activate them. This is always caused by a <code id=activation:event-click><a data-x-internal=event-click href=https://w3c.github.io/uievents/#event-type-click>click</a></code> event.</p> <p>The user agent should allow the user to manually trigger elements that have an <a id=activation:activation-behaviour-2 href=https://dom.spec.whatwg.org/#eventtarget-activation-behavior data-x-internal=activation-behaviour>activation behavior</a>, for instance using keyboard or voice input, or through mouse clicks. When the user triggers an element with a defined <a id=activation:activation-behaviour-3 href=https://dom.spec.whatwg.org/#eventtarget-activation-behavior data-x-internal=activation-behaviour>activation behavior</a> in a manner other than clicking it, the default action of the interaction event must be to <a id=activation:fire-a-click-event href=webappapis.html#fire-a-click-event>fire a <code>click</code> event</a> at the element.</p> <dl class=domintro><dt><code><var>element</var>.<a href=#dom-click id=dom-click-dev>click</a>()</code><div class="mdn-anno wrapped before"><button onclick=toggleStatus(this) class=mdn-anno-btn><b title="Support in all current engines." class=all-engines-flag>✔</b><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click title="The HTMLElement.click() method simulates a mouse click on an element.">HTMLElement/click</a><p class=all-engines-text>Support in all current engines.<div class=support><span class="firefox yes"><span>Firefox</span><span>3+</span></span><span class="safari yes"><span>Safari</span><span>6+</span></span><span class="chrome yes"><span>Chrome</span><span>9+</span></span><hr><span class="opera yes"><span>Opera</span><span>10.5+</span></span><span class="edge_blink yes"><span>Edge</span><span>79+</span></span><hr><span class="edge yes"><span>Edge (Legacy)</span><span>12+</span></span><span class="ie yes"><span>Internet Explorer</span><span>5.5+</span></span><hr><span class="firefox_android yes"><span>Firefox Android</span><span>4+</span></span><span class="safari_ios unknown"><span>Safari iOS</span><span>?</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android yes"><span>WebView Android</span><span>4.4+</span></span><span class="samsunginternet_android yes"><span>Samsung Internet</span><span>1.0+</span></span><span class="opera_android yes"><span>Opera Android</span><span>11+</span></span></div></div></div><dd><p>Acts as if the element was clicked.</dl> <p>Each element has an associated <dfn id=click-in-progress-flag>click in progress flag</dfn>, which is initially unset.</p> <p>The <dfn data-dfn-for=HTMLElement id=dom-click data-dfn-type=method><code>click()</code></dfn> method must run the following steps:</p> <ol><li><p>If this element is a form control that is <a href=form-control-infrastructure.html#concept-fe-disabled id=activation:concept-fe-disabled>disabled</a>, then return.<li><p>If this element's <a href=#click-in-progress-flag id=activation:click-in-progress-flag>click in progress flag</a> is set, then return.<li><p>Set this element's <a href=#click-in-progress-flag id=activation:click-in-progress-flag-2>click in progress flag</a>.<li><p><a id=activation:fire-a-synthetic-pointer-event href=webappapis.html#fire-a-synthetic-pointer-event>Fire a synthetic pointer event</a> named <code id=activation:event-click-2><a data-x-internal=event-click href=https://w3c.github.io/uievents/#event-type-click>click</a></code> at this element, with the <var>not trusted flag</var> set.<li><p>Unset this element's <a href=#click-in-progress-flag id=activation:click-in-progress-flag-3>click in progress flag</a>.</ol> <h4 id=the-toggleevent-interface><span class=secno>6.5.1</span> The <code id=the-toggleevent-interface:toggleevent><a href=#toggleevent>ToggleEvent</a></code> interface<a href=#the-toggleevent-interface class=self-link></a></h4> <div class="mdn-anno wrapped before"><button onclick=toggleStatus(this) class=mdn-anno-btn><b title="Support in all current engines." class=all-engines-flag>✔</b><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/API/ToggleEvent/ToggleEvent title="The ToggleEvent() constructor creates a new ToggleEvent object.">ToggleEvent/ToggleEvent</a><p class=all-engines-text>Support in all current engines.<div class=support><span class="firefox yes"><span>Firefox</span><span title="Requires setting a user preference or runtime flag.">🔰 114+</span></span><span class="safari yes"><span>Safari</span><span>17+</span></span><span class="chrome yes"><span>Chrome</span><span>114+</span></span><hr><span class="opera unknown"><span>Opera</span><span>?</span></span><span class="edge_blink yes"><span>Edge</span><span>114+</span></span><hr><span class="edge unknown"><span>Edge (Legacy)</span><span>?</span></span><span class="ie no"><span>Internet Explorer</span><span>No</span></span><hr><span class="firefox_android unknown"><span>Firefox Android</span><span>?</span></span><span class="safari_ios unknown"><span>Safari iOS</span><span>?</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android unknown"><span>WebView Android</span><span>?</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android unknown"><span>Opera Android</span><span>?</span></span></div></div><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/API/ToggleEvent title="The ToggleEvent interface represents an event notifying the user when a popover element's state toggles between showing and hidden.">ToggleEvent</a><p class=all-engines-text>Support in all current engines.<div class=support><span class="firefox yes"><span>Firefox</span><span title="Requires setting a user preference or runtime flag.">🔰 114+</span></span><span class="safari yes"><span>Safari</span><span>17+</span></span><span class="chrome yes"><span>Chrome</span><span>114+</span></span><hr><span class="opera unknown"><span>Opera</span><span>?</span></span><span class="edge_blink yes"><span>Edge</span><span>114+</span></span><hr><span class="edge unknown"><span>Edge (Legacy)</span><span>?</span></span><span class="ie no"><span>Internet Explorer</span><span>No</span></span><hr><span class="firefox_android unknown"><span>Firefox Android</span><span>?</span></span><span class="safari_ios unknown"><span>Safari iOS</span><span>?</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android unknown"><span>WebView Android</span><span>?</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android unknown"><span>Opera Android</span><span>?</span></span></div></div></div><pre><code class='idl'>[<c- g>Exposed</c->=<c- n>Window</c->] <c- b>interface</c-> <dfn id='toggleevent' data-dfn-type='interface'><c- g>ToggleEvent</c-></dfn> : <a id='the-toggleevent-interface:event' href='https://dom.spec.whatwg.org/#interface-event' data-x-internal='event'><c- n>Event</c-></a> { <c- g>constructor</c->(<c- b>DOMString</c-> <c- g>type</c->, <c- b>optional</c-> <a href='#toggleeventinit' id='the-toggleevent-interface:toggleeventinit'><c- n>ToggleEventInit</c-></a> <c- g>eventInitDict</c-> = {}); <c- b>readonly</c-> <c- b>attribute</c-> <c- b>DOMString</c-> <c- g>oldState</c->; <c- b>readonly</c-> <c- b>attribute</c-> <c- b>DOMString</c-> <c- g>newState</c->; }; <c- b>dictionary</c-> <dfn id='toggleeventinit' data-dfn-type='dictionary'><c- g>ToggleEventInit</c-></dfn> : <a id='the-toggleevent-interface:eventinit' href='https://dom.spec.whatwg.org/#dictdef-eventinit' data-x-internal='eventinit'><c- n>EventInit</c-></a> { <c- b>DOMString</c-> <c- g>oldState</c-> = &quot;&quot;; <c- b>DOMString</c-> <c- g>newState</c-> = &quot;&quot;; };</code></pre> <dl class=domintro><dt><code><var>event</var>.<a href=#dom-toggleevent-oldstate id=dom-toggleevent-oldstate-dev>oldState</a></code><dd> <p>Set to "<code>closed</code>" when transitioning from closed to open, or set to "<code>open</code>" when transitioning from open to closed.</p> <dt><code><var>event</var>.<a href=#dom-toggleevent-newstate id=dom-toggleevent-newstate-dev>newState</a></code><dd> <p>Set to "<code>open</code>" when transitioning from closed to open, or set to "<code>closed</code>" when transitioning from open to closed.</p> </dl> <div class="mdn-anno wrapped before"><button onclick=toggleStatus(this) class=mdn-anno-btn><b title="Support in all current engines." class=all-engines-flag>✔</b><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/API/ToggleEvent/oldState title="The oldState read-only property of the ToggleEvent interface is a string representing the state the element is transitioning from.">ToggleEvent/oldState</a><p class=all-engines-text>Support in all current engines.<div class=support><span class="firefox yes"><span>Firefox</span><span title="Requires setting a user preference or runtime flag.">🔰 114+</span></span><span class="safari yes"><span>Safari</span><span>17+</span></span><span class="chrome yes"><span>Chrome</span><span>114+</span></span><hr><span class="opera unknown"><span>Opera</span><span>?</span></span><span class="edge_blink yes"><span>Edge</span><span>114+</span></span><hr><span class="edge unknown"><span>Edge (Legacy)</span><span>?</span></span><span class="ie no"><span>Internet Explorer</span><span>No</span></span><hr><span class="firefox_android unknown"><span>Firefox Android</span><span>?</span></span><span class="safari_ios unknown"><span>Safari iOS</span><span>?</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android unknown"><span>WebView Android</span><span>?</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android unknown"><span>Opera Android</span><span>?</span></span></div></div><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/API/ToggleEvent/newState title="The newState read-only property of the ToggleEvent interface is a string representing the state the element is transitioning to.">ToggleEvent/newState</a><p class=all-engines-text>Support in all current engines.<div class=support><span class="firefox yes"><span>Firefox</span><span title="Requires setting a user preference or runtime flag.">🔰 114+</span></span><span class="safari yes"><span>Safari</span><span>17+</span></span><span class="chrome yes"><span>Chrome</span><span>114+</span></span><hr><span class="opera unknown"><span>Opera</span><span>?</span></span><span class="edge_blink yes"><span>Edge</span><span>114+</span></span><hr><span class="edge unknown"><span>Edge (Legacy)</span><span>?</span></span><span class="ie no"><span>Internet Explorer</span><span>No</span></span><hr><span class="firefox_android unknown"><span>Firefox Android</span><span>?</span></span><span class="safari_ios unknown"><span>Safari iOS</span><span>?</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android unknown"><span>WebView Android</span><span>?</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android unknown"><span>Opera Android</span><span>?</span></span></div></div></div><p>The <dfn data-dfn-for=ToggleEvent id=dom-toggleevent-oldstate data-dfn-type=attribute><code>oldState</code></dfn> and <dfn data-dfn-for=ToggleEvent id=dom-toggleevent-newstate data-dfn-type=attribute><code>newState</code></dfn> attributes must return the values they are initialized to.</p> <p>A <dfn id=toggle-task-tracker>toggle task tracker</dfn> is a <a id=the-toggleevent-interface:struct href=https://infra.spec.whatwg.org/#struct data-x-internal=struct>struct</a> which has:</p> <dl><dt><dfn id=toggle-task-task>task</dfn><dd>A <a href=webappapis.html#concept-task id=the-toggleevent-interface:concept-task>task</a> which fires a <code id=the-toggleevent-interface:toggleevent-2><a href=#toggleevent>ToggleEvent</a></code>.<dt><dfn id=toggle-task-old-state>old state</dfn><dd>A string which represents the <a href=#toggle-task-task id=the-toggleevent-interface:toggle-task-task>task</a>'s event's value for the <code id=the-toggleevent-interface:dom-toggleevent-oldstate><a href=#dom-toggleevent-oldstate>oldState</a></code> attribute.</dl> <h3 id=focus><span class=secno>6.6</span> Focus<a href=#focus class=self-link></a></h3> <h4 id=introduction-8><span class=secno>6.6.1</span> Introduction<a href=#introduction-8 class=self-link></a></h4> <p><i>This section is non-normative.</i></p> <p>An HTML user interface typically consists of multiple interactive widgets, such as form controls, scrollable regions, links, dialog boxes, browser tabs, and so forth. These widgets form a hierarchy, with some (e.g. browser tabs, dialog boxes) containing others (e.g. links, form controls).</p> <p>When interacting with an interface using a keyboard, key input is channeled from the system, through the hierarchy of interactive widgets, to an active widget, which is said to be <a href=#focused id=introduction-8:focused>focused</a>.</p> <div class=example> <p>Consider an HTML application running in a browser tab running in a graphical environment. Suppose this application had a page with some text controls and links, and was currently showing a modal dialog, which itself had a text control and a button.</p> <p>The hierarchy of focusable widgets, in this scenario, would include the browser window, which would have, amongst its children, the browser tab containing the HTML application. The tab itself would have as its children the various links and text controls, as well as the dialog. The dialog itself would have as its children the text control and the button.</p> <p><img width=800 src=/images/focus-tree.png height=450 alt=""> <p>If the widget with <a href=#focused id=introduction-8:focused-2>focus</a> in this example was the text control in the dialog box, then key input would be channeled from the graphical system to ① the web browser, then to ② the tab, then to ③ the dialog, and finally to ④ the text control.</p> </div> <p>Keyboard <em>events</em> are always targeted at this <a href=#focused id=introduction-8:focused-3>focused</a> element.</p> <h4 id=data-model><span class=secno>6.6.2</span> Data model<a href=#data-model class=self-link></a></h4> <p id=tlbc-system-focus>A <a id=data-model:top-level-traversable href=document-sequences.html#top-level-traversable>top-level traversable</a> has <dfn data-dfn-for="top-level traversable" id=system-focus data-export="">system focus</dfn> when it can receive keyboard input channeled from the operating system, possibly targeted at one of its <a href=document-sequences.html#nav-document id=data-model:nav-document>active document</a>'s <a id=data-model:descendant-navigables href=document-sequences.html#descendant-navigables>descendant navigables</a>.</p> <p>A <a id=data-model:top-level-traversable-2 href=document-sequences.html#top-level-traversable>top-level traversable</a> has <dfn data-dfn-for="top-level traversable" id=user-attention>user attention</dfn> when its <a id=data-model:system-visibility-state href=document-sequences.html#system-visibility-state>system visibility state</a> is "<code>visible</code>", and it either has <a href=#system-focus id=data-model:system-focus>system focus</a> or user agent widgets directly related to it can receive keyboard input channeled from the operating system.</p> <p class=note>User attention is lost when a browser window loses focus, whereas system focus might also be lost to other system widgets in the browser window such as a location bar.</p> <p>A <code id=data-model:document><a href=dom.html#document>Document</a></code> <var>d</var> is a <dfn data-dfn-for=Document id=fully-active-descendant-of-a-top-level-traversable-with-user-attention data-export="">fully active descendant of a top-level traversable with user attention</dfn> when <var>d</var> is <a id=data-model:fully-active href=document-sequences.html#fully-active>fully active</a> and <var>d</var>'s <a id=data-model:node-navigable href=document-sequences.html#node-navigable>node navigable</a>'s <a href=document-sequences.html#nav-top id=data-model:nav-top>top-level traversable</a> has <a href=#user-attention id=data-model:user-attention>user attention</a>.</p> <p>The term <dfn id=focusable-area>focusable area</dfn> is used to refer to regions of the interface that can further become the target of such keyboard input. Focusable areas can be elements, parts of elements, or other regions managed by the user agent.</p> <p>Each <a href=#focusable-area id=data-model:focusable-area>focusable area</a> has a <dfn id=dom-anchor>DOM anchor</dfn>, which is a <code id=data-model:node><a data-x-internal=node href=https://dom.spec.whatwg.org/#interface-node>Node</a></code> object that represents the position of the <a href=#focusable-area id=data-model:focusable-area-2>focusable area</a> in the DOM. (When the <a href=#focusable-area id=data-model:focusable-area-3>focusable area</a> is itself a <code id=data-model:node-2><a data-x-internal=node href=https://dom.spec.whatwg.org/#interface-node>Node</a></code>, it is its own <a href=#dom-anchor id=data-model:dom-anchor>DOM anchor</a>.) The <a href=#dom-anchor id=data-model:dom-anchor-2>DOM anchor</a> is used in some APIs as a substitute for the <a href=#focusable-area id=data-model:focusable-area-4>focusable area</a> when there is no other DOM object to represent the <a href=#focusable-area id=data-model:focusable-area-5>focusable area</a>.</p> <p>The following table describes what objects can be <a href=#focusable-area id=data-model:focusable-area-6>focusable areas</a>. The cells in the left column describe objects that can be <a href=#focusable-area id=data-model:focusable-area-7>focusable areas</a>; the cells in the right column describe the <a href=#dom-anchor id=data-model:dom-anchor-3>DOM anchors</a> for those elements. (The cells that span both columns are non-normative examples.)</p> <table id=table-fa><thead><tr><th id=th-fa-area><a href=#focusable-area id=data-model:focusable-area-8>Focusable area</a> <th id=th-fa-dom-rep><a href=#dom-anchor id=data-model:dom-anchor-4>DOM anchor</a> <tr><th colspan=2 id=th-fa-examples>Examples <tbody><tr><th headers=th-fa-area id=td-fa-1 class=data-header> Elements that meet all the following criteria: <ul class=brief><li>the element's <a href=#tabindex-value id=data-model:tabindex-value>tabindex value</a> is non-null, or the element is determined by the user agent to be focusable;<li>the element is either not a <a id=data-model:shadow-host href=https://dom.spec.whatwg.org/#element-shadow-host data-x-internal=shadow-host>shadow host</a>, or has a <a href=https://dom.spec.whatwg.org/#concept-element-shadow-root id=data-model:concept-element-shadow-root data-x-internal=concept-element-shadow-root>shadow root</a> whose <a id=data-model:delegates-focus href=https://dom.spec.whatwg.org/#shadowroot-delegates-focus data-x-internal=delegates-focus>delegates focus</a> is false;<li>the element is not <a href=semantics-other.html#concept-element-disabled id=data-model:concept-element-disabled>actually disabled</a>;<li>the element is not <a href=#inert id=data-model:inert>inert</a>;<li>the element is either <a id=data-model:being-rendered href=rendering.html#being-rendered>being rendered</a>, <a id=data-model:delegating-its-rendering-to-its-children href=rendering.html#delegating-its-rendering-to-its-children>delegating its rendering to its children</a>, or <a id=data-model:being-used-as-relevant-canvas-fallback-content href=canvas.html#being-used-as-relevant-canvas-fallback-content>being used as relevant canvas fallback content</a>.</ul> <td headers="td-fa-1 th-fa-dom-rep"> The element itself. <tr><td colspan=2 headers="td-fa-1 th-fa-examples"> <p class=example><code id=data-model:the-iframe-element><a href=iframe-embed-object.html#the-iframe-element>iframe</a></code>, <code id=data-model:the-dialog-element><a href=interactive-elements.html#the-dialog-element>dialog</a></code>, <code id="data-model:text-(type=text)-state-and-search-state-(type=search)"><a href="input.html#text-(type=text)-state-and-search-state-(type=search)">&lt;input type=text></a></code>, sometimes <code id=data-model:the-a-element><a href=text-level-semantics.html#the-a-element>&lt;a href=""></a></code> (depending on platform conventions). <tbody><tr><th headers=th-fa-area id=td-fa-2 class=data-header> The shapes of <code id=data-model:the-area-element><a href=image-maps.html#the-area-element>area</a></code> elements in an <a id=data-model:image-map href=image-maps.html#image-map>image map</a> associated with an <code id=data-model:the-img-element><a href=embedded-content.html#the-img-element>img</a></code> element that is <a id=data-model:being-rendered-2 href=rendering.html#being-rendered>being rendered</a> and is not <a href=#inert id=data-model:inert-2>inert</a>. <td headers="td-fa-2 th-fa-dom-rep"> The <code id=data-model:the-img-element-2><a href=embedded-content.html#the-img-element>img</a></code> element. <tr><td colspan=2 headers="td-fa-2 th-fa-examples"> <div class=example> <p>In the following example, the <code id=data-model:the-area-element-2><a href=image-maps.html#the-area-element>area</a></code> element creates two shapes, one on each image. The <a href=#dom-anchor id=data-model:dom-anchor-5>DOM anchor</a> of the first shape is the first <code id=data-model:the-img-element-3><a href=embedded-content.html#the-img-element>img</a></code> element, and the <a href=#dom-anchor id=data-model:dom-anchor-6>DOM anchor</a> of the second shape is the second <code id=data-model:the-img-element-4><a href=embedded-content.html#the-img-element>img</a></code> element.</p> <pre><code class='html'><c- p>&lt;</c-><c- f>map</c-> <c- e>id</c-><c- o>=</c-><c- s>wallmap</c-><c- p>&gt;&lt;</c-><c- f>area</c-> <c- e>alt</c-><c- o>=</c-><c- s>&quot;Enter Door&quot;</c-> <c- e>coords</c-><c- o>=</c-><c- s>&quot;10,10,100,200&quot;</c-> <c- e>href</c-><c- o>=</c-><c- s>&quot;door.html&quot;</c-><c- p>&gt;&lt;/</c-><c- f>map</c-><c- p>&gt;</c-> ... <c- p>&lt;</c-><c- f>img</c-> <c- e>src</c-><c- o>=</c-><c- s>&quot;images/innerwall.jpeg&quot;</c-> <c- e>alt</c-><c- o>=</c-><c- s>&quot;There is a white wall here, with a door.&quot;</c-> <c- e>usemap</c-><c- o>=</c-><c- s>&quot;#wallmap&quot;</c-><c- p>&gt;</c-> ... <c- p>&lt;</c-><c- f>img</c-> <c- e>src</c-><c- o>=</c-><c- s>&quot;images/outerwall.jpeg&quot;</c-> <c- e>alt</c-><c- o>=</c-><c- s>&quot;There is a red wall here, with a door.&quot;</c-> <c- e>usemap</c-><c- o>=</c-><c- s>&quot;#wallmap&quot;</c-><c- p>&gt;</c-></code></pre> </div> <tbody><tr><th headers=th-fa-area id=td-fa-3 class=data-header> The user-agent provided subwidgets of elements that are <a id=data-model:being-rendered-3 href=rendering.html#being-rendered>being rendered</a> and are not <a href=semantics-other.html#concept-element-disabled id=data-model:concept-element-disabled-2>actually disabled</a> or <a href=#inert id=data-model:inert-3>inert</a>. <td headers="td-fa-3 th-fa-dom-rep"> The element for which the <a href=#focusable-area id=data-model:focusable-area-9>focusable area</a> is a subwidget. <tr><td colspan=2 headers="td-fa-3 th-fa-examples"> <p class=example>The <a href=media.html#expose-a-user-interface-to-the-user id=data-model:expose-a-user-interface-to-the-user>controls in the user interface</a> for a <code id=data-model:the-video-element><a href=media.html#the-video-element>video</a></code> element, the up and down buttons in a spin-control version of <code id="data-model:number-state-(type=number)"><a href="input.html#number-state-(type=number)">&lt;input type=number></a></code>, the part of a <code id=data-model:the-details-element><a href=interactive-elements.html#the-details-element>details</a></code> element's rendering that enables the element to be opened or closed using keyboard input.</p> <tbody><tr><th headers=th-fa-area id=td-fa-4 class=data-header> The scrollable regions of elements that are <a id=data-model:being-rendered-4 href=rendering.html#being-rendered>being rendered</a> and are not <a href=#inert id=data-model:inert-4>inert</a>. <td headers="td-fa-4 th-fa-dom-rep"> The element for which the box that the scrollable region scrolls was created. <tr><td colspan=2 headers="td-fa-4 th-fa-examples"> <p class=example>The CSS <a id="data-model:'overflow'" href=https://drafts.csswg.org/css-overflow/#propdef-overflow data-x-internal="'overflow'">'overflow'</a> property's 'scroll' value typically creates a scrollable region.</p> <tbody><tr><th headers=th-fa-area id=td-fa-5 class=data-header> The <a id=data-model:viewport href=https://drafts.csswg.org/css2/#viewport data-x-internal=viewport>viewport</a> of a <code id=data-model:document-2><a href=dom.html#document>Document</a></code> that has a non-null <a href=document-sequences.html#concept-document-bc id=data-model:concept-document-bc>browsing context</a> and is not <a href=#inert id=data-model:inert-5>inert</a>. <td headers="td-fa-5 th-fa-dom-rep"> The <code id=data-model:document-3><a href=dom.html#document>Document</a></code> for which the <a id=data-model:viewport-2 href=https://drafts.csswg.org/css2/#viewport data-x-internal=viewport>viewport</a> was created. <tr><td colspan=2 headers="td-fa-5 th-fa-examples"> <p class=example>The contents of an <code id=data-model:the-iframe-element-2><a href=iframe-embed-object.html#the-iframe-element>iframe</a></code>.</p> <tbody><tr><th headers=th-fa-area id=td-fa-6 class=data-header> Any other element or part of an element determined by the user agent to be a focusable area, especially to aid with accessibility or to better match platform conventions. <td headers="td-fa-6 th-fa-dom-rep"> The element. <tr><td colspan=2 headers="td-fa-6 th-fa-examples"> <p class=example>A user agent could make all list item bullets <a href=#sequentially-focusable id=data-model:sequentially-focusable>sequentially focusable</a>, so that a user can more easily navigate lists.</p> <p class=example>Similarly, a user agent could make all elements with <code id=data-model:attr-title><a href=dom.html#attr-title>title</a></code> attributes <a href=#sequentially-focusable id=data-model:sequentially-focusable-2>sequentially focusable</a>, so that their advisory information can be accessed.</p> </table> <p id=bc-focus-ergo-bcc-focus class=note>A <a id=data-model:navigable-container href=document-sequences.html#navigable-container>navigable container</a> (e.g. an <code id=data-model:the-iframe-element-3><a href=iframe-embed-object.html#the-iframe-element>iframe</a></code>) is a <a href=#focusable-area id=data-model:focusable-area-10>focusable area</a>, but key events routed to a <a id=data-model:navigable-container-2 href=document-sequences.html#navigable-container>navigable container</a> get immediately routed to its <a id=data-model:content-navigable href=document-sequences.html#content-navigable>content navigable</a>'s <a href=document-sequences.html#nav-document id=data-model:nav-document-2>active document</a>. Similarly, in sequential focus navigation a <a id=data-model:navigable-container-3 href=document-sequences.html#navigable-container>navigable container</a> essentially acts merely as a placeholder for its <a id=data-model:content-navigable-2 href=document-sequences.html#content-navigable>content navigable</a>'s <a href=document-sequences.html#nav-document id=data-model:nav-document-3>active document</a>.</p> <hr> <p>One <a href=#focusable-area id=data-model:focusable-area-11>focusable area</a> in each <code id=data-model:document-4><a href=dom.html#document>Document</a></code> is designated the <dfn id=focused-area-of-the-document>focused area of the document</dfn>. Which control is so designated changes over time, based on algorithms in this specification.</p> <p class=note>Even if a document is not <a id=data-model:fully-active-2 href=document-sequences.html#fully-active>fully active</a> and not shown to the user, it can still have a <a href=#focused-area-of-the-document id=data-model:focused-area-of-the-document>focused area of the document</a>. If a document's <a id=data-model:fully-active-3 href=document-sequences.html#fully-active>fully active</a> state changes, its <a href=#focused-area-of-the-document id=data-model:focused-area-of-the-document-2>focused area of the document</a> will stay the same.</p> <p id=currently-focused-area-of-a-top-level-browsing-context>The <dfn id=currently-focused-area-of-a-top-level-traversable>currently focused area of a top-level traversable</dfn> <var>traversable</var> is the <a href=#focusable-area id=data-model:focusable-area-12>focusable area</a>-or-null returned by this algorithm:</p> <ol><li><p>If <var>traversable</var> does not have <a href=#system-focus id=data-model:system-focus-2>system focus</a>, then return null.<li><p>Let <var>candidate</var> be <var>traversable</var>'s <a href=document-sequences.html#nav-document id=data-model:nav-document-4>active document</a>.<li><p>While <var>candidate</var>'s <a href=#focused-area-of-the-document id=data-model:focused-area-of-the-document-3>focused area</a> is a <a id=data-model:navigable-container-4 href=document-sequences.html#navigable-container>navigable container</a> with a non-null <a id=data-model:content-navigable-3 href=document-sequences.html#content-navigable>content navigable</a>: set <var>candidate</var> to the <a href=document-sequences.html#nav-document id=data-model:nav-document-5>active document</a> of that <a id=data-model:navigable-container-5 href=document-sequences.html#navigable-container>navigable container</a>'s <a id=data-model:content-navigable-4 href=document-sequences.html#content-navigable>content navigable</a>.<li><p>If <var>candidate</var>'s <a href=#focused-area-of-the-document id=data-model:focused-area-of-the-document-4>focused area</a> is non-null, set <var>candidate</var> to <var>candidate</var>'s <a href=#focused-area-of-the-document id=data-model:focused-area-of-the-document-5>focused area</a>.<li><p>Return <var>candidate</var>.</ol> <p id=current-focus-chain-of-a-top-level-browsing-context>The <dfn id=current-focus-chain-of-a-top-level-traversable>current focus chain of a top-level traversable</dfn> <var>traversable</var> is the <a href=#focus-chain id=data-model:focus-chain>focus chain</a> of the <a href=#currently-focused-area-of-a-top-level-traversable id=data-model:currently-focused-area-of-a-top-level-traversable>currently focused area</a> of <var>traversable</var>, if <var>traversable</var> is non-null, or an empty list otherwise.</p> <p>An element that is the <a href=#dom-anchor id=data-model:dom-anchor-7>DOM anchor</a> of a <a href=#focusable-area id=data-model:focusable-area-13>focusable area</a> is said to <dfn id=gains-focus>gain focus</dfn> when that <a href=#focusable-area id=data-model:focusable-area-14>focusable area</a> becomes the <a href=#currently-focused-area-of-a-top-level-traversable id=data-model:currently-focused-area-of-a-top-level-traversable-2>currently focused area of a top-level traversable</a>. When an element is the <a href=#dom-anchor id=data-model:dom-anchor-8>DOM anchor</a> of a <a href=#focusable-area id=data-model:focusable-area-15>focusable area</a> of the <a href=#currently-focused-area-of-a-top-level-traversable id=data-model:currently-focused-area-of-a-top-level-traversable-3>currently focused area of a top-level traversable</a>, it is <dfn id=focused>focused</dfn>.</p> <p>The <dfn id=focus-chain>focus chain</dfn> of a <a href=#focusable-area id=data-model:focusable-area-16>focusable area</a> <var>subject</var> is the ordered list constructed as follows:</p> <ol><li><p>Let <var>output</var> be an empty <a id=data-model:list href=https://infra.spec.whatwg.org/#list data-x-internal=list>list</a>.<li><p>Let <var>currentObject</var> be <var>subject</var>.<li> <p>While true:</p> <ol><li><p><a href=https://infra.spec.whatwg.org/#list-append id=data-model:list-append data-x-internal=list-append>Append</a> <var>currentObject</var> to <var>output</var>.<li> <p>If <var>currentObject</var> is an <code id=data-model:the-area-element-3><a href=image-maps.html#the-area-element>area</a></code> element's shape, then <a href=https://infra.spec.whatwg.org/#list-append id=data-model:list-append-2 data-x-internal=list-append>append</a> that <code id=data-model:the-area-element-4><a href=image-maps.html#the-area-element>area</a></code> element to <var>output</var>.</p> <p>Otherwise, if <var>currentObject</var>'s <a href=#dom-anchor id=data-model:dom-anchor-9>DOM anchor</a> is an element that is not <var>currentObject</var> itself, then <a href=https://infra.spec.whatwg.org/#list-append id=data-model:list-append-3 data-x-internal=list-append>append</a> <var>currentObject</var>'s <a href=#dom-anchor id=data-model:dom-anchor-10>DOM anchor</a> to <var>output</var>.</p> <li> <p>If <var>currentObject</var> is a <a href=#focusable-area id=data-model:focusable-area-17>focusable area</a>, then set <var>currentObject</var> to <var>currentObject</var>'s <a href=#dom-anchor id=data-model:dom-anchor-11>DOM anchor</a>'s <a id=data-model:node-document href=https://dom.spec.whatwg.org/#concept-node-document data-x-internal=node-document>node document</a>.</p> <p>Otherwise, if <var>currentObject</var> is a <code id=data-model:document-5><a href=dom.html#document>Document</a></code> whose <a id=data-model:node-navigable-2 href=document-sequences.html#node-navigable>node navigable</a>'s <a href=document-sequences.html#nav-parent id=data-model:nav-parent>parent</a> is non-null, then set <var>currentObject</var> to <var>currentObject</var>'s <a id=data-model:node-navigable-3 href=document-sequences.html#node-navigable>node navigable</a>'s <a href=document-sequences.html#nav-parent id=data-model:nav-parent-2>parent</a>.</p> <p>Otherwise, <a id=data-model:break href=https://infra.spec.whatwg.org/#iteration-break data-x-internal=break>break</a>.</p> </ol> <li> <p>Return <var>output</var>.</p> <p class=note>The chain starts with <var>subject</var> and (if <var>subject</var> is or can be the <a href=#currently-focused-area-of-a-top-level-traversable id=data-model:currently-focused-area-of-a-top-level-traversable-4>currently focused area of a top-level traversable</a>) continues up the focus hierarchy up to the <code id=data-model:document-6><a href=dom.html#document>Document</a></code> of the <a id=data-model:top-level-traversable-3 href=document-sequences.html#top-level-traversable>top-level traversable</a>.</p> </ol> <p>All elements that are <a href=#focusable-area id=data-model:focusable-area-18>focusable areas</a> are said to be <dfn id=focusable>focusable</dfn>.</p> <p>There are two special types of focusability for <a href=#focusable-area id=data-model:focusable-area-19>focusable areas</a>:</p> <ul><li> <p>A <a href=#focusable-area id=data-model:focusable-area-20>focusable area</a> is said to be <dfn id=sequentially-focusable>sequentially focusable</dfn> if it is included in its <code id=data-model:document-7><a href=dom.html#document>Document</a></code>'s <a href=#sequential-focus-navigation-order id=data-model:sequential-focus-navigation-order>sequential focus navigation order</a> and the user agent determines that it is sequentially focusable.</p> <li> <p>A <a href=#focusable-area id=data-model:focusable-area-21>focusable area</a> is said to be <dfn id=click-focusable>click focusable</dfn> if the user agent determines that it is click focusable. User agents should consider focusable areas with non-null <a href=#tabindex-value id=data-model:tabindex-value-2>tabindex values</a> to be click focusable.</p> </ul> <p class=note>Elements which are not <a href=#focusable id=data-model:focusable>focusable</a> are not <a href=#focusable-area id=data-model:focusable-area-22>focusable areas</a>, and thus not <a href=#sequentially-focusable id=data-model:sequentially-focusable-3>sequentially focusable</a> and not <a href=#click-focusable id=data-model:click-focusable>click focusable</a>.</p> <div class=note> <p>Being <a href=#focusable id=data-model:focusable-2>focusable</a> is a statement about whether an element can be focused programmatically, e.g. via the <code id=data-model:dom-focus><a href=#dom-focus>focus()</a></code> method or <code id=data-model:attr-fe-autofocus><a href=#attr-fe-autofocus>autofocus</a></code> attribute. In contrast, <a href=#sequentially-focusable id=data-model:sequentially-focusable-4>sequentially focusable</a> and <a href=#click-focusable id=data-model:click-focusable-2>click focusable</a> govern how the user agent responds to user interaction: respectively, to <a href=#sequential-focus-navigation id=data-model:sequential-focus-navigation>sequential focus navigation</a> and as <a href=#focus-activation-behavior>activation behavior</a>.</p> <p>The user agent might determine that an element is not <a href=#sequentially-focusable id=data-model:sequentially-focusable-5>sequentially focusable</a> even if it is <a href=#focusable id=data-model:focusable-3>focusable</a> and is included in its <code id=data-model:document-8><a href=dom.html#document>Document</a></code>'s <a href=#sequential-focus-navigation-order id=data-model:sequential-focus-navigation-order-2>sequential focus navigation order</a>, according to user preferences. For example, macOS users can set the user agent to skip non-form control elements, or can skip links when doing <a href=#sequential-focus-navigation id=data-model:sequential-focus-navigation-2>sequential focus navigation</a> with just the <kbd>Tab</kbd> key (as opposed to using both the <kbd>Option</kbd> and <kbd>Tab</kbd> keys).</p> <p>Similarly, the user agent might determine that an element is not <a href=#click-focusable id=data-model:click-focusable-3>click focusable</a> even if it is <a href=#focusable id=data-model:focusable-4>focusable</a>. For example, in some user agents, clicking on a non-editable form control does not focus it, i.e. the user agent has determined that such controls are not click focusable.</p> <p>Thus, an element can be <a href=#focusable id=data-model:focusable-5>focusable</a>, but neither <a href=#sequentially-focusable id=data-model:sequentially-focusable-6>sequentially focusable</a> nor <a href=#click-focusable id=data-model:click-focusable-4>click focusable</a>. For example, in some user agents, a non-editable form-control with a negative-integer <a href=#tabindex-value id=data-model:tabindex-value-3>tabindex value</a> would not be focusable via user interaction, only via programmatic APIs.</p> </div> <p>When a user <a href=#activation>activates</a> a <a href=#click-focusable id=data-model:click-focusable-5>click focusable</a> <a href=#focusable-area id=data-model:focusable-area-23>focusable area</a>, the user agent must run the <a href=#focusing-steps id=data-model:focusing-steps>focusing steps</a> on the <a href=#focusable-area id=data-model:focusable-area-24>focusable area</a> with <var>focus trigger</var> set to "<code>click</code>".</p> <p class=note>Note that focusing is not an <a id=data-model:activation-behaviour href=https://dom.spec.whatwg.org/#eventtarget-activation-behavior data-x-internal=activation-behaviour>activation behavior</a>, i.e. calling the <code id=data-model:dom-click><a href=#dom-click>click()</a></code> method on an element or dispatching a synthetic <code id=data-model:event-click><a data-x-internal=event-click href=https://w3c.github.io/uievents/#event-type-click>click</a></code> event on it won't cause the element to get focused.</p> <hr> <p>A node is a <dfn id=focus-navigation-scope-owner>focus navigation scope owner</dfn> if it is a <code id=data-model:document-9><a href=dom.html#document>Document</a></code>, a <a id=data-model:shadow-host-2 href=https://dom.spec.whatwg.org/#element-shadow-host data-x-internal=shadow-host>shadow host</a>, a <a id=data-model:the-slot-element href=scripting.html#the-slot-element>slot</a>, or an element in the <a href=popover.html#popover-showing-state id=data-model:popover-showing-state>popover showing state</a> which also has a <a id=data-model:popover-invoker href=popover.html#popover-invoker>popover invoker</a> set.</p> <p>Each <a href=#focus-navigation-scope-owner id=data-model:focus-navigation-scope-owner>focus navigation scope owner</a> has a <dfn id=focus-navigation-scope>focus navigation scope</dfn>, which is a list of elements. Its contents are determined as follows:</p> <p>Every element <var>element</var> has an <dfn id=associated-focus-navigation-owner>associated focus navigation owner</dfn>, which is either null or a <a href=#focus-navigation-scope-owner id=data-model:focus-navigation-scope-owner-2>focus navigation scope owner</a>. It is determined by the following algorithm:</p> <ol><li><p>If <var>element</var>'s parent is null, then return null.<li><p>If <var>element</var>'s parent is a <a id=data-model:shadow-host-3 href=https://dom.spec.whatwg.org/#element-shadow-host data-x-internal=shadow-host>shadow host</a>, then return <var>element</var>'s <a id=data-model:assigned-slot href=https://dom.spec.whatwg.org/#slotable-assigned-slot data-x-internal=assigned-slot>assigned slot</a>.<li><p>If <var>element</var>'s parent is a <a id=data-model:shadow-root href=https://dom.spec.whatwg.org/#concept-shadow-root data-x-internal=shadow-root>shadow root</a>, then return the parent's <a href=https://dom.spec.whatwg.org/#concept-documentfragment-host id=data-model:concept-documentfragment-host data-x-internal=concept-documentfragment-host>host</a>.<li><p>If <var>element</var>'s parent is the <a id=data-model:document-element href=https://dom.spec.whatwg.org/#document-element data-x-internal=document-element>document element</a>, then return the parent's <a id=data-model:node-document-2 href=https://dom.spec.whatwg.org/#concept-node-document data-x-internal=node-document>node document</a>.<li><p>If <var>element</var> is in the <a href=popover.html#popover-showing-state id=data-model:popover-showing-state-2>popover showing state</a> and has a <a id=data-model:popover-invoker-2 href=popover.html#popover-invoker>popover invoker</a> set, then return <var>element</var>.<li><p>Return <var>element</var>'s parent's <a href=#associated-focus-navigation-owner id=data-model:associated-focus-navigation-owner>associated focus navigation owner</a>.</ol> <p>Then, the contents of a given <a href=#focus-navigation-scope-owner id=data-model:focus-navigation-scope-owner-3>focus navigation scope owner</a> <var>owner</var>'s <a href=#focus-navigation-scope id=data-model:focus-navigation-scope>focus navigation scope</a> are all elements whose <a href=#associated-focus-navigation-owner id=data-model:associated-focus-navigation-owner-2>associated focus navigation owner</a> is <var>owner</var>.</p> <p class=note>The order of elements within a <a href=#focus-navigation-scope id=data-model:focus-navigation-scope-2>focus navigation scope</a> does not impact any of the algorithms in this specification. Ordering only becomes important for the <a href=#tabindex-ordered-focus-navigation-scope id=data-model:tabindex-ordered-focus-navigation-scope>tabindex-ordered focus navigation scope</a> and <a href=#flattened-tabindex-ordered-focus-navigation-scope id=data-model:flattened-tabindex-ordered-focus-navigation-scope>flattened tabindex-ordered focus navigation scope</a> concepts defined below.</p> <p>A <dfn id=tabindex-ordered-focus-navigation-scope>tabindex-ordered focus navigation scope</dfn> is a list of <a href=#focusable-area id=data-model:focusable-area-25>focusable areas</a> and <a href=#focus-navigation-scope-owner id=data-model:focus-navigation-scope-owner-4>focus navigation scope owners</a>. Every <a href=#focus-navigation-scope-owner id=data-model:focus-navigation-scope-owner-5>focus navigation scope owner</a> <var>owner</var> has <a href=#tabindex-ordered-focus-navigation-scope id=data-model:tabindex-ordered-focus-navigation-scope-2>tabindex-ordered focus navigation scope</a>, whose contents are determined as follows:</p> <ul><li><p>It contains all elements in <var>owner</var>'s <a href=#focus-navigation-scope id=data-model:focus-navigation-scope-3>focus navigation scope</a> that are themselves <a href=#focus-navigation-scope-owner id=data-model:focus-navigation-scope-owner-6>focus navigation scope owners</a>, except the elements whose <a href=#tabindex-value id=data-model:tabindex-value-4>tabindex value</a> is a negative integer.<li><p>It contains all of the <a href=#focusable-area id=data-model:focusable-area-26>focusable areas</a> whose <a href=#dom-anchor id=data-model:dom-anchor-12>DOM anchor</a> is an element in <var>owner</var>'s <a href=#focus-navigation-scope id=data-model:focus-navigation-scope-4>focus navigation scope</a>, except the <a href=#focusable-area id=data-model:focusable-area-27>focusable areas</a> whose <a href=#tabindex-value id=data-model:tabindex-value-5>tabindex value</a> is a negative integer.</ul> <p>The order within a <a href=#tabindex-ordered-focus-navigation-scope id=data-model:tabindex-ordered-focus-navigation-scope-3>tabindex-ordered focus navigation scope</a> is determined by each element's <a href=#tabindex-value id=data-model:tabindex-value-6>tabindex value</a>, as described in the section below.</p> <p class=note>The rules there do not give a precise ordering, as they are composed mostly of "should" statements and relative orderings.</p> <p>A <dfn id=flattened-tabindex-ordered-focus-navigation-scope>flattened tabindex-ordered focus navigation scope</dfn> is a list of <a href=#focusable-area id=data-model:focusable-area-28>focusable areas</a>. Every <a href=#focus-navigation-scope-owner id=data-model:focus-navigation-scope-owner-7>focus navigation scope owner</a> <var>owner</var> owns a distinct <a href=#flattened-tabindex-ordered-focus-navigation-scope id=data-model:flattened-tabindex-ordered-focus-navigation-scope-2>flattened tabindex-ordered focus navigation scope</a>, whose contents are determined by the following algorithm:</p> <ol><li><p>Let <var>result</var> be a <a href=https://infra.spec.whatwg.org/#list-clone id=data-model:list-clone data-x-internal=list-clone>clone</a> of <var>owner</var>'s <a href=#tabindex-ordered-focus-navigation-scope id=data-model:tabindex-ordered-focus-navigation-scope-4>tabindex-ordered focus navigation scope</a>.<li> <p>For each <var>item</var> of <var>result</var>:</p> <ol><li><p>If <var>item</var> is not a <a href=#focus-navigation-scope-owner id=data-model:focus-navigation-scope-owner-8>focus navigation scope owner</a>, then <a id=data-model:continue href=https://infra.spec.whatwg.org/#iteration-continue data-x-internal=continue>continue</a>.<li><p>If <var>item</var> is not a <a href=#focusable-area id=data-model:focusable-area-29>focusable area</a>, then replace <var>item</var> with all of the items in <var>item</var>'s <a href=#flattened-tabindex-ordered-focus-navigation-scope id=data-model:flattened-tabindex-ordered-focus-navigation-scope-3>flattened tabindex-ordered focus navigation scope</a>.<li><p>Otherwise, insert the contents of <var>item</var>'s <a href=#flattened-tabindex-ordered-focus-navigation-scope id=data-model:flattened-tabindex-ordered-focus-navigation-scope-4>flattened tabindex-ordered focus navigation scope</a> after <var>item</var>.</ol> </ol> <h4 id=the-tabindex-attribute><span class=secno>6.6.3</span> The <code id=the-tabindex-attribute:attr-tabindex><a href=#attr-tabindex>tabindex</a></code> attribute<a href=#the-tabindex-attribute class=self-link></a></h4> <div class="mdn-anno wrapped before"><button onclick=toggleStatus(this) class=mdn-anno-btn><b title="Support in all current engines." class=all-engines-flag>✔</b><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex title="The tabindex global attribute allows developers to make HTML elements focusable, allow or prevent them from being sequentially focusable (usually with the Tab key, hence the name) and determine their relative ordering for sequential focus navigation.">Global_attributes/tabindex</a><p class=all-engines-text>Support in all current engines.<div class=support><span class="firefox yes"><span>Firefox</span><span>1.5+</span></span><span class="safari yes"><span>Safari</span><span>4+</span></span><span class="chrome yes"><span>Chrome</span><span>1+</span></span><hr><span class="opera unknown"><span>Opera</span><span>?</span></span><span class="edge_blink yes"><span>Edge</span><span>79+</span></span><hr><span class="edge yes"><span>Edge (Legacy)</span><span>12+</span></span><span class="ie yes"><span>Internet Explorer</span><span>Yes</span></span><hr><span class="firefox_android unknown"><span>Firefox Android</span><span>?</span></span><span class="safari_ios unknown"><span>Safari iOS</span><span>?</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android unknown"><span>WebView Android</span><span>?</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android unknown"><span>Opera Android</span><span>?</span></span></div></div></div><p>The <dfn data-dfn-for=htmlsvg-global id=attr-tabindex data-dfn-type=element-attr><code>tabindex</code></dfn> content attribute allows authors to make an element and regions that have the element as its <a href=#dom-anchor id=the-tabindex-attribute:dom-anchor>DOM anchor</a> be <a href=#focusable-area id=the-tabindex-attribute:focusable-area>focusable areas</a>, allow or prevent them from being <a href=#sequentially-focusable id=the-tabindex-attribute:sequentially-focusable>sequentially focusable</a>, and determine their relative ordering for <a href=#sequential-focus-navigation id=the-tabindex-attribute:sequential-focus-navigation>sequential focus navigation</a>.</p> <p>The name "tab index" comes from the common use of the <kbd>Tab</kbd> key to navigate through the focusable elements. The term "tabbing" refers to moving forward through <a href=#sequentially-focusable id=the-tabindex-attribute:sequentially-focusable-2>sequentially focusable</a> <a href=#focusable-area id=the-tabindex-attribute:focusable-area-2>focusable areas</a>.</p> <p>The <code id=the-tabindex-attribute:attr-tabindex-2><a href=#attr-tabindex>tabindex</a></code> attribute, if specified, must have a value that is a <a id=the-tabindex-attribute:valid-integer href=common-microsyntaxes.html#valid-integer>valid integer</a>. Positive numbers specify the relative position of the element's <a href=#focusable-area id=the-tabindex-attribute:focusable-area-3>focusable areas</a> in the <a href=#sequential-focus-navigation-order id=the-tabindex-attribute:sequential-focus-navigation-order>sequential focus navigation order</a>, and negative numbers indicate that the control is not <a href=#sequentially-focusable id=the-tabindex-attribute:sequentially-focusable-3>sequentially focusable</a>.</p> <p>Developers should use caution when using values other than 0 or −1 for their <code id=the-tabindex-attribute:attr-tabindex-3><a href=#attr-tabindex>tabindex</a></code> attributes as this is complicated to do correctly.</p> <div class=note> <p>The following provides a non-normative summary of the behaviors of the possible <code id=the-tabindex-attribute:attr-tabindex-4><a href=#attr-tabindex>tabindex</a></code> attribute values. The below processing model gives the more precise rules.</p> <dl><dt>omitted (or non-integer values)<dd>The user agent will decide whether the element is <a href=#focusable id=the-tabindex-attribute:focusable>focusable</a>, and if it is, whether it is <a href=#sequentially-focusable id=the-tabindex-attribute:sequentially-focusable-4>sequentially focusable</a> or <a href=#click-focusable id=the-tabindex-attribute:click-focusable>click focusable</a> (or both).<dt>−1 (or other negative integer values)<dd>Causes the element to be <a href=#focusable id=the-tabindex-attribute:focusable-2>focusable</a>, and indicates that the author would prefer the element to be <a href=#click-focusable id=the-tabindex-attribute:click-focusable-2>click focusable</a> but not <a href=#sequentially-focusable id=the-tabindex-attribute:sequentially-focusable-5>sequentially focusable</a>. The user agent might ignore this preference for click and sequential focusability, e.g., for specific element types according to platform conventions, or for keyboard-only users.<dt>0<dd>Causes the element to be <a href=#focusable id=the-tabindex-attribute:focusable-3>focusable</a>, and indicates that the author would prefer the element to be both <a href=#click-focusable id=the-tabindex-attribute:click-focusable-3>click focusable</a> and <a href=#sequentially-focusable id=the-tabindex-attribute:sequentially-focusable-6>sequentially focusable</a>. The user agent might ignore this preference for click and sequential focusability.<dt>positive integer values<dd>Behaves the same as 0, but in addition creates a relative ordering within a <a href=#tabindex-ordered-focus-navigation-scope id=the-tabindex-attribute:tabindex-ordered-focus-navigation-scope>tabindex-ordered focus navigation scope</a>, so that elements with higher <code id=the-tabindex-attribute:attr-tabindex-5><a href=#attr-tabindex>tabindex</a></code> attribute value come later.</dl> <p>Note that the <code id=the-tabindex-attribute:attr-tabindex-6><a href=#attr-tabindex>tabindex</a></code> attribute cannot be used to make an element non-focusable. The only way a page author can do that is by <a href=semantics-other.html#concept-element-disabled id=the-tabindex-attribute:concept-element-disabled>disabling</a> the element, or making it <a href=#inert id=the-tabindex-attribute:inert>inert</a>.</p> </div> <hr> <p>The <dfn id=tabindex-value>tabindex value</dfn> of an element is the value of its <code id=the-tabindex-attribute:attr-tabindex-7><a href=#attr-tabindex>tabindex</a></code> attribute, parsed using the <a id=the-tabindex-attribute:rules-for-parsing-integers href=common-microsyntaxes.html#rules-for-parsing-integers>rules for parsing integers</a>. If parsing fails or the attribute is not specified, then the <a href=#tabindex-value id=the-tabindex-attribute:tabindex-value>tabindex value</a> is null.</p> <p>The <a href=#tabindex-value id=the-tabindex-attribute:tabindex-value-2>tabindex value</a> of a <a href=#focusable-area id=the-tabindex-attribute:focusable-area-4>focusable area</a> is the <a href=#tabindex-value id=the-tabindex-attribute:tabindex-value-3>tabindex value</a> of its <a href=#dom-anchor id=the-tabindex-attribute:dom-anchor-2>DOM anchor</a>.</p> <p>The <a href=#tabindex-value id=the-tabindex-attribute:tabindex-value-4>tabindex value</a> of an element must be interpreted as follows:</p> <dl><dt>If the value is null<dd> <p>The user agent should follow platform conventions to determine if the element should be considered as a <a href=#focusable-area id=the-tabindex-attribute:focusable-area-5>focusable area</a> and if so, whether the element and any <a href=#focusable-area id=the-tabindex-attribute:focusable-area-6>focusable areas</a> that have the element as their <a href=#dom-anchor id=the-tabindex-attribute:dom-anchor-3>DOM anchor</a> are <a href=#sequentially-focusable id=the-tabindex-attribute:sequentially-focusable-7>sequentially focusable</a>, and if so, what their relative position in their <a href=#tabindex-ordered-focus-navigation-scope id=the-tabindex-attribute:tabindex-ordered-focus-navigation-scope-2>tabindex-ordered focus navigation scope</a> is to be. If the element is a <a href=#focus-navigation-scope-owner id=the-tabindex-attribute:focus-navigation-scope-owner>focus navigation scope owner</a>, it must be included in its <a href=#tabindex-ordered-focus-navigation-scope id=the-tabindex-attribute:tabindex-ordered-focus-navigation-scope-3>tabindex-ordered focus navigation scope</a> even if it is not a <a href=#focusable-area id=the-tabindex-attribute:focusable-area-7>focusable area</a>.</p> <p>The relative ordering within a <a href=#tabindex-ordered-focus-navigation-scope id=the-tabindex-attribute:tabindex-ordered-focus-navigation-scope-4>tabindex-ordered focus navigation scope</a> for elements and <a href=#focusable-area id=the-tabindex-attribute:focusable-area-8>focusable areas</a> that belong to the same <a href=#focus-navigation-scope id=the-tabindex-attribute:focus-navigation-scope>focus navigation scope</a> and whose <a href=#tabindex-value id=the-tabindex-attribute:tabindex-value-5>tabindex value</a> is null should be in <a id=the-tabindex-attribute:shadow-including-tree-order href=https://dom.spec.whatwg.org/#concept-shadow-including-tree-order data-x-internal=shadow-including-tree-order>shadow-including tree order</a>.</p> <p>Modulo platform conventions, it is suggested that the following elements should be considered as <a href=#focusable-area id=the-tabindex-attribute:focusable-area-9>focusable areas</a> and be <a href=#sequentially-focusable id=the-tabindex-attribute:sequentially-focusable-8>sequentially focusable</a>:</p> <ul><li><code id=the-tabindex-attribute:the-a-element><a href=text-level-semantics.html#the-a-element>a</a></code> elements that have an <code id=the-tabindex-attribute:attr-hyperlink-href><a href=links.html#attr-hyperlink-href>href</a></code> attribute<li><code id=the-tabindex-attribute:the-button-element><a href=form-elements.html#the-button-element>button</a></code> elements<li><code id=the-tabindex-attribute:the-input-element><a href=input.html#the-input-element>input</a></code> elements whose <code id=the-tabindex-attribute:attr-input-type><a href=input.html#attr-input-type>type</a></code> attribute are not in the <a href="input.html#hidden-state-(type=hidden)" id="the-tabindex-attribute:hidden-state-(type=hidden)">Hidden</a> state<li><code id=the-tabindex-attribute:the-select-element><a href=form-elements.html#the-select-element>select</a></code> elements<li><code id=the-tabindex-attribute:the-textarea-element><a href=form-elements.html#the-textarea-element>textarea</a></code> elements<li><code id=the-tabindex-attribute:the-summary-element><a href=interactive-elements.html#the-summary-element>summary</a></code> elements that are the first <code id=the-tabindex-attribute:the-summary-element-2><a href=interactive-elements.html#the-summary-element>summary</a></code> element child of a <code id=the-tabindex-attribute:the-details-element><a href=interactive-elements.html#the-details-element>details</a></code> element<li>Elements with a <code id=the-tabindex-attribute:attr-draggable><a href=dnd.html#attr-draggable>draggable</a></code> attribute set, if that would enable the user agent to allow the user to begin drag operations for those elements without the use of a pointing device<li><a href=#editing-host id=the-tabindex-attribute:editing-host>Editing hosts</a><li><a href=document-sequences.html#navigable-container id=the-tabindex-attribute:navigable-container>Navigable containers</a></ul> <dt id=negative-tabindex>If the value is a negative integer<dd> <p>The user agent must consider the element as a <a href=#focusable-area id=the-tabindex-attribute:focusable-area-10>focusable area</a>, but should omit the element from any <a href=#tabindex-ordered-focus-navigation-scope id=the-tabindex-attribute:tabindex-ordered-focus-navigation-scope-5>tabindex-ordered focus navigation scope</a>.</p> <p class=note>One valid reason to ignore the requirement that sequential focus navigation not allow the author to lead to the element would be if the user's only mechanism for moving the focus is sequential focus navigation. For instance, a keyboard-only user would be unable to click on a text control with a negative <code id=the-tabindex-attribute:attr-tabindex-8><a href=#attr-tabindex>tabindex</a></code>, so that user's user agent would be well justified in allowing the user to tab to the control regardless.</p> <dt>If the value is a zero<dd> <p>The user agent must allow the element to be considered as a <a href=#focusable-area id=the-tabindex-attribute:focusable-area-11>focusable area</a> and should allow the element and any <a href=#focusable-area id=the-tabindex-attribute:focusable-area-12>focusable areas</a> that have the element as their <a href=#dom-anchor id=the-tabindex-attribute:dom-anchor-4>DOM anchor</a> to be <a href=#sequentially-focusable id=the-tabindex-attribute:sequentially-focusable-9>sequentially focusable</a>.</p> <p>The relative ordering within a <a href=#tabindex-ordered-focus-navigation-scope id=the-tabindex-attribute:tabindex-ordered-focus-navigation-scope-6>tabindex-ordered focus navigation scope</a> for elements and <a href=#focusable-area id=the-tabindex-attribute:focusable-area-13>focusable areas</a> that belong to the same <a href=#focus-navigation-scope id=the-tabindex-attribute:focus-navigation-scope-2>focus navigation scope</a> and whose <a href=#tabindex-value id=the-tabindex-attribute:tabindex-value-6>tabindex value</a> is zero should be in <a id=the-tabindex-attribute:shadow-including-tree-order-2 href=https://dom.spec.whatwg.org/#concept-shadow-including-tree-order data-x-internal=shadow-including-tree-order>shadow-including tree order</a>.</p> <dt>If the value is greater than zero<dd> <p>The user agent must allow the element to be considered as a <a href=#focusable-area id=the-tabindex-attribute:focusable-area-14>focusable area</a> and should allow the element and any <a href=#focusable-area id=the-tabindex-attribute:focusable-area-15>focusable areas</a> that have the element as their <a href=#dom-anchor id=the-tabindex-attribute:dom-anchor-5>DOM anchor</a> to be <a href=#sequentially-focusable id=the-tabindex-attribute:sequentially-focusable-10>sequentially focusable</a>, and should place the element — referenced as <var>candidate</var> below — and the aforementioned <a href=#focusable-area id=the-tabindex-attribute:focusable-area-16>focusable areas</a> in the <a href=#tabindex-ordered-focus-navigation-scope id=the-tabindex-attribute:tabindex-ordered-focus-navigation-scope-7>tabindex-ordered focus navigation scope</a> where the element is a part of so that, relative to other elements and <a href=#focusable-area id=the-tabindex-attribute:focusable-area-17>focusable areas</a> that belong to the same <a href=#focus-navigation-scope id=the-tabindex-attribute:focus-navigation-scope-3>focus navigation scope</a>, they are:</p> <ul><li>before any <a href=#focusable-area id=the-tabindex-attribute:focusable-area-18>focusable area</a> whose <a href=#dom-anchor id=the-tabindex-attribute:dom-anchor-6>DOM anchor</a> is an element whose <code id=the-tabindex-attribute:attr-tabindex-9><a href=#attr-tabindex>tabindex</a></code> attribute has been omitted or whose value, when parsed, returns an error,<li>before any <a href=#focusable-area id=the-tabindex-attribute:focusable-area-19>focusable area</a> whose <a href=#dom-anchor id=the-tabindex-attribute:dom-anchor-7>DOM anchor</a> is an element whose <code id=the-tabindex-attribute:attr-tabindex-10><a href=#attr-tabindex>tabindex</a></code> attribute has a value less than or equal to zero,<li>after any <a href=#focusable-area id=the-tabindex-attribute:focusable-area-20>focusable area</a> whose <a href=#dom-anchor id=the-tabindex-attribute:dom-anchor-8>DOM anchor</a> is an element whose <code id=the-tabindex-attribute:attr-tabindex-11><a href=#attr-tabindex>tabindex</a></code> attribute has a value greater than zero but less than the value of the <code id=the-tabindex-attribute:attr-tabindex-12><a href=#attr-tabindex>tabindex</a></code> attribute on <var>candidate</var>,<li>after any <a href=#focusable-area id=the-tabindex-attribute:focusable-area-21>focusable area</a> whose <a href=#dom-anchor id=the-tabindex-attribute:dom-anchor-9>DOM anchor</a> is an element whose <code id=the-tabindex-attribute:attr-tabindex-13><a href=#attr-tabindex>tabindex</a></code> attribute has a value equal to the value of the <code id=the-tabindex-attribute:attr-tabindex-14><a href=#attr-tabindex>tabindex</a></code> attribute on <var>candidate</var> but that is located earlier than <var>candidate</var> in <a id=the-tabindex-attribute:shadow-including-tree-order-3 href=https://dom.spec.whatwg.org/#concept-shadow-including-tree-order data-x-internal=shadow-including-tree-order>shadow-including tree order</a>,<li>before any <a href=#focusable-area id=the-tabindex-attribute:focusable-area-22>focusable area</a> whose <a href=#dom-anchor id=the-tabindex-attribute:dom-anchor-10>DOM anchor</a> is an element whose <code id=the-tabindex-attribute:attr-tabindex-15><a href=#attr-tabindex>tabindex</a></code> attribute has a value equal to the value of the <code id=the-tabindex-attribute:attr-tabindex-16><a href=#attr-tabindex>tabindex</a></code> attribute on <var>candidate</var> but that is located later than <var>candidate</var> in <a id=the-tabindex-attribute:shadow-including-tree-order-4 href=https://dom.spec.whatwg.org/#concept-shadow-including-tree-order data-x-internal=shadow-including-tree-order>shadow-including tree order</a>, and<li>before any <a href=#focusable-area id=the-tabindex-attribute:focusable-area-23>focusable area</a> whose <a href=#dom-anchor id=the-tabindex-attribute:dom-anchor-11>DOM anchor</a> is an element whose <code id=the-tabindex-attribute:attr-tabindex-17><a href=#attr-tabindex>tabindex</a></code> attribute has a value greater than the value of the <code id=the-tabindex-attribute:attr-tabindex-18><a href=#attr-tabindex>tabindex</a></code> attribute on <var>candidate</var>.</ul> </dl> <div class="mdn-anno wrapped before"><button onclick=toggleStatus(this) class=mdn-anno-btn><b title="Support in all current engines." class=all-engines-flag>✔</b><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/tabIndex title="The tabIndex property of the HTMLElement interface represents the tab order of the current element.">HTMLElement/tabIndex</a><p class=all-engines-text>Support in all current engines.<div class=support><span class="firefox yes"><span>Firefox</span><span>1+</span></span><span class="safari yes"><span>Safari</span><span>3.1+</span></span><span class="chrome yes"><span>Chrome</span><span>1+</span></span><hr><span class="opera yes"><span>Opera</span><span>12.1+</span></span><span class="edge_blink yes"><span>Edge</span><span>79+</span></span><hr><span class="edge yes"><span>Edge (Legacy)</span><span>18</span></span><span class="ie yes"><span>Internet Explorer</span><span title="Partial implementation.">🔰 5.5+</span></span><hr><span class="firefox_android unknown"><span>Firefox Android</span><span>?</span></span><span class="safari_ios unknown"><span>Safari iOS</span><span>?</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android unknown"><span>WebView Android</span><span>?</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android yes"><span>Opera Android</span><span>12.1+</span></span></div></div></div><p>The <dfn data-dfn-for=HTMLOrSVGElement id=dom-tabindex data-dfn-type=attribute><code>tabIndex</code></dfn> IDL attribute must <a id=the-tabindex-attribute:reflect href=common-dom-interfaces.html#reflect>reflect</a> the value of the <code id=the-tabindex-attribute:attr-tabindex-19><a href=#attr-tabindex>tabindex</a></code> content attribute. The <a id=the-tabindex-attribute:default-value href=common-dom-interfaces.html#default-value>default value</a> is 0 if the element is an <code id=the-tabindex-attribute:the-a-element-2><a href=text-level-semantics.html#the-a-element>a</a></code>, <code id=the-tabindex-attribute:the-area-element><a href=image-maps.html#the-area-element>area</a></code>, <code id=the-tabindex-attribute:the-button-element-2><a href=form-elements.html#the-button-element>button</a></code>, <code id=the-tabindex-attribute:frame><a href=obsolete.html#frame>frame</a></code>, <code id=the-tabindex-attribute:the-iframe-element><a href=iframe-embed-object.html#the-iframe-element>iframe</a></code>, <code id=the-tabindex-attribute:the-input-element-2><a href=input.html#the-input-element>input</a></code>, <code id=the-tabindex-attribute:the-object-element><a href=iframe-embed-object.html#the-object-element>object</a></code>, <code id=the-tabindex-attribute:the-select-element-2><a href=form-elements.html#the-select-element>select</a></code>, <code id=the-tabindex-attribute:the-textarea-element-2><a href=form-elements.html#the-textarea-element>textarea</a></code>, or <a id=the-tabindex-attribute:svg-a href=https://svgwg.org/svg2-draft/linking.html#AElement data-x-internal=svg-a>SVG <code>a</code></a> element, or is a <code id=the-tabindex-attribute:the-summary-element-3><a href=interactive-elements.html#the-summary-element>summary</a></code> element that is a <a id=the-tabindex-attribute:summary-for-its-parent-details href=interactive-elements.html#summary-for-its-parent-details>summary for its parent details</a>. The <a id=the-tabindex-attribute:default-value-2 href=common-dom-interfaces.html#default-value>default value</a> is −1 otherwise.</p> <p class=note>The varying default value based on element type is a historical artifact.</p> <h4 id=focus-processing-model><span class=secno>6.6.4</span> <span id=processing-model-5></span>Processing model<a href=#focus-processing-model class=self-link></a></h4> <p>To <dfn id=get-the-focusable-area>get the focusable area</dfn> for a <var>focus target</var> that is either an element that is not a <a href=#focusable-area id=focus-processing-model:focusable-area>focusable area</a>, or is a <a id=focus-processing-model:navigable href=document-sequences.html#navigable>navigable</a>, given an optional string <var>focus trigger</var> (default "<code>other</code>"), run the first matching set of steps from the following list:</p> <dl class=switch><dt>If <var>focus target</var> is an <code id=focus-processing-model:the-area-element><a href=image-maps.html#the-area-element>area</a></code> element with one or more shapes that are <a href=#focusable-area id=focus-processing-model:focusable-area-2>focusable areas</a><dd><p>Return the shape corresponding to the first <code id=focus-processing-model:the-img-element><a href=embedded-content.html#the-img-element>img</a></code> element in <a id=focus-processing-model:tree-order href=https://dom.spec.whatwg.org/#concept-tree-order data-x-internal=tree-order>tree order</a> that uses the image map to which the <code id=focus-processing-model:the-area-element-2><a href=image-maps.html#the-area-element>area</a></code> element belongs.<dt>If <var>focus target</var> is an element with one or more scrollable regions that are <a href=#focusable-area id=focus-processing-model:focusable-area-3>focusable areas</a><dd><p>Return the element's first scrollable region, according to a pre-order, depth-first traversal of the <a id=focus-processing-model:flat-tree href=https://drafts.csswg.org/css-scoping/#flat-tree data-x-internal=flat-tree>flat tree</a>. <a href=references.html#refsCSSSCOPING>[CSSSCOPING]</a><dt>If <var>focus target</var> is the <a id=focus-processing-model:document-element href=https://dom.spec.whatwg.org/#document-element data-x-internal=document-element>document element</a> of its <code id=focus-processing-model:document><a href=dom.html#document>Document</a></code><dd><p>Return the <code id=focus-processing-model:document-2><a href=dom.html#document>Document</a></code>'s <a id=focus-processing-model:viewport href=https://drafts.csswg.org/css2/#viewport data-x-internal=viewport>viewport</a>.<dt>If <var>focus target</var> is a <a id=focus-processing-model:navigable-2 href=document-sequences.html#navigable>navigable</a><dd><p>Return the <a id=focus-processing-model:navigable-3 href=document-sequences.html#navigable>navigable</a>'s <a href=document-sequences.html#nav-document id=focus-processing-model:nav-document>active document</a>.<dt>If <var>focus target</var> is a <a id=focus-processing-model:navigable-container href=document-sequences.html#navigable-container>navigable container</a> with a non-null <a id=focus-processing-model:content-navigable href=document-sequences.html#content-navigable>content navigable</a><dd><p>Return the <a id=focus-processing-model:navigable-container-2 href=document-sequences.html#navigable-container>navigable container</a>'s <a id=focus-processing-model:content-navigable-2 href=document-sequences.html#content-navigable>content navigable</a>'s <a href=document-sequences.html#nav-document id=focus-processing-model:nav-document-2>active document</a>.<dt>If <var>focus target</var> is a <a id=focus-processing-model:shadow-host href=https://dom.spec.whatwg.org/#element-shadow-host data-x-internal=shadow-host>shadow host</a> whose <a href=https://dom.spec.whatwg.org/#concept-element-shadow-root id=focus-processing-model:concept-element-shadow-root data-x-internal=concept-element-shadow-root>shadow root</a>'s <a id=focus-processing-model:delegates-focus href=https://dom.spec.whatwg.org/#shadowroot-delegates-focus data-x-internal=delegates-focus>delegates focus</a> is true<dd> <ol><li><p>Let <var>focusedElement</var> be the <a href=#currently-focused-area-of-a-top-level-traversable id=focus-processing-model:currently-focused-area-of-a-top-level-traversable>currently focused area of a top-level traversable</a>'s <a href=#dom-anchor id=focus-processing-model:dom-anchor>DOM anchor</a>.<li><p>If <var>focus target</var> is a <a id=focus-processing-model:shadow-including-inclusive-ancestor href=https://dom.spec.whatwg.org/#concept-shadow-including-inclusive-ancestor data-x-internal=shadow-including-inclusive-ancestor>shadow-including inclusive ancestor</a> of <var>focusedElement</var>, then return <var>focusedElement</var>.<li><p>Return the <a href=#focus-delegate id=focus-processing-model:focus-delegate>focus delegate</a> for <var>focus target</var> given <var>focus trigger</var>.</ol> <p class=note>For <a href=#sequentially-focusable id=focus-processing-model:sequentially-focusable>sequential focusability</a>, the handling of <a href=https://dom.spec.whatwg.org/#element-shadow-host id=focus-processing-model:shadow-host-2 data-x-internal=shadow-host>shadow hosts</a> and <a id=focus-processing-model:delegates-focus-2 href=https://dom.spec.whatwg.org/#shadowroot-delegates-focus data-x-internal=delegates-focus>delegates focus</a> is done when constructing the <a href=#sequential-focus-navigation-order id=focus-processing-model:sequential-focus-navigation-order>sequential focus navigation order</a>. That is, the <a href=#focusing-steps id=focus-processing-model:focusing-steps>focusing steps</a> will never be called on such <a href=https://dom.spec.whatwg.org/#element-shadow-host id=focus-processing-model:shadow-host-3 data-x-internal=shadow-host>shadow hosts</a> as part of sequential focus navigation.</p> <dt>Otherwise<dd><p>Return null.</dl> <p>The <dfn id=focus-delegate>focus delegate</dfn> for a <var>focusTarget</var>, given an optional string <var>focusTrigger</var> (default "<code>other</code>"), is given by the following steps:</p> <ol><li><p>If <var>focusTarget</var> is a <a id=focus-processing-model:shadow-host-4 href=https://dom.spec.whatwg.org/#element-shadow-host data-x-internal=shadow-host>shadow host</a> and its <a href=https://dom.spec.whatwg.org/#concept-element-shadow-root id=focus-processing-model:concept-element-shadow-root-2 data-x-internal=concept-element-shadow-root>shadow root</a>'s <a id=focus-processing-model:delegates-focus-3 href=https://dom.spec.whatwg.org/#shadowroot-delegates-focus data-x-internal=delegates-focus>delegates focus</a> is false, then return null.<li><p>Let <var>whereToLook</var> be <var>focusTarget</var>.<li><p>If <var>whereToLook</var> is a <a id=focus-processing-model:shadow-host-5 href=https://dom.spec.whatwg.org/#element-shadow-host data-x-internal=shadow-host>shadow host</a>, then set <var>whereToLook</var> to <var>whereToLook</var>'s <a href=https://dom.spec.whatwg.org/#concept-element-shadow-root id=focus-processing-model:concept-element-shadow-root-3 data-x-internal=concept-element-shadow-root>shadow root</a>.<li><p>Let <var>autofocusDelegate</var> be the <a href=#autofocus-delegate id=focus-processing-model:autofocus-delegate>autofocus delegate</a> for <var>whereToLook</var> given <var>focusTrigger</var>.<li><p>If <var>autofocusDelegate</var> is not null, then return <var>autofocusDelegate</var>.<li> <p><a href=https://infra.spec.whatwg.org/#list-iterate id=focus-processing-model:list-iterate data-x-internal=list-iterate>For each</a> <var>descendant</var> of <var>whereToLook</var>'s <a href=https://dom.spec.whatwg.org/#concept-tree-descendant id=focus-processing-model:descendant data-x-internal=descendant>descendants</a>, in <a id=focus-processing-model:tree-order-2 href=https://dom.spec.whatwg.org/#concept-tree-order data-x-internal=tree-order>tree order</a>:</p> <ol><li><p>Let <var>focusableArea</var> be null.<li><p>If <var>focusTarget</var> is a <code id=focus-processing-model:the-dialog-element><a href=interactive-elements.html#the-dialog-element>dialog</a></code> element and <var>descendant</var> is <a href=#sequentially-focusable id=focus-processing-model:sequentially-focusable-2>sequentially focusable</a>, then set <var>focusableArea</var> to <var>descendant</var>.<li><p>Otherwise, if <var>focusTarget</var> is not a <code id=focus-processing-model:the-dialog-element-2><a href=interactive-elements.html#the-dialog-element>dialog</a></code> and <var>descendant</var> is a <a href=#focusable-area id=focus-processing-model:focusable-area-4>focusable area</a>, set <var>focusableArea</var> to <var>descendant</var>.<li> <p>Otherwise, set <var>focusableArea</var> to the result of <a href=#get-the-focusable-area id=focus-processing-model:get-the-focusable-area>getting the focusable area</a> for <var>descendant</var> given <var>focusTrigger</var>.</p> <p class=note>This step can end up recursing, i.e., the <a href=#get-the-focusable-area id=focus-processing-model:get-the-focusable-area-2>get the focusable area</a> steps might return the <a href=#focus-delegate id=focus-processing-model:focus-delegate-2>focus delegate</a> of <var>descendant</var>.</p> <li><p>If <var>focusableArea</var> is not null, then return <var>focusableArea</var>.</ol> <p class=note>It's important that we are <em>not</em> looking at the <a href=https://dom.spec.whatwg.org/#concept-shadow-including-descendant id=focus-processing-model:shadow-including-descendant data-x-internal=shadow-including-descendant>shadow-including descendants</a> here, but instead only at the <a href=https://dom.spec.whatwg.org/#concept-tree-descendant id=focus-processing-model:descendant-2 data-x-internal=descendant>descendants</a>. <a href=https://dom.spec.whatwg.org/#element-shadow-host id=focus-processing-model:shadow-host-6 data-x-internal=shadow-host>Shadow hosts</a> are instead handled by the recursive case mentioned above.</p> <li><p>Return null.</ol> <p class=note>The above algorithm essentially returns the first suitable <a href=#focusable-area id=focus-processing-model:focusable-area-5>focusable area</a> where the path between its <a href=#dom-anchor id=focus-processing-model:dom-anchor-2>DOM anchor</a> and <var>focusTarget</var> delegates focus at any shadow tree boundaries.</p> <p>The <dfn id=autofocus-delegate>autofocus delegate</dfn> for a <var>focus target</var> given a <var>focus trigger</var> is given by the following steps:</p> <ol><li> <p>For each <a id=focus-processing-model:descendant-3 href=https://dom.spec.whatwg.org/#concept-tree-descendant data-x-internal=descendant>descendant</a> <var>descendant</var> of <var>focus target</var>, in <a id=focus-processing-model:tree-order-3 href=https://dom.spec.whatwg.org/#concept-tree-order data-x-internal=tree-order>tree order</a>:</p> <ol><li><p>If <var>descendant</var> does not have an <code id=focus-processing-model:attr-fe-autofocus><a href=#attr-fe-autofocus>autofocus</a></code> content attribute, then <a id=focus-processing-model:continue href=https://infra.spec.whatwg.org/#iteration-continue data-x-internal=continue>continue</a>.<li><p>Let <var>focusable area</var> be <var>descendant</var>, if <var>descendant</var> is a <a href=#focusable-area id=focus-processing-model:focusable-area-6>focusable area</a>; otherwise let <var>focusable area</var> be the result of <a href=#get-the-focusable-area id=focus-processing-model:get-the-focusable-area-3>getting the focusable area</a> for <var>descendant</var> given <var>focus trigger</var>.<li><p>If <var>focusable area</var> is null, then <a id=focus-processing-model:continue-2 href=https://infra.spec.whatwg.org/#iteration-continue data-x-internal=continue>continue</a>.<li><p>If <var>focusable area</var> is not <a href=#click-focusable id=focus-processing-model:click-focusable>click focusable</a> and <var>focus trigger</var> is "<code>click</code>", then <a id=focus-processing-model:continue-3 href=https://infra.spec.whatwg.org/#iteration-continue data-x-internal=continue>continue</a>.<li><p>Return <var>focusable area</var>.</ol> <li><p>Return null.</ol> <p>The <dfn id=focusing-steps data-export="">focusing steps</dfn> for an object <var>new focus target</var> that is either a <a href=#focusable-area id=focus-processing-model:focusable-area-7>focusable area</a>, or an element that is not a <a href=#focusable-area id=focus-processing-model:focusable-area-8>focusable area</a>, or a <a id=focus-processing-model:navigable-4 href=document-sequences.html#navigable>navigable</a>, are as follows. They can optionally be run with a <var>fallback target</var> and a string <var>focus trigger</var>.</p> <ol><li><p>If <var>new focus target</var> is not a <a href=#focusable-area id=focus-processing-model:focusable-area-9>focusable area</a>, then set <var>new focus target</var> to the result of <a href=#get-the-focusable-area id=focus-processing-model:get-the-focusable-area-4>getting the focusable area</a> for <var>new focus target</var>, given <var>focus trigger</var> if it was passed.<li> <p>If <var>new focus target</var> is null, then:</p> <ol><li><p>If no <var>fallback target</var> was specified, then return.<li><p>Otherwise, set <var>new focus target</var> to the <var>fallback target</var>.</ol> <li><p>If <var>new focus target</var> is a <a id=focus-processing-model:navigable-container-3 href=document-sequences.html#navigable-container>navigable container</a> with non-null <a id=focus-processing-model:content-navigable-3 href=document-sequences.html#content-navigable>content navigable</a>, then set <var>new focus target</var> to the <a id=focus-processing-model:content-navigable-4 href=document-sequences.html#content-navigable>content navigable</a>'s <a href=document-sequences.html#nav-document id=focus-processing-model:nav-document-3>active document</a>.<li><p>If <var>new focus target</var> is a <a href=#focusable-area id=focus-processing-model:focusable-area-10>focusable area</a> and its <a href=#dom-anchor id=focus-processing-model:dom-anchor-3>DOM anchor</a> is <a href=#inert id=focus-processing-model:inert>inert</a>, then return.<li><p>If <var>new focus target</var> is the <a href=#currently-focused-area-of-a-top-level-traversable id=focus-processing-model:currently-focused-area-of-a-top-level-traversable-2>currently focused area of a top-level traversable</a>, then return.<li><p>Let <var>old chain</var> be the <a href=#current-focus-chain-of-a-top-level-traversable id=focus-processing-model:current-focus-chain-of-a-top-level-traversable>current focus chain of the top-level traversable</a> in which <var>new focus target</var> finds itself.<li><p>Let <var>new chain</var> be the <a href=#focus-chain id=focus-processing-model:focus-chain>focus chain</a> of <var>new focus target</var>.<li><p>Run the <a href=#focus-update-steps id=focus-processing-model:focus-update-steps>focus update steps</a> with <var>old chain</var>, <var>new chain</var>, and <var>new focus target</var> respectively.</ol> <p>User agents must <a id=focus-processing-model:immediately href=infrastructure.html#immediately>immediately</a> run the <a href=#focusing-steps id=focus-processing-model:focusing-steps-2>focusing steps</a> for a <a href=#focusable-area id=focus-processing-model:focusable-area-11>focusable area</a> or <a id=focus-processing-model:navigable-5 href=document-sequences.html#navigable>navigable</a> <var>candidate</var> whenever the user attempts to move the focus to <var>candidate</var>.</p> <p>The <dfn id=unfocusing-steps>unfocusing steps</dfn> for an object <var>old focus target</var> that is either a <a href=#focusable-area id=focus-processing-model:focusable-area-12>focusable area</a> or an element that is not a <a href=#focusable-area id=focus-processing-model:focusable-area-13>focusable area</a> are as follows:</p> <ol><li><p>If <var>old focus target</var> is a <a id=focus-processing-model:shadow-host-7 href=https://dom.spec.whatwg.org/#element-shadow-host data-x-internal=shadow-host>shadow host</a> whose <a href=https://dom.spec.whatwg.org/#concept-element-shadow-root id=focus-processing-model:concept-element-shadow-root-4 data-x-internal=concept-element-shadow-root>shadow root</a>'s <a id=focus-processing-model:delegates-focus-4 href=https://dom.spec.whatwg.org/#shadowroot-delegates-focus data-x-internal=delegates-focus>delegates focus</a> is true, and <var>old focus target</var>'s <a href=https://dom.spec.whatwg.org/#concept-element-shadow-root id=focus-processing-model:concept-element-shadow-root-5 data-x-internal=concept-element-shadow-root>shadow root</a> is a <a id=focus-processing-model:shadow-including-inclusive-ancestor-2 href=https://dom.spec.whatwg.org/#concept-shadow-including-inclusive-ancestor data-x-internal=shadow-including-inclusive-ancestor>shadow-including inclusive ancestor</a> of the <a href=#currently-focused-area-of-a-top-level-traversable id=focus-processing-model:currently-focused-area-of-a-top-level-traversable-3>currently focused area of a top-level traversable</a>'s <a href=#dom-anchor id=focus-processing-model:dom-anchor-4>DOM anchor</a>, then set <var>old focus target</var> to that <a href=#currently-focused-area-of-a-top-level-traversable id=focus-processing-model:currently-focused-area-of-a-top-level-traversable-4>currently focused area of a top-level traversable</a>.<li><p>If <var>old focus target</var> is <a href=#inert id=focus-processing-model:inert-2>inert</a>, then return.<li><p>If <var>old focus target</var> is an <code id=focus-processing-model:the-area-element-3><a href=image-maps.html#the-area-element>area</a></code> element and one of its shapes is the <a href=#currently-focused-area-of-a-top-level-traversable id=focus-processing-model:currently-focused-area-of-a-top-level-traversable-5>currently focused area of a top-level traversable</a>, or, if <var>old focus target</var> is an element with one or more scrollable regions, and one of them is the <a href=#currently-focused-area-of-a-top-level-traversable id=focus-processing-model:currently-focused-area-of-a-top-level-traversable-6>currently focused area of a top-level traversable</a>, then let <var>old focus target</var> be that <a href=#currently-focused-area-of-a-top-level-traversable id=focus-processing-model:currently-focused-area-of-a-top-level-traversable-7>currently focused area of a top-level traversable</a>.<li><p>Let <var>old chain</var> be the <a href=#current-focus-chain-of-a-top-level-traversable id=focus-processing-model:current-focus-chain-of-a-top-level-traversable-2>current focus chain of the top-level traversable</a> in which <var>old focus target</var> finds itself.<li><p>If <var>old focus target</var> is not one of the entries in <var>old chain</var>, then return.<li><p>If <var>old focus target</var> is not a <a href=#focusable-area id=focus-processing-model:focusable-area-14>focusable area</a>, then return.<li><p>Let <var>topDocument</var> be <var>old chain</var>'s last entry.<li> <p>If <var>topDocument</var>'s <a id=focus-processing-model:node-navigable href=document-sequences.html#node-navigable>node navigable</a> has <a href=#system-focus id=focus-processing-model:system-focus>system focus</a>, then run the <a href=#focusing-steps id=focus-processing-model:focusing-steps-3>focusing steps</a> for <var>topDocument</var>'s <a id=focus-processing-model:viewport-2 href=https://drafts.csswg.org/css2/#viewport data-x-internal=viewport>viewport</a>.</p> <p>Otherwise, apply any relevant platform-specific conventions for removing <a href=#system-focus id=focus-processing-model:system-focus-2>system focus</a> from <var>topDocument</var>'s <a id=focus-processing-model:node-navigable-2 href=document-sequences.html#node-navigable>node navigable</a>, and run the <a href=#focus-update-steps id=focus-processing-model:focus-update-steps-2>focus update steps</a> given <var>old chain</var>, an empty list, and null.</p> </ol> <p class=note>The <a href=#unfocusing-steps id=focus-processing-model:unfocusing-steps>unfocusing steps</a> do not always result in the focus changing, even when applied to the <a href=#currently-focused-area-of-a-top-level-traversable id=focus-processing-model:currently-focused-area-of-a-top-level-traversable-8>currently focused area of a top-level traversable</a>. For example, if the <a href=#currently-focused-area-of-a-top-level-traversable id=focus-processing-model:currently-focused-area-of-a-top-level-traversable-9>currently focused area of a top-level traversable</a> is a <a id=focus-processing-model:viewport-3 href=https://drafts.csswg.org/css2/#viewport data-x-internal=viewport>viewport</a>, then it will usually keep its focus regardless until another <a href=#focusable-area id=focus-processing-model:focusable-area-15>focusable area</a> is explicitly focused with the <a href=#focusing-steps id=focus-processing-model:focusing-steps-4>focusing steps</a>.</p> <hr> <p>The <dfn id=focus-update-steps>focus update steps</dfn>, given an <var>old chain</var>, a <var>new chain</var>, and a <var>new focus target</var> respectively, are as follows:</p> <ol><li><p>If the last entry in <var>old chain</var> and the last entry in <var>new chain</var> are the same, pop the last entry from <var>old chain</var> and the last entry from <var>new chain</var> and redo this step.<li> <p>For each entry <var>entry</var> in <var>old chain</var>, in order, run these substeps:</p> <ol><li> <p>If <var>entry</var> is an <code id=focus-processing-model:the-input-element><a href=input.html#the-input-element>input</a></code> element, and the <code id=focus-processing-model:event-change><a href=indices.html#event-change>change</a></code> event <a href=input.html#concept-input-apply id=focus-processing-model:concept-input-apply>applies</a> to the element, and the element does not have a defined <a id=focus-processing-model:activation-behaviour href=https://dom.spec.whatwg.org/#eventtarget-activation-behavior data-x-internal=activation-behaviour>activation behavior</a>, and the user has changed the element's <a href=form-control-infrastructure.html#concept-fe-value id=focus-processing-model:concept-fe-value>value</a> or its list of <a href=input.html#concept-input-type-file-selected id=focus-processing-model:concept-input-type-file-selected>selected files</a> while the control was focused without committing that change (such that it is different to what it was when the control was first focused), then:</p> <ol><li><p>Set <var>entry</var>'s <a id=focus-processing-model:user-validity href=form-control-infrastructure.html#user-validity>user validity</a> to true.<li id=unfocus-causes-change-event><p><a href=https://dom.spec.whatwg.org/#concept-event-fire id=focus-processing-model:concept-event-fire data-x-internal=concept-event-fire>Fire an event</a> named <code id=focus-processing-model:event-change-2><a href=indices.html#event-change>change</a></code> at the element, with the <code id=focus-processing-model:dom-event-bubbles><a data-x-internal=dom-event-bubbles href=https://dom.spec.whatwg.org/#dom-event-bubbles>bubbles</a></code> attribute initialized to true.</ol> <li> <p>If <var>entry</var> is an element, let <var>blur event target</var> be <var>entry</var>.</p> <p>If <var>entry</var> is a <code id=focus-processing-model:document-3><a href=dom.html#document>Document</a></code> object, let <var>blur event target</var> be that <code id=focus-processing-model:document-4><a href=dom.html#document>Document</a></code> object's <a id=focus-processing-model:concept-relevant-global href=webappapis.html#concept-relevant-global>relevant global object</a>.</p> <p>Otherwise, let <var>blur event target</var> be null.</p> <li><p>If <var>entry</var> is the last entry in <var>old chain</var>, and <var>entry</var> is an <code id=focus-processing-model:element><a data-x-internal=element href=https://dom.spec.whatwg.org/#interface-element>Element</a></code>, and the last entry in <var>new chain</var> is also an <code id=focus-processing-model:element-2><a data-x-internal=element href=https://dom.spec.whatwg.org/#interface-element>Element</a></code>, then let <var>related blur target</var> be the last entry in <var>new chain</var>. Otherwise, let <var>related blur target</var> be null.<li> <p>If <var>blur event target</var> is not null, <a href=#fire-a-focus-event id=focus-processing-model:fire-a-focus-event>fire a focus event</a> named <code id=focus-processing-model:event-blur><a href=indices.html#event-blur>blur</a></code> at <var>blur event target</var>, with <var>related blur target</var> as the related target.</p> <p id=note-sometimes-no-blur-event class=note>In some cases, e.g., if <var>entry</var> is an <code id=focus-processing-model:the-area-element-4><a href=image-maps.html#the-area-element>area</a></code> element's shape, a scrollable region, or a <a id=focus-processing-model:viewport-4 href=https://drafts.csswg.org/css2/#viewport data-x-internal=viewport>viewport</a>, no event is fired.</p> </ol> <li><p>Apply any relevant platform-specific conventions for focusing <var>new focus target</var>. (For example, some platforms select the contents of a text control when that control is focused.)<li> <p>For each entry <var>entry</var> in <var>new chain</var>, in reverse order, run these substeps:</p> <ol><li> <p>If <var>entry</var> is a <a href=#focusable-area id=focus-processing-model:focusable-area-16>focusable area</a>, and the <a href=#focused-area-of-the-document id=focus-processing-model:focused-area-of-the-document>focused area of the document</a> is not <var>entry</var>:</p> <ol><li><p>Set <var>document</var>'s <a id=focus-processing-model:concept-relevant-global-2 href=webappapis.html#concept-relevant-global>relevant global object</a>'s <a href=nav-history-apis.html#window-navigation-api id=focus-processing-model:window-navigation-api>navigation API</a>'s <a id=focus-processing-model:focus-changed-during-ongoing-navigation href=nav-history-apis.html#focus-changed-during-ongoing-navigation>focus changed during ongoing navigation</a> to true.<li><p>Designate <var>entry</var> as the <a href=#focused-area-of-the-document id=focus-processing-model:focused-area-of-the-document-2>focused area of the document</a>.</p> </ol> <li> <p>If <var>entry</var> is an element, let <var>focus event target</var> be <var>entry</var>.</p> <p>If <var>entry</var> is a <code id=focus-processing-model:document-5><a href=dom.html#document>Document</a></code> object, let <var>focus event target</var> be that <code id=focus-processing-model:document-6><a href=dom.html#document>Document</a></code> object's <a id=focus-processing-model:concept-relevant-global-3 href=webappapis.html#concept-relevant-global>relevant global object</a>.</p> <p>Otherwise, let <var>focus event target</var> be null.</p> <li><p>If <var>entry</var> is the last entry in <var>new chain</var>, and <var>entry</var> is an <code id=focus-processing-model:element-3><a data-x-internal=element href=https://dom.spec.whatwg.org/#interface-element>Element</a></code>, and the last entry in <var>old chain</var> is also an <code id=focus-processing-model:element-4><a data-x-internal=element href=https://dom.spec.whatwg.org/#interface-element>Element</a></code>, then let <var>related focus target</var> be the last entry in <var>old chain</var>. Otherwise, let <var>related focus target</var> be null.<li> <p>If <var>focus event target</var> is not null, <a href=#fire-a-focus-event id=focus-processing-model:fire-a-focus-event-2>fire a focus event</a> named <code id=focus-processing-model:event-focus><a href=indices.html#event-focus>focus</a></code> at <var>focus event target</var>, with <var>related focus target</var> as the related target.</p> <p class=note>In some cases, e.g. if <var>entry</var> is an <code id=focus-processing-model:the-area-element-5><a href=image-maps.html#the-area-element>area</a></code> element's shape, a scrollable region, or a <a id=focus-processing-model:viewport-5 href=https://drafts.csswg.org/css2/#viewport data-x-internal=viewport>viewport</a>, no event is fired.</p> </ol> </ol> <p>To <dfn id=fire-a-focus-event>fire a focus event</dfn> named <var>e</var> at an element <var>t</var> with a given related target <var>r</var>, <a href=https://dom.spec.whatwg.org/#concept-event-fire id=focus-processing-model:concept-event-fire-2 data-x-internal=concept-event-fire>fire an event</a> named <var>e</var> at <var>t</var>, using <code id=focus-processing-model:focusevent><a data-x-internal=focusevent href=https://w3c.github.io/uievents/#focusevent>FocusEvent</a></code>, with the <code id=focus-processing-model:dom-focusevent-relatedtarget><a data-x-internal=dom-focusevent-relatedtarget href=https://w3c.github.io/uievents/#dom-focusevent-relatedtarget>relatedTarget</a></code> attribute initialized to <var>r</var>, the <code id=focus-processing-model:dom-uievent-view><a data-x-internal=dom-uievent-view href=https://w3c.github.io/uievents/#dom-uievent-view>view</a></code> attribute initialized to <var>t</var>'s <a id=focus-processing-model:node-document href=https://dom.spec.whatwg.org/#concept-node-document data-x-internal=node-document>node document</a>'s <a id=focus-processing-model:concept-relevant-global-4 href=webappapis.html#concept-relevant-global>relevant global object</a>, and the <a id=focus-processing-model:composed-flag href=https://dom.spec.whatwg.org/#composed-flag data-x-internal=composed-flag>composed flag</a> set.</p> <hr> <p>When a key event is to be routed in a <a id=focus-processing-model:top-level-traversable href=document-sequences.html#top-level-traversable>top-level traversable</a>, the user agent must run the following steps:</p> <ol><li><p>Let <var>target area</var> be the <a href=#currently-focused-area-of-a-top-level-traversable id=focus-processing-model:currently-focused-area-of-a-top-level-traversable-10>currently focused area of the top-level traversable</a>.<li><p><a id=focus-processing-model:assert href=https://infra.spec.whatwg.org/#assert data-x-internal=assert>Assert</a>: <var>target area</var> is not null, since key events are only routed to <a href=document-sequences.html#top-level-traversable id=focus-processing-model:top-level-traversable-2>top-level traversables</a> that have <a href=#system-focus id=focus-processing-model:system-focus-3>system focus</a>. Therefore, <var>target area</var> is a <a href=#focusable-area id=focus-processing-model:focusable-area-17>focusable area</a>.<li><p>Let <var>target node</var> be <var>target area</var>'s <a href=#dom-anchor id=focus-processing-model:dom-anchor-5>DOM anchor</a>.<li> <p>If <var>target node</var> is a <code id=focus-processing-model:document-7><a href=dom.html#document>Document</a></code> that has a <a href=dom.html#the-body-element-2 id=focus-processing-model:the-body-element-2>body element</a>, then let <var>target node</var> be <a id=focus-processing-model:the-body-element-2-2 href=dom.html#the-body-element-2>the body element</a> of that <code id=focus-processing-model:document-8><a href=dom.html#document>Document</a></code>.</p> <p>Otherwise, if <var>target node</var> is a <code id=focus-processing-model:document-9><a href=dom.html#document>Document</a></code> object that has a non-null <a id=focus-processing-model:document-element-2 href=https://dom.spec.whatwg.org/#document-element data-x-internal=document-element>document element</a>, then let <var>target node</var> be that <a id=focus-processing-model:document-element-3 href=https://dom.spec.whatwg.org/#document-element data-x-internal=document-element>document element</a>.</p> <li> <p>If <var>target node</var> is not <a href=#inert id=focus-processing-model:inert-3>inert</a>, then:</p> <ol><li><p>Let <var>canHandle</var> be the result of <a href=https://dom.spec.whatwg.org/#concept-event-dispatch id=focus-processing-model:concept-event-dispatch data-x-internal=concept-event-dispatch>dispatching</a> the key event at <var>target node</var>.<li><p>If <var>canHandle</var> is true, then let <var>target area</var> handle the key event. This might include <a href=webappapis.html#fire-a-click-event id=focus-processing-model:fire-a-click-event>firing a <code>click</code> event</a> at <var>target node</var>.</ol> </ol> <hr> <p>The <dfn id=has-focus-steps data-export="">has focus steps</dfn>, given a <code id=focus-processing-model:document-10><a href=dom.html#document>Document</a></code> object <var>target</var>, are as follows:</p> <ol><li><p>If <var>target</var>'s <a id=focus-processing-model:node-navigable-3 href=document-sequences.html#node-navigable>node navigable</a>'s <a href=document-sequences.html#nav-top id=focus-processing-model:nav-top>top-level traversable</a> does not have <a href=#system-focus id=focus-processing-model:system-focus-4>system focus</a>, then return false.<li><p>Let <var>candidate</var> be <var>target</var>'s <a id=focus-processing-model:node-navigable-4 href=document-sequences.html#node-navigable>node navigable</a>'s <a href=document-sequences.html#nav-top id=focus-processing-model:nav-top-2>top-level traversable</a>'s <a id=focus-processing-model:active-document href=document-sequences.html#active-document>active document</a>.<li> <p>While true:</p> <ol><li><p>If <var>candidate</var> is <var>target</var>, then return true.<li><p>If the <a href=#focused-area-of-the-document id=focus-processing-model:focused-area-of-the-document-3>focused area</a> of <var>candidate</var> is a <a id=focus-processing-model:navigable-container-4 href=document-sequences.html#navigable-container>navigable container</a> with a non-null <a id=focus-processing-model:content-navigable-5 href=document-sequences.html#content-navigable>content navigable</a>, then set <var>candidate</var> to the <a href=document-sequences.html#nav-document id=focus-processing-model:nav-document-4>active document</a> of that <a id=focus-processing-model:navigable-container-5 href=document-sequences.html#navigable-container>navigable container</a>'s <a id=focus-processing-model:content-navigable-6 href=document-sequences.html#content-navigable>content navigable</a>.<li><p>Otherwise, return false.</ol> </ol> <h4 id=sequential-focus-navigation><span class=secno>6.6.5</span> <dfn>Sequential focus navigation</dfn><a href=#sequential-focus-navigation class=self-link></a></h4> <p>Each <code id=sequential-focus-navigation:document><a href=dom.html#document>Document</a></code> has a <dfn id=sequential-focus-navigation-order>sequential focus navigation order</dfn>, which orders some or all of the <a href=#focusable-area id=sequential-focus-navigation:focusable-area>focusable areas</a> in the <code id=sequential-focus-navigation:document-2><a href=dom.html#document>Document</a></code> relative to each other. Its contents and ordering are given by the <a href=#flattened-tabindex-ordered-focus-navigation-scope id=sequential-focus-navigation:flattened-tabindex-ordered-focus-navigation-scope>flattened tabindex-ordered focus navigation scope</a> of the <code id=sequential-focus-navigation:document-3><a href=dom.html#document>Document</a></code>.</p> <p class=note>Per the rules defining the <a href=#flattened-tabindex-ordered-focus-navigation-scope id=sequential-focus-navigation:flattened-tabindex-ordered-focus-navigation-scope-2>flattened tabindex-ordered focus navigation scope</a>, the ordering is not necessarily related to the <a id=sequential-focus-navigation:tree-order href=https://dom.spec.whatwg.org/#concept-tree-order data-x-internal=tree-order>tree order</a> of the <code id=sequential-focus-navigation:document-4><a href=dom.html#document>Document</a></code>.</p> <p>If a <a href=#focusable-area id=sequential-focus-navigation:focusable-area-2>focusable area</a> is omitted from the <a href=#sequential-focus-navigation-order id=sequential-focus-navigation:sequential-focus-navigation-order>sequential focus navigation order</a> of its <code id=sequential-focus-navigation:document-5><a href=dom.html#document>Document</a></code>, then it is unreachable via <a href=#sequential-focus-navigation id=sequential-focus-navigation:sequential-focus-navigation>sequential focus navigation</a>.</p> <p>There can also be a <dfn id=sequential-focus-navigation-starting-point>sequential focus navigation starting point</dfn>. It is initially unset. The user agent may set it when the user indicates that it should be moved.</p> <p class=example>For example, the user agent could set it to the position of the user's click if the user clicks on the document contents.</p> <p class=note>User agents are required to set the <a href=#sequential-focus-navigation-starting-point id=sequential-focus-navigation:sequential-focus-navigation-starting-point>sequential focus navigation starting point</a> to the <a id=sequential-focus-navigation:target-element href=browsing-the-web.html#target-element>target element</a> when <a href=browsing-the-web.html#navigate-fragid id=sequential-focus-navigation:navigate-fragid>navigating to a fragment</a>.</p> <p>A <dfn id=sequential-focus-direction>sequential focus direction</dfn> is one of two possible values: "<dfn id=sequential-focus-forward><code>forward</code></dfn>", or "<dfn id=sequential-focus-backward><code>backward</code></dfn>". They are used in the below algorithms to describe the direction in which sequential focus travels at the user's request.</p> <p>A <dfn id=selection-mechanism>selection mechanism</dfn> is one of two possible values: "<dfn id=selection-mechanism-dom><code>DOM</code></dfn>", or "<dfn id=selection-mechanism-sequential><code>sequential</code></dfn>". They are used to describe how the <a href=#sequential-navigation-search-algorithm id=sequential-focus-navigation:sequential-navigation-search-algorithm>sequential navigation search algorithm</a> finds the <a href=#focusable-area id=sequential-focus-navigation:focusable-area-3>focusable area</a> it returns.</p> <p>When the user requests that focus move from the <a href=#currently-focused-area-of-a-top-level-traversable id=sequential-focus-navigation:currently-focused-area-of-a-top-level-traversable>currently focused area of a top-level traversable</a> to the next or previous <a href=#focusable-area id=sequential-focus-navigation:focusable-area-4>focusable area</a> (e.g., as the default action of pressing the <kbd><kbd>tab</kbd></kbd> key), or when the user requests that focus sequentially move to a <a id=sequential-focus-navigation:top-level-traversable href=document-sequences.html#top-level-traversable>top-level traversable</a> in the first place (e.g., from the browser's location bar), the user agent must use the following algorithm:</p> <ol><li><p>Let <var>starting point</var> be the <a href=#currently-focused-area-of-a-top-level-traversable id=sequential-focus-navigation:currently-focused-area-of-a-top-level-traversable-2>currently focused area of a top-level traversable</a>, if the user requested to move focus sequentially from there, or else the <a id=sequential-focus-navigation:top-level-traversable-2 href=document-sequences.html#top-level-traversable>top-level traversable</a> itself, if the user instead requested to move focus from outside the <a id=sequential-focus-navigation:top-level-traversable-3 href=document-sequences.html#top-level-traversable>top-level traversable</a>.<li><p>If there is a <a href=#sequential-focus-navigation-starting-point id=sequential-focus-navigation:sequential-focus-navigation-starting-point-2>sequential focus navigation starting point</a> defined and it is inside <var>starting point</var>, then let <var>starting point</var> be the <a href=#sequential-focus-navigation-starting-point id=sequential-focus-navigation:sequential-focus-navigation-starting-point-3>sequential focus navigation starting point</a> instead.<li> <p>Let <var>direction</var> be "<code id=sequential-focus-navigation:sequential-focus-forward><a href=#sequential-focus-forward>forward</a></code>" if the user requested the next control, and "<code id=sequential-focus-navigation:sequential-focus-backward><a href=#sequential-focus-backward>backward</a></code>" if the user requested the previous control.</p> <p class=note>Typically, pressing <kbd><kbd>tab</kbd></kbd> requests the next control, and pressing <kbd><kbd>shift</kbd> + <kbd>tab</kbd></kbd> requests the previous control.</p> <li> <p><i>Loop</i>: Let <var>selection mechanism</var> be "<code id=sequential-focus-navigation:selection-mechanism-sequential><a href=#selection-mechanism-sequential>sequential</a></code>" if <var>starting point</var> is a <a id=sequential-focus-navigation:navigable href=document-sequences.html#navigable>navigable</a> or if <var>starting point</var> is in its <code id=sequential-focus-navigation:document-6><a href=dom.html#document>Document</a></code>'s <a href=#sequential-focus-navigation-order id=sequential-focus-navigation:sequential-focus-navigation-order-2>sequential focus navigation order</a>.</p> <p>Otherwise, <var>starting point</var> is not in its <code id=sequential-focus-navigation:document-7><a href=dom.html#document>Document</a></code>'s <a href=#sequential-focus-navigation-order id=sequential-focus-navigation:sequential-focus-navigation-order-3>sequential focus navigation order</a>; let <var>selection mechanism</var> be "<code id=sequential-focus-navigation:selection-mechanism-dom><a href=#selection-mechanism-dom>DOM</a></code>".</p> <li><p>Let <var>candidate</var> be the result of running the <a href=#sequential-navigation-search-algorithm id=sequential-focus-navigation:sequential-navigation-search-algorithm-2>sequential navigation search algorithm</a> with <var>starting point</var>, <var>direction</var>, and <var>selection mechanism</var>.<li><p>If <var>candidate</var> is not null, then run the <a href=#focusing-steps id=sequential-focus-navigation:focusing-steps>focusing steps</a> for <var>candidate</var> and return.<li><p>Otherwise, unset the <a href=#sequential-focus-navigation-starting-point id=sequential-focus-navigation:sequential-focus-navigation-starting-point-4>sequential focus navigation starting point</a>.<li> <p>If <var>starting point</var> is a <a id=sequential-focus-navigation:top-level-traversable-4 href=document-sequences.html#top-level-traversable>top-level traversable</a>, or a <a href=#focusable-area id=sequential-focus-navigation:focusable-area-5>focusable area</a> in the <a id=sequential-focus-navigation:top-level-traversable-5 href=document-sequences.html#top-level-traversable>top-level traversable</a>, the user agent should transfer focus to its own controls appropriately (if any), honouring <var>direction</var>, and then return.</p> <p class=example>For example, if <var>direction</var> is <i>backward</i>, then the last <a href=#sequentially-focusable id=sequential-focus-navigation:sequentially-focusable>sequentially focusable</a> control before the browser's rendering area would be the control to focus.</p> <p>If the user agent has no <a href=#sequentially-focusable id=sequential-focus-navigation:sequentially-focusable-2>sequentially focusable</a> controls — a kiosk-mode browser, for instance — then the user agent may instead restart these steps with the <var>starting point</var> being the <a id=sequential-focus-navigation:top-level-traversable-6 href=document-sequences.html#top-level-traversable>top-level traversable</a> itself.</p> <li><p>Otherwise, <var>starting point</var> is a <a href=#focusable-area id=sequential-focus-navigation:focusable-area-6>focusable area</a> in a <a id=sequential-focus-navigation:child-navigable href=document-sequences.html#child-navigable>child navigable</a>. Set <var>starting point</var> to that <a id=sequential-focus-navigation:child-navigable-2 href=document-sequences.html#child-navigable>child navigable</a>'s <a href=document-sequences.html#nav-parent id=sequential-focus-navigation:nav-parent>parent</a> and return to the step labeled <i>loop</i>.</ol> <p>The <dfn id=sequential-navigation-search-algorithm>sequential navigation search algorithm</dfn>, given a <a href=#focusable-area id=sequential-focus-navigation:focusable-area-7>focusable area</a> <var>starting point</var>, <a href=#sequential-focus-direction id=sequential-focus-navigation:sequential-focus-direction>sequential focus direction</a> <var>direction</var>, and <a href=#selection-mechanism id=sequential-focus-navigation:selection-mechanism>selection mechanism</a> <var>selection mechanism</var>, consists of the following steps. They return a <a href=#focusable-area id=sequential-focus-navigation:focusable-area-8>focusable area</a>-or-null.</p> <ol><li> <p>Pick the appropriate cell from the following table, and follow the instructions in that cell.</p> <p>The appropriate cell is the one that is from the column whose header describes <var>direction</var> and from the first row whose header describes <var>starting point</var> and <var>selection mechanism</var>.</p> <table><thead><tr><th> <th><var>direction</var> is "<code id=sequential-focus-navigation:sequential-focus-forward-2><a href=#sequential-focus-forward>forward</a></code>" <th><var>direction</var> is "<code id=sequential-focus-navigation:sequential-focus-backward-2><a href=#sequential-focus-backward>backward</a></code>" <tbody><tr><th><var>starting point</var> is a <a id=sequential-focus-navigation:navigable-2 href=document-sequences.html#navigable>navigable</a> <td>Let <var>candidate</var> be the first <a href=#suitable-sequentially-focusable-area id=sequential-focus-navigation:suitable-sequentially-focusable-area>suitable sequentially focusable area</a> in <var>starting point</var>'s <a href=document-sequences.html#nav-document id=sequential-focus-navigation:nav-document>active document</a>, if any; or else null <td>Let <var>candidate</var> be the last <a href=#suitable-sequentially-focusable-area id=sequential-focus-navigation:suitable-sequentially-focusable-area-2>suitable sequentially focusable area</a> in <var>starting point</var>'s <a href=document-sequences.html#nav-document id=sequential-focus-navigation:nav-document-2>active document</a>, if any; or else null <tr><th><var>selection mechanism</var> is "<code id=sequential-focus-navigation:selection-mechanism-dom-2><a href=#selection-mechanism-dom>DOM</a></code>" <td> <p>Let <var>candidate</var> be the <a href=#suitable-sequentially-focusable-area id=sequential-focus-navigation:suitable-sequentially-focusable-area-3>suitable sequentially focusable area</a>, that appears nearest after <var>starting point</var> in <var>starting point</var>'s <code id=sequential-focus-navigation:document-8><a href=dom.html#document>Document</a></code>, in <a id=sequential-focus-navigation:shadow-including-tree-order href=https://dom.spec.whatwg.org/#concept-shadow-including-tree-order data-x-internal=shadow-including-tree-order>shadow-including tree order</a>, if any; or else null</p> <p class=note>In this case, <var>starting point</var> does not necessarily belong to its <code id=sequential-focus-navigation:document-9><a href=dom.html#document>Document</a></code>'s <a href=#sequential-focus-navigation-order id=sequential-focus-navigation:sequential-focus-navigation-order-4>sequential focus navigation order</a>, so we'll select the <a href=#suitable-sequentially-focusable-area id=sequential-focus-navigation:suitable-sequentially-focusable-area-4>suitable</a> <a href=https://infra.spec.whatwg.org/#list-item id=sequential-focus-navigation:list-item data-x-internal=list-item>item</a> from that list that comes <em>after</em> <var>starting point</var> in <a id=sequential-focus-navigation:shadow-including-tree-order-2 href=https://dom.spec.whatwg.org/#concept-shadow-including-tree-order data-x-internal=shadow-including-tree-order>shadow-including tree order</a>.</p> <td>Let <var>candidate</var> be the <a href=#suitable-sequentially-focusable-area id=sequential-focus-navigation:suitable-sequentially-focusable-area-5>suitable sequentially focusable area</a>, that appears nearest before <var>starting point</var> in <var>starting point</var>'s <code id=sequential-focus-navigation:document-10><a href=dom.html#document>Document</a></code>, in <a id=sequential-focus-navigation:shadow-including-tree-order-3 href=https://dom.spec.whatwg.org/#concept-shadow-including-tree-order data-x-internal=shadow-including-tree-order>shadow-including tree order</a>, if any; or else null <tr><th><var>selection mechanism</var> is "<code id=sequential-focus-navigation:selection-mechanism-sequential-2><a href=#selection-mechanism-sequential>sequential</a></code>" <td>Let <var>candidate</var> be the first <a href=#suitable-sequentially-focusable-area id=sequential-focus-navigation:suitable-sequentially-focusable-area-6>suitable sequentially focusable area</a> after <var>starting point</var>, in <var>starting point</var>'s <code id=sequential-focus-navigation:document-11><a href=dom.html#document>Document</a></code>'s <a href=#sequential-focus-navigation-order id=sequential-focus-navigation:sequential-focus-navigation-order-5>sequential focus navigation order</a>, if any; or else null <td>Let <var>candidate</var> be the last <a href=#suitable-sequentially-focusable-area id=sequential-focus-navigation:suitable-sequentially-focusable-area-7>suitable sequentially focusable area</a> before <var>starting point</var>, in <var>starting point</var>'s <code id=sequential-focus-navigation:document-12><a href=dom.html#document>Document</a></code>'s <a href=#sequential-focus-navigation-order id=sequential-focus-navigation:sequential-focus-navigation-order-6>sequential focus navigation order</a>, if any; or else null </table> <p>A <dfn id=suitable-sequentially-focusable-area>suitable sequentially focusable area</dfn> is a <a href=#focusable-area id=sequential-focus-navigation:focusable-area-9>focusable area</a> whose <a href=#dom-anchor id=sequential-focus-navigation:dom-anchor>DOM anchor</a> is not <a href=#inert id=sequential-focus-navigation:inert>inert</a> and is <a href=#sequentially-focusable id=sequential-focus-navigation:sequentially-focusable-3>sequentially focusable</a>.</p> <li> <p>If <var>candidate</var> is a <a id=sequential-focus-navigation:navigable-container href=document-sequences.html#navigable-container>navigable container</a> with a non-null <a id=sequential-focus-navigation:content-navigable href=document-sequences.html#content-navigable>content navigable</a>, then:</p> <ol><li><p>Let <var>recursive candidate</var> be the result of running the <a href=#sequential-navigation-search-algorithm id=sequential-focus-navigation:sequential-navigation-search-algorithm-3>sequential navigation search algorithm</a> with <var>candidate</var>'s <a id=sequential-focus-navigation:content-navigable-2 href=document-sequences.html#content-navigable>content navigable</a>, <var>direction</var>, and "<code id=sequential-focus-navigation:selection-mechanism-sequential-3><a href=#selection-mechanism-sequential>sequential</a></code>".<li><p>If <var>recursive candidate</var> is null, then return the result of running the <a href=#sequential-navigation-search-algorithm id=sequential-focus-navigation:sequential-navigation-search-algorithm-4>sequential navigation search algorithm</a> with <var>candidate</var>, <var>direction</var>, and <var>selection mechanism</var>.<li><p>Otherwise, set <var>candidate</var> to <var>recursive candidate</var>.</ol> <li><p>Return <var>candidate</var>.</ol> <h4 id=focus-management-apis><span class=secno>6.6.6</span> Focus management APIs<a href=#focus-management-apis class=self-link></a></h4> <pre><code class='idl'><c- b>dictionary</c-> <dfn id='focusoptions' data-dfn-type='dictionary'><c- g>FocusOptions</c-></dfn> { <c- b>boolean</c-> <a href='#dom-focusoptions-preventscroll' id='focus-management-apis:dom-focusoptions-preventscroll'><c- g>preventScroll</c-></a> = <c- b>false</c->; <c- b>boolean</c-> <a href='#dom-focusoptions-focusvisible' id='focus-management-apis:dom-focusoptions-focusvisible'><c- g>focusVisible</c-></a>; };</code></pre> <dl class=domintro><dt><code><var>documentOrShadowRoot</var>.<a href=#dom-documentorshadowroot-activeelement id=dom-documentorshadowroot-activeelement-dev>activeElement</a></code><div class="mdn-anno wrapped before"><button onclick=toggleStatus(this) class=mdn-anno-btn><b title="Support in all current engines." class=all-engines-flag>✔</b><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/API/Document/activeElement title="The activeElement read-only property of the Document interface returns the Element within the DOM that currently has focus.">Document/activeElement</a><p class=all-engines-text>Support in all current engines.<div class=support><span class="firefox yes"><span>Firefox</span><span>3+</span></span><span class="safari yes"><span>Safari</span><span>4+</span></span><span class="chrome yes"><span>Chrome</span><span>2+</span></span><hr><span class="opera yes"><span>Opera</span><span>12.1+</span></span><span class="edge_blink yes"><span>Edge</span><span>79+</span></span><hr><span class="edge yes"><span>Edge (Legacy)</span><span>12+</span></span><span class="ie yes"><span>Internet Explorer</span><span>6+</span></span><hr><span class="firefox_android unknown"><span>Firefox Android</span><span>?</span></span><span class="safari_ios unknown"><span>Safari iOS</span><span>?</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android yes"><span>WebView Android</span><span>37+</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android yes"><span>Opera Android</span><span>12.1+</span></span></div></div><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot/activeElement title="The activeElement read-only property of the ShadowRoot interface returns the element within the shadow tree that has focus.">ShadowRoot/activeElement</a><p class=all-engines-text>Support in all current engines.<div class=support><span class="firefox yes"><span>Firefox</span><span>63+</span></span><span class="safari yes"><span>Safari</span><span>10+</span></span><span class="chrome yes"><span>Chrome</span><span>53+</span></span><hr><span class="opera unknown"><span>Opera</span><span>?</span></span><span class="edge_blink yes"><span>Edge</span><span>79+</span></span><hr><span class="edge unknown"><span>Edge (Legacy)</span><span>?</span></span><span class="ie no"><span>Internet Explorer</span><span>No</span></span><hr><span class="firefox_android unknown"><span>Firefox Android</span><span>?</span></span><span class="safari_ios unknown"><span>Safari iOS</span><span>?</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android unknown"><span>WebView Android</span><span>?</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android unknown"><span>Opera Android</span><span>?</span></span></div></div></div><dd> <p>Returns the deepest element in the document through which or to which key events are being routed. This is, roughly speaking, the focused element in the document.</p> <p>For the purposes of this API, when a <a id=focus-management-apis:child-navigable href=document-sequences.html#child-navigable>child navigable</a> is focused, its <a href=document-sequences.html#nav-container id=focus-management-apis:nav-container>container</a> is <a href=#bc-focus-ergo-bcc-focus>focused</a> within its <a href=document-sequences.html#nav-parent id=focus-management-apis:nav-parent>parent</a>'s <a href=document-sequences.html#nav-document id=focus-management-apis:nav-document>active document</a>. For example, if the user moves the focus to a text control in an <code id=focus-management-apis:the-iframe-element><a href=iframe-embed-object.html#the-iframe-element>iframe</a></code>, the <code id=focus-management-apis:the-iframe-element-2><a href=iframe-embed-object.html#the-iframe-element>iframe</a></code> is the element returned by the <code id=focus-management-apis:dom-documentorshadowroot-activeelement><a href=#dom-documentorshadowroot-activeelement>activeElement</a></code> API in the <code id=focus-management-apis:the-iframe-element-3><a href=iframe-embed-object.html#the-iframe-element>iframe</a></code>'s <a id=focus-management-apis:node-document href=https://dom.spec.whatwg.org/#concept-node-document data-x-internal=node-document>node document</a>.</p> <p>Similarly, when the focused element is in a different <a id=focus-management-apis:node-tree href=https://dom.spec.whatwg.org/#concept-node-tree data-x-internal=node-tree>node tree</a> than <var>documentOrShadowRoot</var>, the element returned will be the <a href=https://dom.spec.whatwg.org/#concept-documentfragment-host id=focus-management-apis:concept-documentfragment-host data-x-internal=concept-documentfragment-host>host</a> that's located in the same <a id=focus-management-apis:node-tree-2 href=https://dom.spec.whatwg.org/#concept-node-tree data-x-internal=node-tree>node tree</a> as <var>documentOrShadowRoot</var> if <var>documentOrShadowRoot</var> is a <a id=focus-management-apis:shadow-including-inclusive-ancestor href=https://dom.spec.whatwg.org/#concept-shadow-including-inclusive-ancestor data-x-internal=shadow-including-inclusive-ancestor>shadow-including inclusive ancestor</a> of the focused element, and null if not.</p> <dt><code><var>document</var>.<a href=#dom-document-hasfocus id=dom-document-hasfocus-dev>hasFocus</a>()</code><div class="mdn-anno wrapped before"><button onclick=toggleStatus(this) class=mdn-anno-btn><b title="Support in all current engines." class=all-engines-flag>✔</b><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/API/Document/hasFocus title="The hasFocus() method of the Document interface returns a boolean value indicating whether the document or any element inside the document has focus. This method can be used to determine whether the active element in a document has focus.">Document/hasFocus</a><p class=all-engines-text>Support in all current engines.<div class=support><span class="firefox yes"><span>Firefox</span><span>3+</span></span><span class="safari yes"><span>Safari</span><span>4+</span></span><span class="chrome yes"><span>Chrome</span><span>2+</span></span><hr><span class="opera unknown"><span>Opera</span><span>?</span></span><span class="edge_blink yes"><span>Edge</span><span>79+</span></span><hr><span class="edge yes"><span>Edge (Legacy)</span><span>12+</span></span><span class="ie yes"><span>Internet Explorer</span><span>5.5+</span></span><hr><span class="firefox_android unknown"><span>Firefox Android</span><span>?</span></span><span class="safari_ios unknown"><span>Safari iOS</span><span>?</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android yes"><span>WebView Android</span><span>37+</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android unknown"><span>Opera Android</span><span>?</span></span></div></div></div><dd> <p>Returns true if key events are being routed through or to the document; otherwise, returns false. Roughly speaking, this corresponds to the document, or a document nested inside this one, being focused.</p> <dt><code><var>window</var>.<a href=#dom-window-focus id=dom-window-focus-dev>focus</a>()</code><div class="mdn-anno wrapped before"><button onclick=toggleStatus(this) class=mdn-anno-btn><b title="Support in all current engines." class=all-engines-flag>✔</b><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/API/Window/focus title="Makes a request to bring the window to the front. It may fail due to user settings and the window isn't guaranteed to be frontmost before this method returns.">Window/focus</a><p class=all-engines-text>Support in all current engines.<div class=support><span class="firefox yes"><span>Firefox</span><span>1+</span></span><span class="safari yes"><span>Safari</span><span>1+</span></span><span class="chrome yes"><span>Chrome</span><span>1+</span></span><hr><span class="opera yes"><span>Opera</span><span>12.1+</span></span><span class="edge_blink yes"><span>Edge</span><span>79+</span></span><hr><span class="edge yes"><span>Edge (Legacy)</span><span>12+</span></span><span class="ie yes"><span>Internet Explorer</span><span>4+</span></span><hr><span class="firefox_android unknown"><span>Firefox Android</span><span>?</span></span><span class="safari_ios unknown"><span>Safari iOS</span><span>?</span></span><span class="chrome_android yes"><span>Chrome Android</span><span>18+</span></span><span class="webview_android unknown"><span>WebView Android</span><span>?</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android yes"><span>Opera Android</span><span>12.1+</span></span></div></div></div><dd> <p>Moves the focus to the window's <a href=nav-history-apis.html#window-navigable id=focus-management-apis:window-navigable>navigable</a>, if any.</p> <dt><code><var>element</var>.<a href=#dom-focus id=dom-focus-dev>focus</a>([ { <a href=#dom-focusoptions-preventscroll id=focus-management-apis:dom-focusoptions-preventscroll-2>preventScroll</a>: true } ])</code><div class="mdn-anno wrapped before"><button onclick=toggleStatus(this) class=mdn-anno-btn><b title="Support in all current engines." class=all-engines-flag>✔</b><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus title="The HTMLElement.focus() method sets focus on the specified element, if it can be focused. The focused element is the element that will receive keyboard and similar events by default.">HTMLElement/focus</a><p class=all-engines-text>Support in all current engines.<div class=support><span class="firefox yes"><span>Firefox</span><span>1.5+</span></span><span class="safari yes"><span>Safari</span><span>3+</span></span><span class="chrome yes"><span>Chrome</span><span>1+</span></span><hr><span class="opera yes"><span>Opera</span><span>8+</span></span><span class="edge_blink yes"><span>Edge</span><span>79+</span></span><hr><span class="edge yes"><span>Edge (Legacy)</span><span>12+</span></span><span class="ie yes"><span>Internet Explorer</span><span>5.5+</span></span><hr><span class="firefox_android unknown"><span>Firefox Android</span><span>?</span></span><span class="safari_ios yes"><span>Safari iOS</span><span>1+</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android unknown"><span>WebView Android</span><span>?</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android yes"><span>Opera Android</span><span>10.1+</span></span></div></div></div><dd> <p>Moves the focus to the element.</p> <p>If the element is a <a id=focus-management-apis:navigable-container href=document-sequences.html#navigable-container>navigable container</a>, moves the focus to its <a id=focus-management-apis:content-navigable href=document-sequences.html#content-navigable>content navigable</a> instead.</p> <p>By default, this method also scrolls the element into view. Providing the <code id=focus-management-apis:dom-focusoptions-preventscroll-3><a href=#dom-focusoptions-preventscroll>preventScroll</a></code> option and setting it to true prevents this behavior.</p> <dt><code><var>element</var>.<a href=#dom-blur id=dom-blur-dev>blur</a>()</code><div class="mdn-anno wrapped before"><button onclick=toggleStatus(this) class=mdn-anno-btn><b title="Support in all current engines." class=all-engines-flag>✔</b><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/blur title="The HTMLElement.blur() method removes keyboard focus from the current element.">HTMLElement/blur</a><p class=all-engines-text>Support in all current engines.<div class=support><span class="firefox yes"><span>Firefox</span><span>1.5+</span></span><span class="safari yes"><span>Safari</span><span>3+</span></span><span class="chrome yes"><span>Chrome</span><span>1+</span></span><hr><span class="opera yes"><span>Opera</span><span>8+</span></span><span class="edge_blink yes"><span>Edge</span><span>79+</span></span><hr><span class="edge yes"><span>Edge (Legacy)</span><span>12+</span></span><span class="ie yes"><span>Internet Explorer</span><span>5.5+</span></span><hr><span class="firefox_android unknown"><span>Firefox Android</span><span>?</span></span><span class="safari_ios yes"><span>Safari iOS</span><span>1+</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android unknown"><span>WebView Android</span><span>?</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android yes"><span>Opera Android</span><span>10.1+</span></span></div></div></div><dd> <p>Moves the focus to the <a id=focus-management-apis:viewport href=https://drafts.csswg.org/css2/#viewport data-x-internal=viewport>viewport</a>. Use of this method is discouraged; if you want to focus the <a id=focus-management-apis:viewport-2 href=https://drafts.csswg.org/css2/#viewport data-x-internal=viewport>viewport</a>, call the <code id=focus-management-apis:dom-focus><a href=#dom-focus>focus()</a></code> method on the <code id=focus-management-apis:document><a href=dom.html#document>Document</a></code>'s <a id=focus-management-apis:document-element href=https://dom.spec.whatwg.org/#document-element data-x-internal=document-element>document element</a>.</p> <p>Do not use this method to hide the focus ring if you find the focus ring unsightly. Instead, use the <code id=focus-management-apis::focus-visible><a data-x-internal=:focus-visible href=https://drafts.csswg.org/selectors/#the-focus-visible-pseudo>:focus-visible</a></code> pseudo-class to override the <a id="focus-management-apis:'outline'" href=https://drafts.csswg.org/css-ui/#outline data-x-internal="'outline'">'outline'</a> property, and provide a different way to show what element is focused. Be aware that if an alternative focusing style isn't made available, the page will be significantly less usable for people who primarily navigate pages using a keyboard, or those with reduced vision who use focus outlines to help them navigate the page.</p> <div class=example> <p>For example, to hide the outline from <code id=focus-management-apis:the-textarea-element><a href=form-elements.html#the-textarea-element>textarea</a></code> elements and instead use a yellow background to indicate focus, you could use:</p> <pre><code class='css'><c- f>textarea:focus-visible </c-><c- p>{</c-> <c- k>outline</c-><c- p>:</c-> none<c- p>;</c-> <c- k>background</c-><c- p>:</c-> yellow<c- p>;</c-> <c- k>color</c-><c- p>:</c-> black<c- p>;</c-> <c- p>}</c-></code></pre> </div> </dl> <p id=dom-document-activeelement>The <dfn data-dfn-for=DocumentOrShadowRoot id=dom-documentorshadowroot-activeelement data-dfn-type=attribute><code>activeElement</code></dfn> attribute's getter must run these steps:</p> <ol><li><p>Let <var>candidate</var> be the <a href=#dom-anchor id=focus-management-apis:dom-anchor>DOM anchor</a> of the <a href=#focused-area-of-the-document id=focus-management-apis:focused-area-of-the-document>focused area</a> of this <code id=focus-management-apis:documentorshadowroot><a href=dom.html#documentorshadowroot>DocumentOrShadowRoot</a></code>'s <a id=focus-management-apis:node-document-2 href=https://dom.spec.whatwg.org/#concept-node-document data-x-internal=node-document>node document</a>.<li><p>Set <var>candidate</var> to the result of <a href=https://dom.spec.whatwg.org/#retarget id=focus-management-apis:dom-retarget data-x-internal=dom-retarget>retargeting</a> <var>candidate</var> against this <code id=focus-management-apis:documentorshadowroot-2><a href=dom.html#documentorshadowroot>DocumentOrShadowRoot</a></code>.<li><p>If <var>candidate</var>'s <a id=focus-management-apis:root href=https://dom.spec.whatwg.org/#concept-tree-root data-x-internal=root>root</a> is not this <code id=focus-management-apis:documentorshadowroot-3><a href=dom.html#documentorshadowroot>DocumentOrShadowRoot</a></code>, then return null.<li><p>If <var>candidate</var> is not a <code id=focus-management-apis:document-2><a href=dom.html#document>Document</a></code> object, then return <var>candidate</var>.<li><p>If <var>candidate</var> has a <a href=dom.html#the-body-element-2 id=focus-management-apis:the-body-element-2>body element</a>, then return that <a href=dom.html#the-body-element-2 id=focus-management-apis:the-body-element-2-2>body element</a>.<li><p>If <var>candidate</var>'s <a id=focus-management-apis:document-element-2 href=https://dom.spec.whatwg.org/#document-element data-x-internal=document-element>document element</a> is non-null, then return that <a id=focus-management-apis:document-element-3 href=https://dom.spec.whatwg.org/#document-element data-x-internal=document-element>document element</a>.<li><p>Return null.</ol> <p>The <dfn data-dfn-for=Document id=dom-document-hasfocus data-dfn-type=method><code>hasFocus()</code></dfn> method on the <code id=focus-management-apis:document-3><a href=dom.html#document>Document</a></code> object, when invoked, must return the result of running the <a href=#has-focus-steps id=focus-management-apis:has-focus-steps>has focus steps</a> with the <code id=focus-management-apis:document-4><a href=dom.html#document>Document</a></code> object as the argument.</p> <p>The <dfn data-dfn-for=Window id=dom-window-focus data-dfn-type=method><code>focus()</code></dfn> method, when invoked, must run these steps:</p> <ol><li><p>Let <var>current</var> be this <code id=focus-management-apis:window><a href=nav-history-apis.html#window>Window</a></code> object's <a href=nav-history-apis.html#window-navigable id=focus-management-apis:window-navigable-2>navigable</a>.<li><p>If <var>current</var> is null, then return.<li><p>Run the <a href=#focusing-steps id=focus-management-apis:focusing-steps>focusing steps</a> with <var>current</var>.<li><p>If <var>current</var> is a <a id=focus-management-apis:top-level-traversable href=document-sequences.html#top-level-traversable>top-level traversable</a>, user agents are encouraged to trigger some sort of notification to indicate to the user that the page is attempting to gain focus.</ol> <div class="mdn-anno wrapped before"><button onclick=toggleStatus(this) class=mdn-anno-btn><b title="Support in all current engines." class=all-engines-flag>✔</b><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/API/Window/blur title="Shifts focus away from the window.">Window/blur</a><p class=all-engines-text>Support in all current engines.<div class=support><span class="firefox yes"><span>Firefox</span><span>1+</span></span><span class="safari yes"><span>Safari</span><span>1+</span></span><span class="chrome yes"><span>Chrome</span><span>1+</span></span><hr><span class="opera yes"><span>Opera</span><span>12.1+</span></span><span class="edge_blink yes"><span>Edge</span><span>79+</span></span><hr><span class="edge yes"><span>Edge (Legacy)</span><span>12+</span></span><span class="ie yes"><span>Internet Explorer</span><span>4+</span></span><hr><span class="firefox_android unknown"><span>Firefox Android</span><span>?</span></span><span class="safari_ios unknown"><span>Safari iOS</span><span>?</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android unknown"><span>WebView Android</span><span>?</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android yes"><span>Opera Android</span><span>12.1+</span></span></div></div></div><p>The <dfn data-dfn-for=Window id=dom-window-blur data-dfn-type=method><code>blur()</code></dfn> method steps are to do nothing.</p> <p class=note>Historically, the <code id=focus-management-apis:dom-window-focus><a href=#dom-window-focus>focus()</a></code> and <code id=focus-management-apis:dom-window-blur><a href=#dom-window-blur>blur()</a></code> methods actually affected the system-level focus of the system widget (e.g., tab or window) that contained the <a id=focus-management-apis:navigable href=document-sequences.html#navigable>navigable</a>, but hostile sites widely abuse this behavior to the user's detriment.</p> <p>The <dfn data-dfn-for=HTMLOrSVGElement id=dom-focus data-dfn-type=method><code>focus(<var>options</var>)</code></dfn> method on elements, when invoked, must run the following steps:</p> <ol><li><p>If the element is marked as <i id=focus-management-apis:locked-for-focus><a href=#locked-for-focus>locked for focus</a></i>, then return.<li><p>Mark the element as <dfn id=locked-for-focus>locked for focus</dfn>.<li><p>Run the <a href=#focusing-steps id=focus-management-apis:focusing-steps-2>focusing steps</a> for the element.<li><p>If the value of the <dfn data-dfn-for=FocusOptions id=dom-focusoptions-focusvisible data-dfn-type=dict-member><code>focusVisible</code></dfn> dictionary member of <var>options</var> is true, or is not present but in an <a id=focus-management-apis:implementation-defined href=https://infra.spec.whatwg.org/#implementation-defined data-x-internal=implementation-defined>implementation-defined</a> way the user agent determines it would be best to do so, then <a id=focus-management-apis:indicate-focus href=https://drafts.csswg.org/selectors/#indicate-focus data-x-internal=indicate-focus>indicate focus</a>.<li><p>If the value of the <dfn data-dfn-for=FocusOptions id=dom-focusoptions-preventscroll data-dfn-type=dict-member><code>preventScroll</code></dfn> dictionary member of <var>options</var> is false, then <a href=https://drafts.csswg.org/cssom-view/#scroll-a-target-into-view id=focus-management-apis:scroll-a-target-into-view data-x-internal=scroll-a-target-into-view>scroll the element into view</a> given "auto", "center", and "center".<li><p>Unmark the element as <i id=focus-management-apis:locked-for-focus-2><a href=#locked-for-focus>locked for focus</a></i>.</ol> <p>The <dfn data-dfn-for=HTMLOrSVGElement id=dom-blur data-dfn-type=method><code>blur()</code></dfn> method, when invoked, should run the <a href=#unfocusing-steps id=focus-management-apis:unfocusing-steps>unfocusing steps</a> for the element on which the method was called. User agents may selectively or uniformly ignore calls to this method for usability reasons.</p> <p class=example>For example, if the <code id=focus-management-apis:dom-blur><a href=#dom-blur>blur()</a></code> method is unwisely being used to remove the focus ring for aesthetics reasons, the page would become unusable by keyboard users. Ignoring calls to this method would thus allow keyboard users to interact with the page.</p> <h4 id=the-autofocus-attribute><span class=secno>6.6.7</span> <span id=autofocusing-a-form-control:-the-autofocus-attribute></span>The <code id=the-autofocus-attribute:attr-fe-autofocus><a href=#attr-fe-autofocus>autofocus</a></code> attribute<a href=#the-autofocus-attribute class=self-link></a></h4> <p>The <dfn data-dfn-for=html-global id=attr-fe-autofocus data-dfn-type=element-attr><code>autofocus</code></dfn> content attribute allows the author to indicate that an element is to be focused as soon as the page is loaded, allowing the user to just start typing without having to manually focus the main element.</p> <p>When the <code id=the-autofocus-attribute:attr-fe-autofocus-2><a href=#attr-fe-autofocus>autofocus</a></code> attribute is specified on an element inside <code id=the-autofocus-attribute:the-dialog-element><a href=interactive-elements.html#the-dialog-element>dialog</a></code> elements or <a id=the-autofocus-attribute:html-elements href=infrastructure.html#html-elements>HTML elements</a> whose <code id=the-autofocus-attribute:attr-popover><a href=popover.html#attr-popover>popover</a></code> attribute is set, then it will be focused when the dialog or popover becomes shown.</p> <p>The <code id=the-autofocus-attribute:attr-fe-autofocus-3><a href=#attr-fe-autofocus>autofocus</a></code> attribute is a <a id=the-autofocus-attribute:boolean-attribute href=common-microsyntaxes.html#boolean-attribute>boolean attribute</a>.</p> <p>To find the <dfn id=nearest-ancestor-autofocus-scoping-root-element>nearest ancestor autofocus scoping root element</dfn> given an <code id=the-autofocus-attribute:element><a data-x-internal=element href=https://dom.spec.whatwg.org/#interface-element>Element</a></code> <var>element</var>:</p> <ol><li><p>If <var>element</var> is a <code id=the-autofocus-attribute:the-dialog-element-2><a href=interactive-elements.html#the-dialog-element>dialog</a></code> element, then return <var>element</var>.<li><p>If <var>element</var>'s <code id=the-autofocus-attribute:attr-popover-2><a href=popover.html#attr-popover>popover</a></code> attribute is not in the <a href=popover.html#attr-popover-none-state id=the-autofocus-attribute:attr-popover-none-state>no popover state</a>, then return <var>element</var>.<li><p>Let <var>ancestor</var> be <var>element</var>.<li> <p>While <var>ancestor</var> has a <a id=the-autofocus-attribute:parent-element href=https://dom.spec.whatwg.org/#parent-element data-x-internal=parent-element>parent element</a>:</p> <ol><li><p>Set <var>ancestor</var> to <var>ancestor</var>'s <a id=the-autofocus-attribute:parent-element-2 href=https://dom.spec.whatwg.org/#parent-element data-x-internal=parent-element>parent element</a>.<li><p>If <var>ancestor</var> is a <code id=the-autofocus-attribute:the-dialog-element-3><a href=interactive-elements.html#the-dialog-element>dialog</a></code> element, then return <var>ancestor</var>.<li><p>If <var>ancestor</var>'s <code id=the-autofocus-attribute:attr-popover-3><a href=popover.html#attr-popover>popover</a></code> attribute is not in the <a href=popover.html#attr-popover-none-state id=the-autofocus-attribute:attr-popover-none-state-2>no popover state</a>, then return <var>ancestor</var>.</ol> <li><p>Return <var>ancestor</var>.</ol> <p>There must not be two elements with the same <a href=#nearest-ancestor-autofocus-scoping-root-element id=the-autofocus-attribute:nearest-ancestor-autofocus-scoping-root-element>nearest ancestor autofocus scoping root element</a> that both have the <code id=the-autofocus-attribute:attr-fe-autofocus-4><a href=#attr-fe-autofocus>autofocus</a></code> attribute specified.</p> <p>Each <code id=the-autofocus-attribute:document><a href=dom.html#document>Document</a></code> has an <dfn id=autofocus-candidates>autofocus candidates</dfn> <a id=the-autofocus-attribute:list href=https://infra.spec.whatwg.org/#list data-x-internal=list>list</a>, initially empty.</p> <p>Each <code id=the-autofocus-attribute:document-2><a href=dom.html#document>Document</a></code> has an <dfn id=autofocus-processed-flag>autofocus processed flag</dfn> boolean, initially false.</p> <p>When an element with the <code id=the-autofocus-attribute:attr-fe-autofocus-5><a href=#attr-fe-autofocus>autofocus</a></code> attribute specified is <a href=infrastructure.html#insert-an-element-into-a-document id=the-autofocus-attribute:insert-an-element-into-a-document>inserted into a document</a>, run the following steps:</p> <ol><li><p>If the user has indicated (for example, by starting to type in a form control) that they do not wish focus to be changed, then optionally return.<li><p>Let <var>target</var> be the element's <a id=the-autofocus-attribute:node-document href=https://dom.spec.whatwg.org/#concept-node-document data-x-internal=node-document>node document</a>.<li><p>If <var>target</var> is not <a id=the-autofocus-attribute:fully-active href=document-sequences.html#fully-active>fully active</a>, then return.<li><p>If <var>target</var>'s <a id=the-autofocus-attribute:active-sandboxing-flag-set href=browsers.html#active-sandboxing-flag-set>active sandboxing flag set</a> has the <a id=the-autofocus-attribute:sandboxed-automatic-features-browsing-context-flag href=browsers.html#sandboxed-automatic-features-browsing-context-flag>sandboxed automatic features browsing context flag</a>, then return.<li><p><a href=https://infra.spec.whatwg.org/#list-iterate id=the-autofocus-attribute:list-iterate data-x-internal=list-iterate>For each</a> <var>ancestorNavigable</var> of <var>target</var>'s <a id=the-autofocus-attribute:ancestor-navigables href=document-sequences.html#ancestor-navigables>ancestor navigables</a>: if <var>ancestorNavigable</var>'s <a href=document-sequences.html#nav-document id=the-autofocus-attribute:nav-document>active document</a>'s <a href=https://dom.spec.whatwg.org/#concept-document-origin id=the-autofocus-attribute:concept-document-origin data-x-internal=concept-document-origin>origin</a> is not <a id=the-autofocus-attribute:same-origin href=browsers.html#same-origin>same origin</a> with <var>target</var>'s <a href=https://dom.spec.whatwg.org/#concept-document-origin id=the-autofocus-attribute:concept-document-origin-2 data-x-internal=concept-document-origin>origin</a>, then return.<li><p>Let <var>topDocument</var> be <var>target</var>'s <a id=the-autofocus-attribute:node-navigable href=document-sequences.html#node-navigable>node navigable</a>'s <a href=document-sequences.html#nav-top id=the-autofocus-attribute:nav-top>top-level traversable</a>'s <a href=document-sequences.html#nav-document id=the-autofocus-attribute:nav-document-2>active document</a>.<li><p>If <var>topDocument</var>'s <a href=#autofocus-processed-flag id=the-autofocus-attribute:autofocus-processed-flag>autofocus processed flag</a> is false, then <a href=https://infra.spec.whatwg.org/#list-remove id=the-autofocus-attribute:list-remove data-x-internal=list-remove>remove</a> the element from <var>topDocument</var>'s <a href=#autofocus-candidates id=the-autofocus-attribute:autofocus-candidates>autofocus candidates</a>, and <a href=https://infra.spec.whatwg.org/#list-append id=the-autofocus-attribute:list-append data-x-internal=list-append>append</a> the element to <var>topDocument</var>'s <a href=#autofocus-candidates id=the-autofocus-attribute:autofocus-candidates-2>autofocus candidates</a>.</ol> <p class=note>We do not check if an element is a <a href=#focusable-area id=the-autofocus-attribute:focusable-area>focusable area</a> before storing it in the <a href=#autofocus-candidates id=the-autofocus-attribute:autofocus-candidates-3>autofocus candidates</a> list, because even if it is not a focusable area when it is inserted, it could become one by the time <a href=#flush-autofocus-candidates id=the-autofocus-attribute:flush-autofocus-candidates>flush autofocus candidates</a> sees it.</p> <p>To <dfn id=flush-autofocus-candidates>flush autofocus candidates</dfn> for a document <var>topDocument</var>, run these steps:</p> <ol><li><p>If <var>topDocument</var>'s <a href=#autofocus-processed-flag id=the-autofocus-attribute:autofocus-processed-flag-2>autofocus processed flag</a> is true, then return.<li><p>Let <var>candidates</var> be <var>topDocument</var>'s <a href=#autofocus-candidates id=the-autofocus-attribute:autofocus-candidates-4>autofocus candidates</a>.<li><p>If <var>candidates</var> <a href=https://infra.spec.whatwg.org/#list-is-empty id=the-autofocus-attribute:list-is-empty data-x-internal=list-is-empty>is empty</a>, then return.<li> <p>If <var>topDocument</var>'s <a href=#focused-area-of-the-document id=the-autofocus-attribute:focused-area-of-the-document>focused area</a> is not <var>topDocument</var> itself, or <var>topDocument</var> has non-null <a id=the-autofocus-attribute:target-element href=browsing-the-web.html#target-element>target element</a>, then:</p> <ol><li><p><a href=https://infra.spec.whatwg.org/#list-empty id=the-autofocus-attribute:list-empty data-x-internal=list-empty>Empty</a> <var>candidates</var>.<li><p>Set <var>topDocument</var>'s <a href=#autofocus-processed-flag id=the-autofocus-attribute:autofocus-processed-flag-3>autofocus processed flag</a> to true.<li><p>Return.</ol> <li> <p>While <var>candidates</var> is not <a href=https://infra.spec.whatwg.org/#list-is-empty id=the-autofocus-attribute:list-is-empty-2 data-x-internal=list-is-empty>empty</a>:</p> <ol><li><p>Let <var>element</var> be <var>candidates</var>[0].<li><p>Let <var>doc</var> be <var>element</var>'s <a id=the-autofocus-attribute:node-document-2 href=https://dom.spec.whatwg.org/#concept-node-document data-x-internal=node-document>node document</a>.<li><p>If <var>doc</var> is not <a id=the-autofocus-attribute:fully-active-2 href=document-sequences.html#fully-active>fully active</a>, then <a href=https://infra.spec.whatwg.org/#list-remove id=the-autofocus-attribute:list-remove-2 data-x-internal=list-remove>remove</a> <var>element</var> from <var>candidates</var>, and <a id=the-autofocus-attribute:continue href=https://infra.spec.whatwg.org/#iteration-continue data-x-internal=continue>continue</a>.<li><p>If <var>doc</var>'s <a id=the-autofocus-attribute:node-navigable-2 href=document-sequences.html#node-navigable>node navigable</a>'s <a href=document-sequences.html#nav-top id=the-autofocus-attribute:nav-top-2>top-level traversable</a> is not the same as <var>topDocument</var>'s <a id=the-autofocus-attribute:node-navigable-3 href=document-sequences.html#node-navigable>node navigable</a>, then <a href=https://infra.spec.whatwg.org/#list-remove id=the-autofocus-attribute:list-remove-3 data-x-internal=list-remove>remove</a> <var>element</var> from <var>candidates</var>, and <a id=the-autofocus-attribute:continue-2 href=https://infra.spec.whatwg.org/#iteration-continue data-x-internal=continue>continue</a>.<li> <p>If <var>doc</var>'s <a id=the-autofocus-attribute:script-blocking-style-sheet-set href=semantics.html#script-blocking-style-sheet-set>script-blocking style sheet set</a> is not <a href=https://infra.spec.whatwg.org/#list-empty id=the-autofocus-attribute:list-empty-2 data-x-internal=list-empty>empty</a>, then return.</p> <p class=note>In this case, <var>element</var> is the currently-best candidate, but <var>doc</var> is not ready for autofocusing. We'll try again next time <a href=#flush-autofocus-candidates id=the-autofocus-attribute:flush-autofocus-candidates-2>flush autofocus candidates</a> is called.</p> <li><p><a href=https://infra.spec.whatwg.org/#list-remove id=the-autofocus-attribute:list-remove-4 data-x-internal=list-remove>Remove</a> <var>element</var> from <var>candidates</var>.<li><p>Let <var>inclusiveAncestorDocuments</var> be a <a id=the-autofocus-attribute:list-2 href=https://infra.spec.whatwg.org/#list data-x-internal=list>list</a> consisting of the <a href=document-sequences.html#nav-document id=the-autofocus-attribute:nav-document-3>active document</a> of <var>doc</var>'s <a id=the-autofocus-attribute:inclusive-ancestor-navigables href=document-sequences.html#inclusive-ancestor-navigables>inclusive ancestor navigables</a>.<li><p>If any <code id=the-autofocus-attribute:document-3><a href=dom.html#document>Document</a></code> in <var>inclusiveAncestorDocuments</var> has non-null <a id=the-autofocus-attribute:target-element-2 href=browsing-the-web.html#target-element>target element</a>, then <a id=the-autofocus-attribute:continue-3 href=https://infra.spec.whatwg.org/#iteration-continue data-x-internal=continue>continue</a>.<li><p>Let <var>target</var> be <var>element</var>.<li> <p>If <var>target</var> is not a <a href=#focusable-area id=the-autofocus-attribute:focusable-area-2>focusable area</a>, then set <var>target</var> to the result of <a href=#get-the-focusable-area id=the-autofocus-attribute:get-the-focusable-area>getting the focusable area</a> for <var>target</var>.</p> <p class=note><a href=#autofocus-candidates id=the-autofocus-attribute:autofocus-candidates-5>Autofocus candidates</a> can <a href=https://infra.spec.whatwg.org/#list-contain id=the-autofocus-attribute:list-contains data-x-internal=list-contains>contain</a> elements which are not <a href=#focusable-area id=the-autofocus-attribute:focusable-area-3>focusable areas</a>. In addition to the special cases handled in the <a href=#get-the-focusable-area id=the-autofocus-attribute:get-the-focusable-area-2>get the focusable area</a> algorithm, this can happen because a non-<a href=#focusable-area id=the-autofocus-attribute:focusable-area-4>focusable area</a> element with an <code id=the-autofocus-attribute:attr-fe-autofocus-6><a href=#attr-fe-autofocus>autofocus</a></code> attribute was <a href=infrastructure.html#insert-an-element-into-a-document id=the-autofocus-attribute:insert-an-element-into-a-document-2>inserted into a document</a> and it never became focusable, or because the element was focusable but its status changed while it was stored in <a href=#autofocus-candidates id=the-autofocus-attribute:autofocus-candidates-6>autofocus candidates</a>.</p> <li> <p>If <var>target</var> is not null, then:</p> <ol><li><p><a href=https://infra.spec.whatwg.org/#list-empty id=the-autofocus-attribute:list-empty-3 data-x-internal=list-empty>Empty</a> <var>candidates</var>.<li><p>Set <var>topDocument</var>'s <a href=#autofocus-processed-flag id=the-autofocus-attribute:autofocus-processed-flag-4>autofocus processed flag</a> to true.<li><p>Run the <a href=#focusing-steps id=the-autofocus-attribute:focusing-steps>focusing steps</a> for <var>target</var>.</ol> </ol> </ol> <p class=note>This handles the automatic focusing during document load. The <code id=the-autofocus-attribute:dom-dialog-show><a href=interactive-elements.html#dom-dialog-show>show()</a></code> and <code id=the-autofocus-attribute:dom-dialog-showmodal><a href=interactive-elements.html#dom-dialog-showmodal>showModal()</a></code> methods of <code id=the-autofocus-attribute:the-dialog-element-4><a href=interactive-elements.html#the-dialog-element>dialog</a></code> elements also processes the <code id=the-autofocus-attribute:attr-fe-autofocus-7><a href=#attr-fe-autofocus>autofocus</a></code> attribute.</p> <p class=note>Focusing the element does not imply that the user agent has to focus the browser window if it has lost focus.</p> <div class="mdn-anno wrapped before"><button onclick=toggleStatus(this) class=mdn-anno-btn><b title="Support in one engine only." class=less-than-two-engines-flag>⚠</b><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autofocus title="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.">Global_attributes/autofocus</a><p class=less-than-two-engines-text>Support in one engine only.<div class=support><span class="firefox yes"><span>Firefox</span><span title="Partial implementation.">🔰 1+</span></span><span class="safari yes"><span>Safari</span><span title="Partial implementation.">🔰 4+</span></span><span class="chrome yes"><span>Chrome</span><span>79+</span></span><hr><span class="opera yes"><span>Opera</span><span>66+</span></span><span class="edge_blink yes"><span>Edge</span><span>79+</span></span><hr><span class="edge no"><span>Edge (Legacy)</span><span>No</span></span><span class="ie yes"><span>Internet Explorer</span><span title="Partial implementation.">🔰 10+</span></span><hr><span class="firefox_android unknown"><span>Firefox Android</span><span>?</span></span><span class="safari_ios unknown"><span>Safari iOS</span><span>?</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android yes"><span>WebView Android</span><span>79+</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android yes"><span>Opera Android</span><span>57+</span></span></div></div></div><p>The <dfn data-dfn-for=HTMLOrSVGElement id=dom-fe-autofocus data-dfn-type=attribute><code>autofocus</code></dfn> IDL attribute must <a id=the-autofocus-attribute:reflect href=common-dom-interfaces.html#reflect>reflect</a> the content attribute of the same name.</p> <div class=example> <p>In the following snippet, the text control would be focused when the document was loaded.</p> <pre><code class='html'><c- p>&lt;</c-><c- f>input</c-> <c- e>maxlength</c-><c- o>=</c-><c- s>&quot;256&quot;</c-> <c- e>name</c-><c- o>=</c-><c- s>&quot;q&quot;</c-> <c- e>value</c-><c- o>=</c-><c- s>&quot;&quot;</c-> <c- e>autofocus</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>input</c-> <c- e>type</c-><c- o>=</c-><c- s>&quot;submit&quot;</c-> <c- e>value</c-><c- o>=</c-><c- s>&quot;Search&quot;</c-><c- p>&gt;</c-></code></pre> </div> <div class=example> <p>The <code id=the-autofocus-attribute:attr-fe-autofocus-8><a href=#attr-fe-autofocus>autofocus</a></code> attribute applies to all elements, not just to form controls. This allows examples such as the following:</p> <pre><code class='html'><c- p>&lt;</c-><c- f>div</c-> <c- e>contenteditable</c-> <c- e>autofocus</c-><c- p>&gt;</c->Edit <c- p>&lt;</c-><c- f>strong</c-><c- p>&gt;</c->me!<c- p>&lt;/</c-><c- f>strong</c-><c- p>&gt;&lt;</c-><c- f>div</c-><c- p>&gt;</c-></code></pre> </div> <h3 id=assigning-keyboard-shortcuts><span class=secno>6.7</span> Assigning keyboard shortcuts<a href=#assigning-keyboard-shortcuts class=self-link></a></h3> <h4 id=introduction-9><span class=secno>6.7.1</span> Introduction<a href=#introduction-9 class=self-link></a></h4> <p><i>This section is non-normative.</i></p> <p>Each element that can be activated or focused can be assigned a single key combination to activate it, using the <code id=introduction-9:the-accesskey-attribute><a href=#the-accesskey-attribute>accesskey</a></code> attribute.</p> <p>The exact shortcut is determined by the user agent, based on information about the user's keyboard, what keyboard shortcuts already exist on the platform, and what other shortcuts have been specified on the page, using the information provided in the <code id=introduction-9:the-accesskey-attribute-2><a href=#the-accesskey-attribute>accesskey</a></code> attribute as a guide.</p> <p>In order to ensure that a relevant keyboard shortcut is available on a wide variety of input devices, the author can provide a number of alternatives in the <code id=introduction-9:the-accesskey-attribute-3><a href=#the-accesskey-attribute>accesskey</a></code> attribute.</p> <p>Each alternative consists of a single character, such as a letter or digit.</p> <p>User agents can provide users with a list of the keyboard shortcuts, but authors are encouraged to do so also. The <code id=introduction-9:dom-accesskeylabel><a href=#dom-accesskeylabel>accessKeyLabel</a></code> IDL attribute returns a string representing the actual key combination assigned by the user agent.</p> <div class=example> <p>In this example, an author has provided a button that can be invoked using a shortcut key. To support full keyboards, the author has provided "C" as a possible key. To support devices equipped only with numeric keypads, the author has provided "1" as another possible key.</p> <pre><code class='html'><c- p>&lt;</c-><c- f>input</c-> <c- e>type</c-><c- o>=</c-><c- s>button</c-> <c- e>value</c-><c- o>=</c-><c- s>Collect</c-> <c- e>onclick</c-><c- o>=</c-><c- s>&quot;collect()&quot;</c-> <strong><c- e>accesskey</c-><c- o>=</c-><c- s>&quot;C 1&quot;</c-></strong> <c- e>id</c-><c- o>=</c-><c- s>c</c-><c- p>&gt;</c-></code></pre> </div> <div class=example> <p>To tell the user what the shortcut key is, the author has this script here opted to explicitly add the key combination to the button's label:</p> <pre><code class='js'><c- a>function</c-> addShortcutKeyLabel<c- p>(</c->button<c- p>)</c-> <c- p>{</c-> <strong> <c- k>if</c-> <c- p>(</c->button<c- p>.</c->accessKeyLabel <c- o>!=</c-> <c- t>&apos;&apos;</c-><c- p>)</c-> button<c- p>.</c->value <c- o>+=</c-> <c- t>&apos; (&apos;</c-> <c- o>+</c-> button<c- p>.</c->accessKeyLabel <c- o>+</c-> <c- t>&apos;)&apos;</c-><c- p>;</c-></strong> <c- p>}</c-> addShortcutKeyLabel<c- p>(</c->document<c- p>.</c->getElementById<c- p>(</c-><c- t>&apos;c&apos;</c-><c- p>));</c-></code></pre> <p>Browsers on different platforms will show different labels, even for the same key combination, based on the convention prevalent on that platform. For example, if the key combination is the Control key, the Shift key, and the letter C, a Windows browser might display "<samp>Ctrl+Shift+C</samp>", whereas a Mac browser might display "<samp>^⇧C</samp>", while an Emacs browser might just display "<samp>C-C</samp>". Similarly, if the key combination is the Alt key and the Escape key, Windows might use "<samp>Alt+Esc</samp>", Mac might use "<samp>⌥⎋</samp>", and an Emacs browser might use "<samp>M-ESC</samp>" or "<samp>ESC ESC</samp>".</p> <p>In general, therefore, it is unwise to attempt to parse the value returned from the <code id=introduction-9:dom-accesskeylabel-2><a href=#dom-accesskeylabel>accessKeyLabel</a></code> IDL attribute.</p> </div> <h4 id=the-accesskey-attribute><span class=secno>6.7.2</span> The <dfn data-dfn-for=html-global data-dfn-type=element-attr><code>accesskey</code></dfn> attribute<a href=#the-accesskey-attribute class=self-link></a></h4><div class="mdn-anno wrapped"><button onclick=toggleStatus(this) class=mdn-anno-btn><b title="Support in all current engines." class=all-engines-flag>✔</b><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/accesskey title="The accesskey global attribute provides a hint for generating a keyboard shortcut for the current element. The attribute value must consist of a single printable character (which includes accented and other characters that can be generated by the keyboard).">Global_attributes/accesskey</a><p class=all-engines-text>Support in all current engines.<div class=support><span class="firefox yes"><span>Firefox</span><span>1+</span></span><span class="safari yes"><span>Safari</span><span>4+</span></span><span class="chrome yes"><span>Chrome</span><span>1+</span></span><hr><span class="opera unknown"><span>Opera</span><span>?</span></span><span class="edge_blink yes"><span>Edge</span><span>79+</span></span><hr><span class="edge yes"><span>Edge (Legacy)</span><span>12+</span></span><span class="ie yes"><span>Internet Explorer</span><span>Yes</span></span><hr><span class="firefox_android unknown"><span>Firefox Android</span><span>?</span></span><span class="safari_ios unknown"><span>Safari iOS</span><span>?</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android unknown"><span>WebView Android</span><span>?</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android unknown"><span>Opera Android</span><span>?</span></span></div></div></div> <p>All <a id=the-accesskey-attribute:html-elements href=infrastructure.html#html-elements>HTML elements</a> may have the <code id=the-accesskey-attribute:the-accesskey-attribute><a href=#the-accesskey-attribute>accesskey</a></code> content attribute set. The <code id=the-accesskey-attribute:the-accesskey-attribute-2><a href=#the-accesskey-attribute>accesskey</a></code> attribute's value is used by the user agent as a guide for creating a keyboard shortcut that activates or focuses the element.</p> <p>If specified, the value must be an <a id=the-accesskey-attribute:ordered-set-of-unique-space-separated-tokens href=common-microsyntaxes.html#ordered-set-of-unique-space-separated-tokens>ordered set of unique space-separated tokens</a> none of which are <a id=the-accesskey-attribute:identical-to href=https://infra.spec.whatwg.org/#string-is data-x-internal=identical-to>identical to</a> another token and each of which must be exactly one code point in length.</p> <div class=example> <p>In the following example, a variety of links are given with access keys so that keyboard users familiar with the site can more quickly navigate to the relevant pages:</p> <pre><code class='html'><c- p>&lt;</c-><c- f>nav</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>p</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>a</c-> <c- e>title</c-><c- o>=</c-><c- s>&quot;Consortium Activities&quot;</c-> <c- e>accesskey</c-><c- o>=</c-><c- s>&quot;A&quot;</c-> <c- e>href</c-><c- o>=</c-><c- s>&quot;/Consortium/activities&quot;</c-><c- p>&gt;</c->Activities<c- p>&lt;/</c-><c- f>a</c-><c- p>&gt;</c-> | <c- p>&lt;</c-><c- f>a</c-> <c- e>title</c-><c- o>=</c-><c- s>&quot;Technical Reports and Recommendations&quot;</c-> <c- e>accesskey</c-><c- o>=</c-><c- s>&quot;T&quot;</c-> <c- e>href</c-><c- o>=</c-><c- s>&quot;/TR/&quot;</c-><c- p>&gt;</c->Technical Reports<c- p>&lt;/</c-><c- f>a</c-><c- p>&gt;</c-> | <c- p>&lt;</c-><c- f>a</c-> <c- e>title</c-><c- o>=</c-><c- s>&quot;Alphabetical Site Index&quot;</c-> <c- e>accesskey</c-><c- o>=</c-><c- s>&quot;S&quot;</c-> <c- e>href</c-><c- o>=</c-><c- s>&quot;/Consortium/siteindex&quot;</c-><c- p>&gt;</c->Site Index<c- p>&lt;/</c-><c- f>a</c-><c- p>&gt;</c-> | <c- p>&lt;</c-><c- f>a</c-> <c- e>title</c-><c- o>=</c-><c- s>&quot;About This Site&quot;</c-> <c- e>accesskey</c-><c- o>=</c-><c- s>&quot;B&quot;</c-> <c- e>href</c-><c- o>=</c-><c- s>&quot;/Consortium/&quot;</c-><c- p>&gt;</c->About Consortium<c- p>&lt;/</c-><c- f>a</c-><c- p>&gt;</c-> | <c- p>&lt;</c-><c- f>a</c-> <c- e>title</c-><c- o>=</c-><c- s>&quot;Contact Consortium&quot;</c-> <c- e>accesskey</c-><c- o>=</c-><c- s>&quot;C&quot;</c-> <c- e>href</c-><c- o>=</c-><c- s>&quot;/Consortium/contact&quot;</c-><c- p>&gt;</c->Contact<c- p>&lt;/</c-><c- f>a</c-><c- p>&gt;</c-> <c- p>&lt;/</c-><c- f>p</c-><c- p>&gt;</c-> <c- p>&lt;/</c-><c- f>nav</c-><c- p>&gt;</c-></code></pre> </div> <div class=example> <p>In the following example, the search field is given two possible access keys, "s" and "0" (in that order). A user agent on a device with a full keyboard might pick <kbd><kbd>Ctrl</kbd> + <kbd>Alt</kbd> + <kbd>S</kbd></kbd> as the shortcut key, while a user agent on a small device with just a numeric keypad might pick just the plain unadorned key <kbd><kbd>0</kbd></kbd>:</p> <pre><code class='html'><c- p>&lt;</c-><c- f>form</c-> <c- e>action</c-><c- o>=</c-><c- s>&quot;/search&quot;</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>label</c-><c- p>&gt;</c->Search: <c- p>&lt;</c-><c- f>input</c-> <c- e>type</c-><c- o>=</c-><c- s>&quot;search&quot;</c-> <c- e>name</c-><c- o>=</c-><c- s>&quot;q&quot;</c-> <c- e>accesskey</c-><c- o>=</c-><c- s>&quot;s 0&quot;</c-><c- p>&gt;&lt;/</c-><c- f>label</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>input</c-> <c- e>type</c-><c- o>=</c-><c- s>&quot;submit&quot;</c-><c- p>&gt;</c-> <c- p>&lt;/</c-><c- f>form</c-><c- p>&gt;</c-></code></pre> </div> <div class=example> <p>In the following example, a button has possible access keys described. A script then tries to update the button's label to advertise the key combination the user agent selected.</p> <pre><code class='html'><c- p>&lt;</c-><c- f>input</c-> <c- e>type</c-><c- o>=</c-><c- s>submit</c-> <c- e>accesskey</c-><c- o>=</c-><c- s>&quot;N @ 1&quot;</c-> <c- e>value</c-><c- o>=</c-><c- s>&quot;Compose&quot;</c-><c- p>&gt;</c-> ... <c- p>&lt;</c-><c- f>script</c-><c- p>&gt;</c-> <c- a>function</c-> labelButton<c- p>(</c->button<c- p>)</c-> <c- p>{</c-> <c- k>if</c-> <c- p>(</c->button<c- p>.</c->accessKeyLabel<c- p>)</c-> button<c- p>.</c->value <c- o>+=</c-> <c- t>&apos; (&apos;</c-> <c- o>+</c-> button<c- p>.</c->accessKeyLabel <c- o>+</c-> <c- t>&apos;)&apos;</c-><c- p>;</c-> <c- p>}</c-> <c- a>var</c-> inputs <c- o>=</c-> document<c- p>.</c->getElementsByTagName<c- p>(</c-><c- t>&apos;input&apos;</c-><c- p>);</c-> <c- k>for</c-> <c- p>(</c-><c- a>var</c-> i <c- o>=</c-> <c- mf>0</c-><c- p>;</c-> i <c- o>&lt;</c-> inputs<c- p>.</c->length<c- p>;</c-> i <c- o>+=</c-> <c- mf>1</c-><c- p>)</c-> <c- p>{</c-> <c- k>if</c-> <c- p>(</c->inputs<c- p>[</c->i<c- p>].</c->type <c- o>==</c-> <c- u>&quot;submit&quot;</c-><c- p>)</c-> labelButton<c- p>(</c->inputs<c- p>[</c->i<c- p>]);</c-> <c- p>}</c-> <c- p>&lt;/</c-><c- f>script</c-><c- p>&gt;</c-></code></pre> <p>On one user agent, the button's label might become "<samp>Compose (⌘N)</samp>". On another, it might become "<samp>Compose (Alt+⇧+1)</samp>". If the user agent doesn't assign a key, it will be just "<samp>Compose</samp>". The exact string depends on what the <a href=#assigned-access-key id=the-accesskey-attribute:assigned-access-key>assigned access key</a> is, and on how the user agent represents that key combination.</p> </div> <h4 id=keyboard-shortcuts-processing-model><span class=secno>6.7.3</span> <span id=processing-model-6></span>Processing model<a href=#keyboard-shortcuts-processing-model class=self-link></a></h4> <p>An element's <dfn id=assigned-access-key>assigned access key</dfn> is a key combination derived from the element's <code id=keyboard-shortcuts-processing-model:the-accesskey-attribute><a href=#the-accesskey-attribute>accesskey</a></code> content attribute. Initially, an element must not have an <a href=#assigned-access-key id=keyboard-shortcuts-processing-model:assigned-access-key>assigned access key</a>.</p> <p>Whenever an element's <code id=keyboard-shortcuts-processing-model:the-accesskey-attribute-2><a href=#the-accesskey-attribute>accesskey</a></code> attribute is set, changed, or removed, the user agent must update the element's <a href=#assigned-access-key id=keyboard-shortcuts-processing-model:assigned-access-key-2>assigned access key</a> by running the following steps:</p> <ol><li><p>If the element has no <code id=keyboard-shortcuts-processing-model:the-accesskey-attribute-3><a href=#the-accesskey-attribute>accesskey</a></code> attribute, then skip to the <i>fallback</i> step below.<li><p>Otherwise, <a href=https://infra.spec.whatwg.org/#split-on-ascii-whitespace id=keyboard-shortcuts-processing-model:split-a-string-on-spaces data-x-internal=split-a-string-on-spaces>split the attribute's value on ASCII whitespace</a>, and let <var>keys</var> be the resulting tokens.<li> <p>For each value in <var>keys</var> in turn, in the order the tokens appeared in the attribute's value, run the following substeps:</p> <ol><li><p>If the value is not a string exactly one code point in length, then skip the remainder of these steps for this value.<li><p>If the value does not correspond to a key on the system's keyboard, then skip the remainder of these steps for this value.<li><p> <a id=keyboard-shortcuts-processing-model:tracking-vector title="There is a tracking vector here." href=https://infra.spec.whatwg.org/#tracking-vector class=tracking-vector data-x-internal=tracking-vector><img width=46 alt="(This is a tracking vector.)" crossorigin="" src=https://resources.whatwg.org/tracking-vector.svg height=64></a> If the user agent can find a mix of zero or more modifier keys that, combined with the key that corresponds to the value given in the attribute, can be used as the access key, then the user agent may assign that combination of keys as the element's <a href=#assigned-access-key id=keyboard-shortcuts-processing-model:assigned-access-key-3>assigned access key</a> and return.</ol> <li><p><i>Fallback</i>: Optionally, the user agent may assign a key combination of its choosing as the element's <a href=#assigned-access-key id=keyboard-shortcuts-processing-model:assigned-access-key-4>assigned access key</a> and then return.<li><p>If this step is reached, the element has no <a href=#assigned-access-key id=keyboard-shortcuts-processing-model:assigned-access-key-5>assigned access key</a>.</ol> <p>Once a user agent has selected and assigned an access key for an element, the user agent should not change the element's <a href=#assigned-access-key id=keyboard-shortcuts-processing-model:assigned-access-key-6>assigned access key</a> unless the <code id=keyboard-shortcuts-processing-model:the-accesskey-attribute-4><a href=#the-accesskey-attribute>accesskey</a></code> content attribute is changed or the element is moved to another <code id=keyboard-shortcuts-processing-model:document><a href=dom.html#document>Document</a></code>.</p> <p>When the user presses the key combination corresponding to the <a href=#assigned-access-key id=keyboard-shortcuts-processing-model:assigned-access-key-7>assigned access key</a> for an element, if the element <a href=interactive-elements.html#concept-command id=keyboard-shortcuts-processing-model:concept-command>defines a command</a>, the command's <a href=interactive-elements.html#command-facet-hiddenstate id=keyboard-shortcuts-processing-model:command-facet-hiddenstate>Hidden State</a> facet is false (visible), the command's <a href=interactive-elements.html#command-facet-disabledstate id=keyboard-shortcuts-processing-model:command-facet-disabledstate>Disabled State</a> facet is also false (enabled), the element is <a id=keyboard-shortcuts-processing-model:in-a-document href=https://dom.spec.whatwg.org/#in-a-document data-x-internal=in-a-document>in a document</a> that has a non-null <a href=document-sequences.html#concept-document-bc id=keyboard-shortcuts-processing-model:concept-document-bc>browsing context</a>, and neither the element nor any of its ancestors has a <code id=keyboard-shortcuts-processing-model:attr-hidden><a href=#attr-hidden>hidden</a></code> attribute specified, then the user agent must trigger the <a href=interactive-elements.html#command-facet-action id=keyboard-shortcuts-processing-model:command-facet-action>Action</a> of the command.</p> <p class=note>User agents <a href=interactive-elements.html#expose-commands-in-ui>might expose</a> elements that have an <code id=keyboard-shortcuts-processing-model:the-accesskey-attribute-5><a href=#the-accesskey-attribute>accesskey</a></code> attribute in other ways as well, e.g. in a menu displayed in response to a specific key combination.</p> <hr> <div class="mdn-anno wrapped before"><button onclick=toggleStatus(this) class=mdn-anno-btn><b title="Support in all current engines." class=all-engines-flag>✔</b><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/accessKey title="The HTMLElement.accessKey property sets the keystroke which a user can press to jump to a given element.">HTMLElement/accessKey</a><p class=all-engines-text>Support in all current engines.<div class=support><span class="firefox yes"><span>Firefox</span><span>5+</span></span><span class="safari yes"><span>Safari</span><span>6+</span></span><span class="chrome yes"><span>Chrome</span><span>17+</span></span><hr><span class="opera yes"><span>Opera</span><span>12.1+</span></span><span class="edge_blink yes"><span>Edge</span><span>79+</span></span><hr><span class="edge yes"><span>Edge (Legacy)</span><span>12+</span></span><span class="ie yes"><span>Internet Explorer</span><span>5.5+</span></span><hr><span class="firefox_android unknown"><span>Firefox Android</span><span>?</span></span><span class="safari_ios unknown"><span>Safari iOS</span><span>?</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android unknown"><span>WebView Android</span><span>?</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android yes"><span>Opera Android</span><span>12.1+</span></span></div></div></div><p>The <dfn data-dfn-for=HTMLElement id=dom-accesskey data-dfn-type=attribute><code>accessKey</code></dfn> IDL attribute must <a id=keyboard-shortcuts-processing-model:reflect href=common-dom-interfaces.html#reflect>reflect</a> the <code id=keyboard-shortcuts-processing-model:the-accesskey-attribute-6><a href=#the-accesskey-attribute>accesskey</a></code> content attribute.</p> <div class="mdn-anno wrapped before"><button onclick=toggleStatus(this) class=mdn-anno-btn><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/accessKeyLabel title="The HTMLElement.accessKeyLabel read-only property returns a string containing the element's browser-assigned access key (if any); otherwise it returns an empty string.">HTMLElement/accessKeyLabel</a><div class=support><span class="firefox yes"><span>Firefox</span><span>8+</span></span><span class="safari yes"><span>Safari</span><span>14+</span></span><span class="chrome no"><span>Chrome</span><span>No</span></span><hr><span class="opera unknown"><span>Opera</span><span>?</span></span><span class="edge_blink no"><span>Edge</span><span>No</span></span><hr><span class="edge unknown"><span>Edge (Legacy)</span><span>?</span></span><span class="ie no"><span>Internet Explorer</span><span>No</span></span><hr><span class="firefox_android unknown"><span>Firefox Android</span><span>?</span></span><span class="safari_ios unknown"><span>Safari iOS</span><span>?</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android unknown"><span>WebView Android</span><span>?</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android unknown"><span>Opera Android</span><span>?</span></span></div></div></div><p>The <dfn data-dfn-for=HTMLElement id=dom-accesskeylabel data-dfn-type=attribute><code>accessKeyLabel</code></dfn> IDL attribute must return a string that represents the element's <a href=#assigned-access-key id=keyboard-shortcuts-processing-model:assigned-access-key-8>assigned access key</a>, if any. If the element does not have one, then the IDL attribute must return the empty string.</p> <h3 id=editing-2><span class=secno>6.8</span> Editing<a href=#editing-2 class=self-link></a></h3> <h4 id=contenteditable><span class=secno>6.8.1</span> Making document regions editable: The <code id=contenteditable:attr-contenteditable><a href=#attr-contenteditable>contenteditable</a></code> content attribute<a href=#contenteditable class=self-link></a></h4><div class="mdn-anno wrapped"><button onclick=toggleStatus(this) class=mdn-anno-btn><b title="Support in all current engines." class=all-engines-flag>✔</b><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/contentEditable title="The contentEditable property of the HTMLElement interface specifies whether or not the element is editable.">HTMLElement/contentEditable</a><p class=all-engines-text>Support in all current engines.<div class=support><span class="firefox yes"><span>Firefox</span><span>3+</span></span><span class="safari yes"><span>Safari</span><span>3+</span></span><span class="chrome yes"><span>Chrome</span><span>1+</span></span><hr><span class="opera yes"><span>Opera</span><span>9+</span></span><span class="edge_blink yes"><span>Edge</span><span>79+</span></span><hr><span class="edge yes"><span>Edge (Legacy)</span><span>12+</span></span><span class="ie yes"><span>Internet Explorer</span><span>5.5+</span></span><hr><span class="firefox_android unknown"><span>Firefox Android</span><span>?</span></span><span class="safari_ios yes"><span>Safari iOS</span><span>1+</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android unknown"><span>WebView Android</span><span>?</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android yes"><span>Opera Android</span><span>10.1+</span></span></div></div></div> <pre><code class='idl'><c- b>interface</c-> <c- b>mixin</c-> <dfn id='elementcontenteditable' data-dfn-type='interface'><c- g>ElementContentEditable</c-></dfn> { [<a id='contenteditable:cereactions' href='custom-elements.html#cereactions'><c- g>CEReactions</c-></a>] <c- b>attribute</c-> <c- b>DOMString</c-> <a href='#dom-contenteditable' id='contenteditable:dom-contenteditable'><c- g>contentEditable</c-></a>; [<a id='contenteditable:cereactions-2' href='custom-elements.html#cereactions'><c- g>CEReactions</c-></a>] <c- b>attribute</c-> <c- b>DOMString</c-> <a href='#dom-enterkeyhint' id='contenteditable:dom-enterkeyhint'><c- g>enterKeyHint</c-></a>; <c- b>readonly</c-> <c- b>attribute</c-> <c- b>boolean</c-> <a href='#dom-iscontenteditable' id='contenteditable:dom-iscontenteditable'><c- g>isContentEditable</c-></a>; [<a id='contenteditable:cereactions-3' href='custom-elements.html#cereactions'><c- g>CEReactions</c-></a>] <c- b>attribute</c-> <c- b>DOMString</c-> <a href='#dom-inputmode' id='contenteditable:dom-inputmode'><c- g>inputMode</c-></a>; };</code></pre> <div class="mdn-anno wrapped before"><button onclick=toggleStatus(this) class=mdn-anno-btn><b title="Support in all current engines." class=all-engines-flag>✔</b><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/contenteditable title="The contenteditable global attribute is an enumerated attribute indicating if the element should be editable by the user. If so, the browser modifies its widget to allow editing.">Global_attributes/contenteditable</a><p class=all-engines-text>Support in all current engines.<div class=support><span class="firefox yes"><span>Firefox</span><span>3+</span></span><span class="safari yes"><span>Safari</span><span>4+</span></span><span class="chrome yes"><span>Chrome</span><span>1+</span></span><hr><span class="opera yes"><span>Opera</span><span>9+</span></span><span class="edge_blink yes"><span>Edge</span><span>79+</span></span><hr><span class="edge yes"><span>Edge (Legacy)</span><span>12+</span></span><span class="ie yes"><span>Internet Explorer</span><span>5.5+</span></span><hr><span class="firefox_android unknown"><span>Firefox Android</span><span>?</span></span><span class="safari_ios unknown"><span>Safari iOS</span><span>?</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android unknown"><span>WebView Android</span><span>?</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android unknown"><span>Opera Android</span><span>?</span></span></div></div></div><p>The <dfn data-dfn-for=html-global id=attr-contenteditable data-dfn-type=element-attr><code>contenteditable</code></dfn> content attribute is an <a id=contenteditable:enumerated-attribute href=common-microsyntaxes.html#enumerated-attribute>enumerated attribute</a> with the following keywords and states:</p> <table><thead><tr><th>Keyword <th>State <th>Brief description <tbody><tr><td><dfn data-dfn-for=html-global/contenteditable id=attr-contenteditable-true data-dfn-type=attr-value><code>true</code></dfn> <td rowspan=2><dfn id=attr-contenteditable-true-state>true</dfn> <td rowspan=2>The element is editable. <tr><td>(the empty string) <tr><td><dfn data-dfn-for=html-global/contenteditable id=attr-contenteditable-false data-dfn-type=attr-value><code>false</code></dfn> <td><dfn id=attr-contenteditable-false-state>false</dfn> <td>The element is not editable. <tr><td><dfn data-dfn-for=html-global/contenteditable id=attr-contenteditable-plaintextonly data-dfn-type=attr-value><code>plaintext-only</code></dfn> <td><dfn id=attr-contenteditable-plaintextonly-state>plaintext-only</dfn> <td>Only the element's raw text content is editable; rich formatting is disabled. </table> <p>The attribute's <i id=contenteditable:missing-value-default><a href=common-microsyntaxes.html#missing-value-default>missing value default</a></i> and <i id=contenteditable:invalid-value-default><a href=common-microsyntaxes.html#invalid-value-default>invalid value default</a></i> are both the <dfn id=attr-contenteditable-inherit-state>inherit</dfn> state. The inherit state indicates that the element is editable (or not) based on the parent element's state.</p> <div class=example> <p>For example, consider a page that has a <code id=contenteditable:the-form-element><a href=forms.html#the-form-element>form</a></code> and a <code id=contenteditable:the-textarea-element><a href=form-elements.html#the-textarea-element>textarea</a></code> to publish a new article, where the user is expected to write the article using HTML:</p> <pre><code class='html'><c- p>&lt;</c-><c- f>form</c-> <c- e>method</c-><c- o>=</c-><c- s>POST</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>fieldset</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>legend</c-><c- p>&gt;</c->New article<c- p>&lt;/</c-><c- f>legend</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>textarea</c-> <c- e>name</c-><c- o>=</c-><c- s>article</c-><c- p>&gt;</c-><c- ni>&amp;lt;</c->p&gt;Hello world.<c- ni>&amp;lt;</c->/p&gt;<c- p>&lt;/</c-><c- f>textarea</c-><c- p>&gt;</c-> <c- p>&lt;/</c-><c- f>fieldset</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>p</c-><c- p>&gt;&lt;</c-><c- f>button</c-><c- p>&gt;</c->Publish<c- p>&lt;/</c-><c- f>button</c-><c- p>&gt;&lt;/</c-><c- f>p</c-><c- p>&gt;</c-> <c- p>&lt;/</c-><c- f>form</c-><c- p>&gt;</c-></code></pre> <p>When scripting is enabled, the <code id=contenteditable:the-textarea-element-2><a href=form-elements.html#the-textarea-element>textarea</a></code> element could be replaced with a rich text control instead, using the <code id=contenteditable:attr-contenteditable-2><a href=#attr-contenteditable>contenteditable</a></code> attribute:</p> <pre><code class='html'><c- p>&lt;</c-><c- f>form</c-> <c- e>method</c-><c- o>=</c-><c- s>POST</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>fieldset</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>legend</c-><c- p>&gt;</c->New article<c- p>&lt;/</c-><c- f>legend</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>textarea</c-> <c- e>id</c-><c- o>=</c-><c- s>textarea</c-> <c- e>name</c-><c- o>=</c-><c- s>article</c-><c- p>&gt;</c-><c- ni>&amp;lt;</c->p&gt;Hello world.<c- ni>&amp;lt;</c->/p&gt;<c- p>&lt;/</c-><c- f>textarea</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>div</c-> <c- e>id</c-><c- o>=</c-><c- s>div</c-> <c- e>style</c-><c- o>=</c-><c- s>&quot;white-space: pre-wrap&quot;</c-> <c- e>hidden</c-><c- p>&gt;&lt;</c-><c- f>p</c-><c- p>&gt;</c->Hello world.<c- p>&lt;/</c-><c- f>p</c-><c- p>&gt;&lt;/</c-><c- f>div</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>script</c-><c- p>&gt;</c-> <c- a>let</c-> textarea <c- o>=</c-> document<c- p>.</c->getElementById<c- p>(</c-><c- u>&quot;textarea&quot;</c-><c- p>);</c-> <c- a>let</c-> div <c- o>=</c-> document<c- p>.</c->getElementById<c- p>(</c-><c- u>&quot;div&quot;</c-><c- p>);</c-> textarea<c- p>.</c->hidden <c- o>=</c-> <c- kc>true</c-><c- p>;</c-> div<c- p>.</c->hidden <c- o>=</c-> <c- kc>false</c-><c- p>;</c-> div<c- p>.</c->contentEditable <c- o>=</c-> <c- u>&quot;true&quot;</c-><c- p>;</c-> div<c- p>.</c->oninput <c- o>=</c-> <c- p>(</c->e<c- p>)</c-> <c- p>=&gt;</c-> <c- p>{</c-> textarea<c- p>.</c->value <c- o>=</c-> div<c- p>.</c->innerHTML<c- p>;</c-> <c- p>};</c-> <c- p>&lt;/</c-><c- f>script</c-><c- p>&gt;</c-> <c- p>&lt;/</c-><c- f>fieldset</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>p</c-><c- p>&gt;&lt;</c-><c- f>button</c-><c- p>&gt;</c->Publish<c- p>&lt;/</c-><c- f>button</c-><c- p>&gt;&lt;/</c-><c- f>p</c-><c- p>&gt;</c-> <c- p>&lt;/</c-><c- f>form</c-><c- p>&gt;</c-></code></pre> <p>Features to enable, e.g., inserting links, can be implemented using the <code id=contenteditable:execCommand><a data-x-internal=execCommand href=https://w3c.github.io/editing/docs/execCommand/#execcommand%28%29>document.execCommand()</a></code> API, or using <code id=contenteditable:selection><a data-x-internal=selection href=https://w3c.github.io/selection-api/#selection-interface>Selection</a></code> APIs and other DOM APIs. <a href=references.html#refsEXECCOMMAND>[EXECCOMMAND]</a> <a href=references.html#refsSELECTION>[SELECTION]</a> <a href=references.html#refsDOM>[DOM]</a></p> </div> <div class=example> <p>The <code id=contenteditable:attr-contenteditable-3><a href=#attr-contenteditable>contenteditable</a></code> attribute can also be used to great effect:</p> <pre><code class='html'><c- cp>&lt;!doctype html&gt;</c-> <c- p>&lt;</c-><c- f>html</c-> <c- e>lang</c-><c- o>=</c-><c- s>en</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>title</c-><c- p>&gt;</c->Live CSS editing!<c- p>&lt;/</c-><c- f>title</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>style</c-> <c- e>style</c-><c- o>=</c-><c- s>white-space:pre</c-> <c- e>contenteditable</c-><c- p>&gt;</c-> <c- f>html</c-> <c- p>{</c-> <c- k>margin</c-><c- p>:</c-><c- mf>.2</c-><c- b>em</c-><c- p>;</c-> <c- k>font-size</c-><c- p>:</c-><c- mi>2</c-><c- b>em</c-><c- p>;</c-> <c- k>color</c-><c- p>:</c-><c- kc>lime</c-><c- p>;</c-> <c- k>background</c-><c- p>:</c-><c- kc>purple</c-> <c- p>}</c-> <c- f>head</c-><c- o>,</c-> <c- f>title</c-><c- o>,</c-> <c- f>style</c-> <c- p>{</c-> <c- k>display</c-><c- p>:</c-><c- kc>block</c-> <c- p>}</c-> <c- f>body</c-> <c- p>{</c-> <c- k>display</c-><c- p>:</c-><c- kc>none</c-> <c- p>}</c-> <c- p>&lt;/</c-><c- f>style</c-><c- p>&gt;</c-></code></pre> </div> <dl class=domintro><dt><code><var>element</var>.<a href=#dom-contenteditable id=dom-contenteditable-dev>contentEditable</a> [ = <var>value</var> ]</code><dd> <p>Returns "<code>true</code>", "<code>plaintext-only</code>", "<code>false</code>", or "<code id=contenteditable:attr-contenteditable-inherit-state><a href=#attr-contenteditable-inherit-state>inherit</a></code>", based on the state of the <code id=contenteditable:attr-contenteditable-4><a href=#attr-contenteditable>contenteditable</a></code> attribute.</p> <p>Can be set, to change that state.</p> <p>Throws a <a id=contenteditable:syntaxerror href=https://webidl.spec.whatwg.org/#syntaxerror data-x-internal=syntaxerror>"<code>SyntaxError</code>"</a> <code id=contenteditable:domexception><a data-x-internal=domexception href=https://webidl.spec.whatwg.org/#dfn-DOMException>DOMException</a></code> if the new value isn't one of those strings.</p> <dt><code><var>element</var>.<a href=#dom-iscontenteditable id=dom-iscontenteditable-dev>isContentEditable</a></code><div class="mdn-anno wrapped before"><button onclick=toggleStatus(this) class=mdn-anno-btn><b title="Support in all current engines." class=all-engines-flag>✔</b><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/isContentEditable title="The HTMLElement.isContentEditable read-only property returns a boolean value that is true if the contents of the element are editable; otherwise it returns false.">HTMLElement/isContentEditable</a><p class=all-engines-text>Support in all current engines.<div class=support><span class="firefox yes"><span>Firefox</span><span>4+</span></span><span class="safari yes"><span>Safari</span><span>3+</span></span><span class="chrome yes"><span>Chrome</span><span>1+</span></span><hr><span class="opera yes"><span>Opera</span><span>12.1+</span></span><span class="edge_blink yes"><span>Edge</span><span>79+</span></span><hr><span class="edge yes"><span>Edge (Legacy)</span><span>12+</span></span><span class="ie yes"><span>Internet Explorer</span><span>5.5+</span></span><hr><span class="firefox_android unknown"><span>Firefox Android</span><span>?</span></span><span class="safari_ios yes"><span>Safari iOS</span><span>1+</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android unknown"><span>WebView Android</span><span>?</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android yes"><span>Opera Android</span><span>12.1+</span></span></div></div></div><dd><p>Returns true if the element is editable; otherwise, returns false.</dl> <p>The <dfn data-dfn-for=ElementContentEditable id=dom-contenteditable data-dfn-type=attribute><code>contentEditable</code></dfn> IDL attribute, on getting, must return the string "<code>true</code>" if the content attribute is set to the <a href=#attr-contenteditable-true-state id=contenteditable:attr-contenteditable-true-state>true</a> state, "<code>plaintext-only</code>" if the content attribute is set to the <a href=#attr-contenteditable-plaintextonly-state id=contenteditable:attr-contenteditable-plaintextonly-state>plaintext-only</a> state, "<code>false</code>" if the content attribute is set to the <a href=#attr-contenteditable-false-state id=contenteditable:attr-contenteditable-false-state>false</a> state, and "<code id=contenteditable:attr-contenteditable-inherit-state-2><a href=#attr-contenteditable-inherit-state>inherit</a></code>" otherwise. On setting, if the new value is an <a id=contenteditable:ascii-case-insensitive href=https://infra.spec.whatwg.org/#ascii-case-insensitive data-x-internal=ascii-case-insensitive>ASCII case-insensitive</a> match for the string "<code>inherit</code>" then the content attribute must be removed, if the new value is an <a id=contenteditable:ascii-case-insensitive-2 href=https://infra.spec.whatwg.org/#ascii-case-insensitive data-x-internal=ascii-case-insensitive>ASCII case-insensitive</a> match for the string "<code>true</code>" then the content attribute must be set to the string "<code>true</code>", if the new value is an <a id=contenteditable:ascii-case-insensitive-3 href=https://infra.spec.whatwg.org/#ascii-case-insensitive data-x-internal=ascii-case-insensitive>ASCII case-insensitive</a> match for the string "<code>plaintext-only</code>" then the content attribute must be set to the string "<code>plaintext-only</code>", if the new value is an <a id=contenteditable:ascii-case-insensitive-4 href=https://infra.spec.whatwg.org/#ascii-case-insensitive data-x-internal=ascii-case-insensitive>ASCII case-insensitive</a> match for the string "<code>false</code>" then the content attribute must be set to the string "<code>false</code>", and otherwise the attribute setter must throw a <a id=contenteditable:syntaxerror-2 href=https://webidl.spec.whatwg.org/#syntaxerror data-x-internal=syntaxerror>"<code>SyntaxError</code>"</a> <code id=contenteditable:domexception-2><a data-x-internal=domexception href=https://webidl.spec.whatwg.org/#dfn-DOMException>DOMException</a></code>.</p> <p>The <dfn data-dfn-for=ElementContentEditable id=dom-iscontenteditable data-dfn-type=attribute><code>isContentEditable</code></dfn> IDL attribute, on getting, must return true if the element is either an <a href=#editing-host id=contenteditable:editing-host>editing host</a> or <a id=contenteditable:editable href=https://w3c.github.io/editing/docs/execCommand/#editable data-x-internal=editable>editable</a>, and false otherwise.</p> <h4 id=making-entire-documents-editable:-the-designmode-idl-attribute><span class=secno>6.8.2</span> Making entire documents editable: the <code id=making-entire-documents-editable:-the-designmode-idl-attribute:designMode><a href=#designMode>designMode</a></code> getter and setter<a href=#making-entire-documents-editable:-the-designmode-idl-attribute class=self-link></a></h4> <dl class=domintro><dt><code><var>document</var>.<a href=#designMode id=dom-document-designmode-dev>designMode</a> [ = <var>value</var> ]</code><div class="mdn-anno wrapped before"><button onclick=toggleStatus(this) class=mdn-anno-btn><b title="Support in all current engines." class=all-engines-flag>✔</b><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/API/Document/designMode title="document.designMode controls whether the entire document is editable. Valid values are &quot;on&quot; and &quot;off&quot;. According to the specification, this property is meant to default to &quot;off&quot;. Firefox follows this standard. The earlier versions of Chrome and IE default to &quot;inherit&quot;. Starting in Chrome 43, the default is &quot;off&quot; and &quot;inherit&quot; is no longer supported. In IE6-10, the value is capitalized.">Document/designMode</a><p class=all-engines-text>Support in all current engines.<div class=support><span class="firefox yes"><span>Firefox</span><span>1+</span></span><span class="safari yes"><span>Safari</span><span>1.2+</span></span><span class="chrome yes"><span>Chrome</span><span>1+</span></span><hr><span class="opera yes"><span>Opera</span><span>9+</span></span><span class="edge_blink yes"><span>Edge</span><span>79+</span></span><hr><span class="edge yes"><span>Edge (Legacy)</span><span>12+</span></span><span class="ie yes"><span>Internet Explorer</span><span>4+</span></span><hr><span class="firefox_android unknown"><span>Firefox Android</span><span>?</span></span><span class="safari_ios unknown"><span>Safari iOS</span><span>?</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android unknown"><span>WebView Android</span><span>?</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android yes"><span>Opera Android</span><span>10.1+</span></span></div></div></div><dd> <p>Returns "<code>on</code>" if the document is editable, and "<code>off</code>" if it isn't.</p> <p>Can be set, to change the document's current state. This focuses the document and resets the selection in that document.</p> </dl> <p><code id=making-entire-documents-editable:-the-designmode-idl-attribute:document><a href=dom.html#document>Document</a></code> objects have an associated <dfn id=design-mode-enabled>design mode enabled</dfn>, which is a boolean. It is initially false.</p> <p>The <dfn data-dfn-for=Document id=designMode data-dfn-type=attribute><code>designMode</code></dfn> getter steps are to return "<code>on</code>" if <a id=making-entire-documents-editable:-the-designmode-idl-attribute:this href=https://webidl.spec.whatwg.org/#this data-x-internal=this>this</a>'s <a href=#design-mode-enabled id=making-entire-documents-editable:-the-designmode-idl-attribute:design-mode-enabled>design mode enabled</a> is true; otherwise "<code>off</code>".</p> <p>The <code id=making-entire-documents-editable:-the-designmode-idl-attribute:designMode-2><a href=#designMode>designMode</a></code> setter steps are:</p> <ol><li><p>Let <var>value</var> be the given value, <a id=making-entire-documents-editable:-the-designmode-idl-attribute:converted-to-ascii-lowercase href=https://infra.spec.whatwg.org/#ascii-lowercase data-x-internal=converted-to-ascii-lowercase>converted to ASCII lowercase</a>.<li> <p>If <var>value</var> is "<code>on</code>" and <a id=making-entire-documents-editable:-the-designmode-idl-attribute:this-2 href=https://webidl.spec.whatwg.org/#this data-x-internal=this>this</a>'s <a href=#design-mode-enabled id=making-entire-documents-editable:-the-designmode-idl-attribute:design-mode-enabled-2>design mode enabled</a> is false, then:</p> <ol><li><p>Set <a id=making-entire-documents-editable:-the-designmode-idl-attribute:this-3 href=https://webidl.spec.whatwg.org/#this data-x-internal=this>this</a>'s <a href=#design-mode-enabled id=making-entire-documents-editable:-the-designmode-idl-attribute:design-mode-enabled-3>design mode enabled</a> to true.<li><p>Reset <a id=making-entire-documents-editable:-the-designmode-idl-attribute:this-4 href=https://webidl.spec.whatwg.org/#this data-x-internal=this>this</a>'s <a id=making-entire-documents-editable:-the-designmode-idl-attribute:active-range href=https://w3c.github.io/editing/docs/execCommand/#active-range data-x-internal=active-range>active range</a>'s start and end boundary points to be at the start of <a id=making-entire-documents-editable:-the-designmode-idl-attribute:this-5 href=https://webidl.spec.whatwg.org/#this data-x-internal=this>this</a>.<li><p>Run the <a href=#focusing-steps id=making-entire-documents-editable:-the-designmode-idl-attribute:focusing-steps>focusing steps</a> for <a id=making-entire-documents-editable:-the-designmode-idl-attribute:this-6 href=https://webidl.spec.whatwg.org/#this data-x-internal=this>this</a>'s <a id=making-entire-documents-editable:-the-designmode-idl-attribute:document-element href=https://dom.spec.whatwg.org/#document-element data-x-internal=document-element>document element</a>, if non-null.</ol> <li><p>If <var>value</var> is "<code>off</code>", then set <a id=making-entire-documents-editable:-the-designmode-idl-attribute:this-7 href=https://webidl.spec.whatwg.org/#this data-x-internal=this>this</a>'s <a href=#design-mode-enabled id=making-entire-documents-editable:-the-designmode-idl-attribute:design-mode-enabled-4>design mode enabled</a> to false.</ol> <h4 id=best-practices-for-in-page-editors><span class=secno>6.8.3</span> Best practices for in-page editors<a href=#best-practices-for-in-page-editors class=self-link></a></h4> <p>Authors are encouraged to set the <a id="best-practices-for-in-page-editors:'white-space'" href=https://drafts.csswg.org/css-text/#white-space-property data-x-internal="'white-space'">'white-space'</a> property on <a href=#editing-host id=best-practices-for-in-page-editors:editing-host>editing hosts</a> and on markup that was originally created through these editing mechanisms to the value 'pre-wrap'. Default HTML whitespace handling is not well suited to WYSIWYG editing, and line wrapping will not work correctly in some corner cases if <a id="best-practices-for-in-page-editors:'white-space'-2" href=https://drafts.csswg.org/css-text/#white-space-property data-x-internal="'white-space'">'white-space'</a> is left at its default value.</p> <div class=example> <p>As an example of problems that occur if the default 'normal' value is used instead, consider the case of the user typing "<kbd>yellow␣␣ball</kbd>", with two spaces (here represented by "␣") between the words. With the editing rules in place for the default value of <a id="best-practices-for-in-page-editors:'white-space'-3" href=https://drafts.csswg.org/css-text/#white-space-property data-x-internal="'white-space'">'white-space'</a> ('normal'), the resulting markup will either consist of "<samp>yellow&amp;nbsp; ball</samp>" or "<samp>yellow &amp;nbsp;ball</samp>"; i.e., there will be a non-breaking space between the two words in addition to the regular space. This is necessary because the 'normal' value for <a id="best-practices-for-in-page-editors:'white-space'-4" href=https://drafts.csswg.org/css-text/#white-space-property data-x-internal="'white-space'">'white-space'</a> requires adjacent regular spaces to be collapsed together.</p> <p>In the former case, "<samp>yellow⍽</samp>" might wrap to the next line ("⍽" being used here to represent a non-breaking space) even though "<samp>yellow</samp>" alone might fit at the end of the line; in the latter case, "<samp>⍽ball</samp>", if wrapped to the start of the line, would have visible indentation from the non-breaking space.</p> <p>When <a id="best-practices-for-in-page-editors:'white-space'-5" href=https://drafts.csswg.org/css-text/#white-space-property data-x-internal="'white-space'">'white-space'</a> is set to 'pre-wrap', however, the editing rules will instead simply put two regular spaces between the words, and should the two words be split at the end of a line, the spaces would be neatly removed from the rendering.</p> </div> <h4 id=editing-apis><span class=secno>6.8.4</span> Editing APIs<a href=#editing-apis class=self-link></a></h4> <p>An <dfn id=editing-host data-export="">editing host</dfn> is either an <a href=infrastructure.html#html-elements id=editing-apis:html-elements>HTML element</a> with its <code id=editing-apis:attr-contenteditable><a href=#attr-contenteditable>contenteditable</a></code> attribute in the <i>true</i> state or <i>plaintext-only</i> state, or a <a href=https://dom.spec.whatwg.org/#concept-tree-child id=editing-apis:concept-tree-child data-x-internal=concept-tree-child>child</a> <a href=infrastructure.html#html-elements id=editing-apis:html-elements-2>HTML element</a> of a <code id=editing-apis:document><a href=dom.html#document>Document</a></code> whose <a href=#design-mode-enabled id=editing-apis:design-mode-enabled>design mode enabled</a> is true.</p> <p>The definition of the terms <dfn id=active-range><a href=https://w3c.github.io/editing/docs/execCommand/#active-range>active range</a></dfn>, <dfn id=editing-host-of><a href=https://w3c.github.io/editing/docs/execCommand/#editing-host-of>editing host of</a></dfn>, and <dfn id=editable><a href=https://w3c.github.io/editing/docs/execCommand/#editable>editable</a></dfn>, the user interface requirements of elements that are <a href=#editing-host id=editing-apis:editing-host>editing hosts</a> or <a id=editing-apis:editable href=https://w3c.github.io/editing/docs/execCommand/#editable data-x-internal=editable>editable</a>, the <dfn id=execCommand><a href=https://w3c.github.io/editing/docs/execCommand/#execcommand%28%29><code>execCommand()</code></a></dfn>, <dfn id=dom-document-querycommandenabled><a href=https://w3c.github.io/editing/docs/execCommand/#querycommandenabled%28%29><code>queryCommandEnabled()</code></a></dfn>, <dfn id=dom-document-querycommandindeterm><a href=https://w3c.github.io/editing/docs/execCommand/#querycommandindeterm%28%29><code>queryCommandIndeterm()</code></a></dfn>, <dfn id=dom-document-querycommandstate><a href=https://w3c.github.io/editing/docs/execCommand/#querycommandstate%28%29><code>queryCommandState()</code></a></dfn>, <dfn id=dom-document-querycommandsupported><a href=https://w3c.github.io/editing/docs/execCommand/#querycommandsupported%28%29><code>queryCommandSupported()</code></a></dfn>, and <dfn id=dom-document-querycommandvalue><a href=https://w3c.github.io/editing/docs/execCommand/#querycommandvalue%28%29><code>queryCommandValue()</code></a></dfn> methods, text selections, and the <dfn id=delete-the-selection><a href=https://w3c.github.io/editing/docs/execCommand/#delete-the-selection>delete the selection</a></dfn> algorithm are defined in <cite>execCommand</cite>. <a href=references.html#refsEXECCOMMAND>[EXECCOMMAND]</a></p> <h4 id=spelling-and-grammar-checking><span class=secno>6.8.5</span> Spelling and grammar checking<a href=#spelling-and-grammar-checking class=self-link></a></h4> <p>User agents can support the checking of spelling and grammar of editable text, either in form controls (such as the value of <code id=spelling-and-grammar-checking:the-textarea-element><a href=form-elements.html#the-textarea-element>textarea</a></code> elements), or in elements in an <a href=#editing-host id=spelling-and-grammar-checking:editing-host>editing host</a> (e.g. using <code id=spelling-and-grammar-checking:attr-contenteditable><a href=#attr-contenteditable>contenteditable</a></code>).</p> <p>For each element, user agents must establish a <dfn id=concept-spellcheck-default>default behavior</dfn>, either through defaults or through preferences expressed by the user. There are three possible default behaviors for each element:</p> <dl><dt><dfn id=concept-spellcheck-default-true>true-by-default</dfn> <dd>The element will be checked for spelling and grammar if its contents are editable and spellchecking is not explicitly disabled through the <code id=spelling-and-grammar-checking:attr-spellcheck><a href=#attr-spellcheck>spellcheck</a></code> attribute. <dt><dfn id=concept-spellcheck-default-false>false-by-default</dfn> <dd>The element will never be checked for spelling and grammar unless spellchecking is explicitly enabled through the <code id=spelling-and-grammar-checking:attr-spellcheck-2><a href=#attr-spellcheck>spellcheck</a></code> attribute. <dt><dfn id=concept-spellcheck-default-inherit>inherit-by-default</dfn> <dd>The element's default behavior is the same as its parent element's. Elements that have no parent element cannot have this as their default behavior. </dl> <hr> <div class="mdn-anno wrapped before"><button onclick=toggleStatus(this) class=mdn-anno-btn><b title="Support in all current engines." class=all-engines-flag>✔</b><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/spellcheck title="The spellcheck global attribute is an enumerated attribute that defines whether the element may be checked for spelling errors.">Global_attributes/spellcheck</a><p class=all-engines-text>Support in all current engines.<div class=support><span class="firefox yes"><span>Firefox</span><span>Yes</span></span><span class="safari yes"><span>Safari</span><span>Yes</span></span><span class="chrome yes"><span>Chrome</span><span>9+</span></span><hr><span class="opera yes"><span>Opera</span><span>Yes</span></span><span class="edge_blink yes"><span>Edge</span><span>79+</span></span><hr><span class="edge yes"><span>Edge (Legacy)</span><span>12+</span></span><span class="ie yes"><span>Internet Explorer</span><span>11</span></span><hr><span class="firefox_android yes"><span>Firefox Android</span><span>57+</span></span><span class="safari_ios yes"><span>Safari iOS</span><span>9.3+</span></span><span class="chrome_android yes"><span>Chrome Android</span><span>47+</span></span><span class="webview_android unknown"><span>WebView Android</span><span>?</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android yes"><span>Opera Android</span><span>37+</span></span></div></div></div><p>The <dfn data-dfn-for=html-global id=attr-spellcheck data-dfn-type=element-attr><code>spellcheck</code></dfn> attribute is an <a id=spelling-and-grammar-checking:enumerated-attribute href=common-microsyntaxes.html#enumerated-attribute>enumerated attribute</a> with the following keywords and states:</p> <table><thead><tr><th>Keyword <th>State <th>Brief description <tbody><tr><td><dfn data-dfn-for=html-global/spellcheck id=attr-spellcheck-true data-dfn-type=attr-value><code>true</code></dfn> <td rowspan=2><dfn id=attr-spellcheck-true-state>true</dfn> <td rowspan=2>Spelling and grammar will be checked. <tr><td>(the empty string) <tr><td><dfn data-dfn-for=html-global/spellcheck id=attr-spellcheck-false data-dfn-type=attr-value><code>false</code></dfn> <td><dfn id=attr-spellcheck-false-state>false</dfn> <td>Spelling and grammar will not be checked. </table> <p>The attribute's <i id=spelling-and-grammar-checking:missing-value-default><a href=common-microsyntaxes.html#missing-value-default>missing value default</a></i> and <i id=spelling-and-grammar-checking:invalid-value-default><a href=common-microsyntaxes.html#invalid-value-default>invalid value default</a></i> are both the <dfn id=attr-spellcheck-default-state>default</dfn> state. The default state indicates that the element is to act according to a default behavior, possibly based on the parent element's own <code id=spelling-and-grammar-checking:attr-spellcheck-3><a href=#attr-spellcheck>spellcheck</a></code> state, as defined below.</p> <hr> <dl class=domintro><dt><code><var>element</var>.<a href=#dom-spellcheck id=dom-spellcheck-dev>spellcheck</a> [ = <var>value</var> ]</code><dd> <p>Returns true if the element is to have its spelling and grammar checked; otherwise, returns false.</p> <p>Can be set, to override the default and set the <code id=spelling-and-grammar-checking:attr-spellcheck-4><a href=#attr-spellcheck>spellcheck</a></code> content attribute.</p> </dl> <p>The <dfn data-dfn-for=HTMLElement id=dom-spellcheck data-dfn-type=attribute><code>spellcheck</code></dfn> IDL attribute, on getting, must return true if the element's <code id=spelling-and-grammar-checking:attr-spellcheck-5><a href=#attr-spellcheck>spellcheck</a></code> content attribute is in the <a href=#attr-spellcheck-true-state id=spelling-and-grammar-checking:attr-spellcheck-true-state>true</a> state, or if the element's <code id=spelling-and-grammar-checking:attr-spellcheck-6><a href=#attr-spellcheck>spellcheck</a></code> content attribute is in the <a href=#attr-spellcheck-default-state id=spelling-and-grammar-checking:attr-spellcheck-default-state>default</a> state and the element's <a href=#concept-spellcheck-default id=spelling-and-grammar-checking:concept-spellcheck-default>default behavior</a> is <a href=#concept-spellcheck-default-true id=spelling-and-grammar-checking:concept-spellcheck-default-true>true-by-default</a>, or if the element's <code id=spelling-and-grammar-checking:attr-spellcheck-7><a href=#attr-spellcheck>spellcheck</a></code> content attribute is in the <a href=#attr-spellcheck-default-state id=spelling-and-grammar-checking:attr-spellcheck-default-state-2>default</a> state and the element's <a href=#concept-spellcheck-default id=spelling-and-grammar-checking:concept-spellcheck-default-2>default behavior</a> is <a href=#concept-spellcheck-default-inherit id=spelling-and-grammar-checking:concept-spellcheck-default-inherit>inherit-by-default</a> and the element's parent element's <code id=spelling-and-grammar-checking:dom-spellcheck><a href=#dom-spellcheck>spellcheck</a></code> IDL attribute would return true; otherwise, if none of those conditions applies, then the attribute must instead return false.</p> <p class=note>The <code id=spelling-and-grammar-checking:dom-spellcheck-2><a href=#dom-spellcheck>spellcheck</a></code> IDL attribute is not affected by user preferences that override the <code id=spelling-and-grammar-checking:attr-spellcheck-8><a href=#attr-spellcheck>spellcheck</a></code> content attribute, and therefore might not reflect the actual spellchecking state.</p> <p>On setting, if the new value is true, then the element's <code id=spelling-and-grammar-checking:attr-spellcheck-9><a href=#attr-spellcheck>spellcheck</a></code> content attribute must be set to "<code>true</code>", otherwise it must be set to "<code>false</code>". <hr> <p>User agents should only consider the following pieces of text as checkable for the purposes of this feature:</p> <ul><li>The <a href=form-control-infrastructure.html#concept-fe-value id=spelling-and-grammar-checking:concept-fe-value>value</a> of <code id=spelling-and-grammar-checking:the-input-element><a href=input.html#the-input-element>input</a></code> elements whose <code id=spelling-and-grammar-checking:attr-input-type><a href=input.html#attr-input-type>type</a></code> attributes are in the <a href="input.html#text-(type=text)-state-and-search-state-(type=search)" id="spelling-and-grammar-checking:text-(type=text)-state-and-search-state-(type=search)">Text</a>, <a href="input.html#text-(type=text)-state-and-search-state-(type=search)" id="spelling-and-grammar-checking:text-(type=text)-state-and-search-state-(type=search)-2">Search</a>, <a href="input.html#url-state-(type=url)" id="spelling-and-grammar-checking:url-state-(type=url)">URL</a>, or <a href="input.html#email-state-(type=email)" id="spelling-and-grammar-checking:email-state-(type=email)">Email</a> states and that are <i id=spelling-and-grammar-checking:concept-fe-mutable><a href=form-control-infrastructure.html#concept-fe-mutable>mutable</a></i> (i.e. that do not have the <code id=spelling-and-grammar-checking:attr-input-readonly><a href=input.html#attr-input-readonly>readonly</a></code> attribute specified and that are not <a href=form-control-infrastructure.html#concept-fe-disabled id=spelling-and-grammar-checking:concept-fe-disabled>disabled</a>).<li>The <a href=form-control-infrastructure.html#concept-fe-value id=spelling-and-grammar-checking:concept-fe-value-2>value</a> of <code id=spelling-and-grammar-checking:the-textarea-element-2><a href=form-elements.html#the-textarea-element>textarea</a></code> elements that do not have a <code id=spelling-and-grammar-checking:attr-textarea-readonly><a href=form-elements.html#attr-textarea-readonly>readonly</a></code> attribute and that are not <a href=form-control-infrastructure.html#concept-fe-disabled id=spelling-and-grammar-checking:concept-fe-disabled-2>disabled</a>.<li>Text in <code id=spelling-and-grammar-checking:text><a data-x-internal=text href=https://dom.spec.whatwg.org/#interface-text>Text</a></code> nodes that are children of <a href=#editing-host id=spelling-and-grammar-checking:editing-host-2>editing hosts</a> or <a id=spelling-and-grammar-checking:editable href=https://w3c.github.io/editing/docs/execCommand/#editable data-x-internal=editable>editable</a> elements.<li>Text in attributes of <a id=spelling-and-grammar-checking:editable-2 href=https://w3c.github.io/editing/docs/execCommand/#editable data-x-internal=editable>editable</a> elements.</ul> <p>For text that is part of a <code id=spelling-and-grammar-checking:text-2><a data-x-internal=text href=https://dom.spec.whatwg.org/#interface-text>Text</a></code> node, the element with which the text is associated is the element that is the immediate parent of the first character of the word, sentence, or other piece of text. For text in attributes, it is the attribute's element. For the values of <code id=spelling-and-grammar-checking:the-input-element-2><a href=input.html#the-input-element>input</a></code> and <code id=spelling-and-grammar-checking:the-textarea-element-3><a href=form-elements.html#the-textarea-element>textarea</a></code> elements, it is the element itself.</p> <p>To determine if a word, sentence, or other piece of text in an applicable element (as defined above) is to have spelling- and grammar-checking enabled, the UA must use the following algorithm:</p> <ol><li>If the user has disabled the checking for this text, then the checking is disabled.<li>Otherwise, if the user has forced the checking for this text to always be enabled, then the checking is enabled.<li>Otherwise, if the element with which the text is associated has a <code id=spelling-and-grammar-checking:attr-spellcheck-10><a href=#attr-spellcheck>spellcheck</a></code> content attribute, then: if that attribute is in the <a href=#attr-spellcheck-true-state id=spelling-and-grammar-checking:attr-spellcheck-true-state-2>true</a> state, then checking is enabled; otherwise, if that attribute is in the <a href=#attr-spellcheck-false-state id=spelling-and-grammar-checking:attr-spellcheck-false-state>false</a> state, then checking is disabled.<li>Otherwise, if there is an ancestor element with a <code id=spelling-and-grammar-checking:attr-spellcheck-11><a href=#attr-spellcheck>spellcheck</a></code> content attribute that is not in the <a href=#attr-spellcheck-default-state id=spelling-and-grammar-checking:attr-spellcheck-default-state-3>default</a> state, then: if the nearest such ancestor's <code id=spelling-and-grammar-checking:attr-spellcheck-12><a href=#attr-spellcheck>spellcheck</a></code> content attribute is in the <a href=#attr-spellcheck-true-state id=spelling-and-grammar-checking:attr-spellcheck-true-state-3>true</a> state, then checking is enabled; otherwise, checking is disabled.<li>Otherwise, if the element's <a href=#concept-spellcheck-default id=spelling-and-grammar-checking:concept-spellcheck-default-3>default behavior</a> is <a href=#concept-spellcheck-default-true id=spelling-and-grammar-checking:concept-spellcheck-default-true-2>true-by-default</a>, then checking is enabled.<li>Otherwise, if the element's <a href=#concept-spellcheck-default id=spelling-and-grammar-checking:concept-spellcheck-default-4>default behavior</a> is <a href=#concept-spellcheck-default-false id=spelling-and-grammar-checking:concept-spellcheck-default-false>false-by-default</a>, then checking is disabled.<li>Otherwise, if the element's parent element has <em>its</em> checking enabled, then checking is enabled.<li>Otherwise, checking is disabled.</ol> <p>If the checking is enabled for a word/sentence/text, the user agent should indicate spelling and grammar errors in that text. User agents should take into account the other semantics given in the document when suggesting spelling and grammar corrections. User agents may use the language of the element to determine what spelling and grammar rules to use, or may use the user's preferred language settings. UAs should use <code id=spelling-and-grammar-checking:the-input-element-3><a href=input.html#the-input-element>input</a></code> element attributes such as <code id=spelling-and-grammar-checking:attr-input-pattern><a href=input.html#attr-input-pattern>pattern</a></code> to ensure that the resulting value is valid, where possible.</p> <p>If checking is disabled, the user agent should not indicate spelling or grammar errors for that text.</p> <div class=example> <p>The element with ID "a" in the following example would be the one used to determine if the word "Hello" is checked for spelling errors. In this example, it would not be.</p> <pre><code class='html'><c- p>&lt;</c-><c- f>div</c-> <c- e>contenteditable</c-><c- o>=</c-><c- s>&quot;true&quot;</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>span</c-> <c- e>spellcheck</c-><c- o>=</c-><c- s>&quot;false&quot;</c-> <c- e>id</c-><c- o>=</c-><c- s>&quot;a&quot;</c-><c- p>&gt;</c->Hell<c- p>&lt;/</c-><c- f>span</c-><c- p>&gt;&lt;</c-><c- f>em</c-><c- p>&gt;</c->o!<c- p>&lt;/</c-><c- f>em</c-><c- p>&gt;</c-> <c- p>&lt;/</c-><c- f>div</c-><c- p>&gt;</c-></code></pre> <p>The element with ID "b" in the following example would have checking enabled (the leading space character in the attribute's value on the <code id=spelling-and-grammar-checking:the-input-element-4><a href=input.html#the-input-element>input</a></code> element causes the attribute to be ignored, so the ancestor's value is used instead, regardless of the default).</p> <pre class=bad><code class='html'><c- p>&lt;</c-><c- f>p</c-> <c- e>spellcheck</c-><c- o>=</c-><c- s>&quot;true&quot;</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>label</c-><c- p>&gt;</c->Name: <c- p>&lt;</c-><c- f>input</c-> <c- e>spellcheck</c-><c- o>=</c-><c- s>&quot; false&quot;</c-> <c- e>id</c-><c- o>=</c-><c- s>&quot;b&quot;</c-><c- p>&gt;&lt;/</c-><c- f>label</c-><c- p>&gt;</c-> <c- p>&lt;/</c-><c- f>p</c-><c- p>&gt;</c-></code></pre> </div> <p class=note>This specification does not define the user interface for spelling and grammar checkers. A user agent could offer on-demand checking, could perform continuous checking while the checking is enabled, or could use other interfaces.</p> <h4 id=writing-suggestions><span class=secno>6.8.6</span> Writing suggestions<a href=#writing-suggestions class=self-link></a></h4> <p>User agents offer writing suggestions as users type into editable regions, either in form controls (e.g., the <code id=writing-suggestions:the-textarea-element><a href=form-elements.html#the-textarea-element>textarea</a></code> element) or in elements in an <a href=#editing-host id=writing-suggestions:editing-host> editing host</a>.</p> <p>The <dfn data-dfn-for=html-global id=attr-writingsuggestions data-dfn-type=element-attr><code>writingsuggestions</code></dfn> content attribute is an <a id=writing-suggestions:enumerated-attribute href=common-microsyntaxes.html#enumerated-attribute>enumerated attribute</a> with the following keywords and states:</p> <table><thead><tr><th>Keyword <th>State <th>Brief description <tbody><tr><td><dfn data-dfn-for=html-global/writingsuggestions id=attr-writingsuggestions-true data-dfn-type=attr-value><code>true</code></dfn> <td rowspan=2><dfn id=attr-writingsuggestions-true-state>true</dfn> <td rowspan=2>Writing suggestions should be offered on this element. <tr><td>(the empty string) <tr><td><dfn data-dfn-for=html-global/writingsuggestions id=attr-writingsuggestions-false data-dfn-type=attr-value><code>false</code></dfn> <td><dfn id=attr-writingsuggestions-false-state>false</dfn> <td>Writing suggestions should not be offered on this element. </table> <p>The attribute's <i id=writing-suggestions:missing-value-default><a href=common-microsyntaxes.html#missing-value-default>missing value default</a></i> is the <dfn id=attr-writingsuggestions-default-state>default</dfn> state. The default state indicates that the element is to act according to a default behavior, possibly based on the parent element's own <code id=writing-suggestions:attr-writingsuggestions><a href=#attr-writingsuggestions>writingsuggestions</a></code> state, as defined below.</p> <p>The attribute's <i id=writing-suggestions:invalid-value-default><a href=common-microsyntaxes.html#invalid-value-default>invalid value default</a></i> is the <a href=#attr-writingsuggestions-true-state id=writing-suggestions:attr-writingsuggestions-true-state>true</a> state.</p> <dl class=domintro><dt><code><var>element</var>.<a href=#dom-writingsuggestions id=dom-writingsuggestions-dev>writingSuggestions</a> [ = <var>value</var> ]</code><dd> <p>Returns "<code>true</code>" if the user agent is to offer writing suggestions under the scope of the element; otherwise, returns "<code>false</code>".</p> <p>Can be set, to override the default and set the <code id=writing-suggestions:attr-writingsuggestions-2><a href=#attr-writingsuggestions> writingsuggestions</a></code> content attribute.</p> </dl> <p>The <dfn id=computed-writing-suggestions-value>computed writing suggestions value</dfn> of a given <var>element</var> is determined by running the following steps:</p> <ol><li><p>If <var>element</var>'s <code id=writing-suggestions:attr-writingsuggestions-3><a href=#attr-writingsuggestions>writingsuggestions</a></code> content attribute is in the <a href=#attr-writingsuggestions-false-state id=writing-suggestions:attr-writingsuggestions-false-state>false</a> state, return "<code>false</code>".<li><p>If <var>element</var>'s <code id=writing-suggestions:attr-writingsuggestions-4><a href=#attr-writingsuggestions>writingsuggestions</a></code> content attribute is in the <a href=#attr-writingsuggestions-default-state id=writing-suggestions:attr-writingsuggestions-default-state>default</a> state, <var>element</var> has a parent element, and the <a href=#computed-writing-suggestions-value id=writing-suggestions:computed-writing-suggestions-value>computed writing suggestions value</a> of <var>element</var>'s parent element is "<code>false</code>", then return "<code>false</code>".<li><p>Return "<code>true</code>".</ol> <p>The <dfn data-dfn-for=HTMLElement id=dom-writingsuggestions data-dfn-type=attribute><code>writingSuggestions</code></dfn> getter steps are:</p> <ol><li><p>Return <a id=writing-suggestions:this href=https://webidl.spec.whatwg.org/#this data-x-internal=this>this</a>'s <a href=#computed-writing-suggestions-value id=writing-suggestions:computed-writing-suggestions-value-2>computed writing suggestions value</a>.</ol> <p class=note>The <code id=writing-suggestions:dom-writingsuggestions><a href=#dom-writingsuggestions>writingSuggestions</a></code> IDL attribute is not affected by user preferences that override the <code id=writing-suggestions:attr-writingsuggestions-5><a href=#attr-writingsuggestions>writingsuggestions</a></code> content attribute, and therefore might not reflect the actual writing suggestions state.</p> <p>The <code id=writing-suggestions:dom-writingsuggestions-2><a href=#dom-writingsuggestions>writingSuggestions</a></code> setter steps are:</p> <ol><li><p>Set <a id=writing-suggestions:this-2 href=https://webidl.spec.whatwg.org/#this data-x-internal=this>this</a>'s <code id=writing-suggestions:attr-writingsuggestions-6><a href=#attr-writingsuggestions>writingsuggestions</a></code> content attribute to the given value.</ol> <hr> <p>User agents should only offer suggestions within an element's scope if the result of running the following algorithm given <var>element</var> returns true:</p> <ol><li><p>If the user has disabled writing suggestions, then return false.<li> <p>If none of the following conditions are true:</p> <ul><li><p><var>element</var> is an <code id=writing-suggestions:the-input-element><a href=input.html#the-input-element>input</a></code> element whose <code id=writing-suggestions:attr-input-type><a href=input.html#attr-input-type>type</a></code> attribute is in either the <a href="input.html#text-(type=text)-state-and-search-state-(type=search)" id="writing-suggestions:text-(type=text)-state-and-search-state-(type=search)">Text</a>, <a href="input.html#text-(type=text)-state-and-search-state-(type=search)" id="writing-suggestions:text-(type=text)-state-and-search-state-(type=search)-2">Search</a>, <a href="input.html#telephone-state-(type=tel)" id="writing-suggestions:telephone-state-(type=tel)">Telephone</a>, <a href="input.html#url-state-(type=url)" id="writing-suggestions:url-state-(type=url)">URL</a>, or <a href="input.html#email-state-(type=email)" id="writing-suggestions:email-state-(type=email)">Email</a> state and is <i id=writing-suggestions:concept-fe-mutable><a href=form-control-infrastructure.html#concept-fe-mutable>mutable</a></i>;<li><p><var>element</var> is a <code id=writing-suggestions:the-textarea-element-2><a href=form-elements.html#the-textarea-element>textarea</a></code> element that is <i id=writing-suggestions:concept-fe-mutable-2><a href=form-control-infrastructure.html#concept-fe-mutable>mutable</a></i>; or<li><p><var>element</var> is an <a href=#editing-host id=writing-suggestions:editing-host-2>editing host</a> or is <a id=writing-suggestions:editable href=https://w3c.github.io/editing/docs/execCommand/#editable data-x-internal=editable>editable</a>,</ul> <p>then return false.</p> <li><p>If <var>element</var> has an <a id=writing-suggestions:inclusive-ancestor href=https://dom.spec.whatwg.org/#concept-tree-inclusive-ancestor data-x-internal=inclusive-ancestor>inclusive ancestor</a> with a <code id=writing-suggestions:attr-writingsuggestions-7><a href=#attr-writingsuggestions>writingsuggestions</a></code> content attribute that's not in the <a href=#attr-writingsuggestions-default-state id=writing-suggestions:attr-writingsuggestions-default-state-2>default</a> and the nearest such ancestor's <code id=writing-suggestions:attr-writingsuggestions-8><a href=#attr-writingsuggestions>writingsuggestions</a></code> content attribute is in the <a href=#attr-writingsuggestions-false-state id=writing-suggestions:attr-writingsuggestions-false-state-2>false</a> state, then return false.<li><p>Otherwise, return true.</ol> <p class=note>This specification does not define the user interface for writing suggestions. A user agent could offer on-demand suggestions, continuous suggestions as the user types, inline suggestions, autofill-like suggestions in a popup, or could use other interfaces.</p> <h4 id=autocapitalization><span class=secno>6.8.7</span> Autocapitalization<a href=#autocapitalization class=self-link></a></h4> <p>Some methods of entering text, for example virtual keyboards on mobile devices, and also voice input, often assist users by automatically capitalizing the first letter of sentences (when composing text in a language with this convention). A virtual keyboard that implements autocapitalization might automatically switch to showing uppercase letters (but allow the user to toggle it back to lowercase) when a letter that should be autocapitalized is about to be typed. Other types of input, for example voice input, may perform autocapitalization in a way that does not give users an option to intervene first. The <code id=autocapitalization:attr-autocapitalize><a href=#attr-autocapitalize>autocapitalize</a></code> attribute allows authors to control such behavior.</p> <p>The <code id=autocapitalization:attr-autocapitalize-2><a href=#attr-autocapitalize>autocapitalize</a></code> attribute, as typically implemented, does not affect behavior when typing on a physical keyboard. (For this reason, as well as the ability for users to override the autocapitalization behavior in some cases or edit the text after initial input, the attribute must not be relied on for any sort of input validation.)</p> <p>The <code id=autocapitalization:attr-autocapitalize-3><a href=#attr-autocapitalize>autocapitalize</a></code> attribute can be used on an <a href=#editing-host id=autocapitalization:editing-host>editing host</a> to control autocapitalization behavior for the hosted editable region, on an <code id=autocapitalization:the-input-element><a href=input.html#the-input-element>input</a></code> or <code id=autocapitalization:the-textarea-element><a href=form-elements.html#the-textarea-element>textarea</a></code> element to control the behavior for inputting text into that element, or on a <code id=autocapitalization:the-form-element><a href=forms.html#the-form-element>form</a></code> element to control the default behavior for all <a href=forms.html#category-autocapitalize id=autocapitalization:category-autocapitalize>autocapitalize-and-autocorrect inheriting elements</a> associated with the <code id=autocapitalization:the-form-element-2><a href=forms.html#the-form-element>form</a></code> element. <p>The <code id=autocapitalization:attr-autocapitalize-4><a href=#attr-autocapitalize>autocapitalize</a></code> attribute never causes autocapitalization to be enabled for <code id=autocapitalization:the-input-element-2><a href=input.html#the-input-element>input</a></code> elements whose <code id=autocapitalization:attr-input-type><a href=input.html#attr-input-type>type</a></code> attribute is in one of the <a href="input.html#url-state-(type=url)" id="autocapitalization:url-state-(type=url)">URL</a>, <a href="input.html#email-state-(type=email)" id="autocapitalization:email-state-(type=email)">Email</a>, or <a href="input.html#password-state-(type=password)" id="autocapitalization:password-state-(type=password)">Password</a> states. (This behavior is included in the <a href=#used-autocapitalization-hint id=autocapitalization:used-autocapitalization-hint>used autocapitalization hint</a> algorithm below.)</p> <p>The autocapitalization processing model is based on selecting among five <dfn id=autocapitalization-hint>autocapitalization hints</dfn>, defined as follows:</p> <dl><dt><dfn id=autocap-hint-default>default</dfn><dd><p>The user agent and input method should make their own determination of whether or not to enable autocapitalization.<dt><dfn id=autocap-hint-none>none</dfn><dd><p>No autocapitalization should be applied (all letters should default to lowercase).<dt><dfn id=autocap-hint-sentences>sentences</dfn><dd><p>The first letter of each sentence should default to a capital letter; all other letters should default to lowercase.<dt><dfn id=autocap-hint-words>words</dfn><dd><p>The first letter of each word should default to a capital letter; all other letters should default to lowercase.<dt><dfn id=autocap-hint-characters>characters</dfn><dd><p>All letters should default to uppercase.</dl> <div class="mdn-anno wrapped before"><button onclick=toggleStatus(this) class=mdn-anno-btn><b title="Support in all current engines." class=all-engines-flag>✔</b><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autocapitalize title="The autocapitalize global attribute is an enumerated attribute that controls whether and how text input is automatically capitalized as it is entered/edited by the user.">Global_attributes/autocapitalize</a><p class=all-engines-text>Support in all current engines.<div class=support><span class="firefox yes"><span>Firefox</span><span>111+</span></span><span class="safari no"><span>Safari</span><span>No</span></span><span class="chrome yes"><span>Chrome</span><span>43+</span></span><hr><span class="opera unknown"><span>Opera</span><span>?</span></span><span class="edge_blink yes"><span>Edge</span><span>79+</span></span><hr><span class="edge unknown"><span>Edge (Legacy)</span><span>?</span></span><span class="ie unknown"><span>Internet Explorer</span><span>?</span></span><hr><span class="firefox_android unknown"><span>Firefox Android</span><span>?</span></span><span class="safari_ios yes"><span>Safari iOS</span><span>5+</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android unknown"><span>WebView Android</span><span>?</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android unknown"><span>Opera Android</span><span>?</span></span></div></div></div><p>The <dfn data-dfn-for=html-global id=attr-autocapitalize data-dfn-type=element-attr><code>autocapitalize</code></dfn> attribute is an <a id=autocapitalization:enumerated-attribute href=common-microsyntaxes.html#enumerated-attribute>enumerated attribute</a> whose states are the possible <a href=#autocapitalization-hint id=autocapitalization:autocapitalization-hint>autocapitalization hints</a>. The <a href=#autocapitalization-hint id=autocapitalization:autocapitalization-hint-2>autocapitalization hint</a> specified by the attribute's state combines with other considerations to form the <a href=#used-autocapitalization-hint id=autocapitalization:used-autocapitalization-hint-2>used autocapitalization hint</a>, which informs the behavior of the user agent. The keywords for this attribute and their state mappings are as follows:</p> <table><thead><tr><th> Keyword <th> State <tbody><tr><td><dfn data-dfn-for=html-global/autocapitalize id=attr-autocapitalize-off data-dfn-type=attr-value><code>off</code></dfn> <td rowspan=2><a href=#autocap-hint-none id=autocapitalization:autocap-hint-none>none</a> <tr><td><dfn data-dfn-for=html-global/autocapitalize id=attr-autocapitalize-none data-dfn-type=attr-value><code>none</code></dfn> <tr><td><dfn data-dfn-for=html-global/autocapitalize id=attr-autocapitalize-on data-dfn-type=attr-value><code>on</code></dfn> <td rowspan=2><a href=#autocap-hint-sentences id=autocapitalization:autocap-hint-sentences>sentences</a> <tr><td><dfn data-dfn-for=html-global/autocapitalize id=attr-autocapitalize-sentences data-dfn-type=attr-value><code>sentences</code></dfn> <tr><td><dfn data-dfn-for=html-global/autocapitalize id=attr-autocapitalize-words data-dfn-type=attr-value><code>words</code></dfn> <td><a href=#autocap-hint-words id=autocapitalization:autocap-hint-words>words</a> <tr><td><dfn data-dfn-for=html-global/autocapitalize id=attr-autocapitalize-characters data-dfn-type=attr-value><code>characters</code></dfn> <td><a href=#autocap-hint-characters id=autocapitalization:autocap-hint-characters>characters</a> </table> <p>The attribute's <i id=autocapitalization:missing-value-default><a href=common-microsyntaxes.html#missing-value-default>missing value default</a></i> is the <a href=#autocap-hint-default id=autocapitalization:autocap-hint-default>default</a> state, and its <i id=autocapitalization:invalid-value-default><a href=common-microsyntaxes.html#invalid-value-default>invalid value default</a></i> is the <a href=#autocap-hint-sentences id=autocapitalization:autocap-hint-sentences-2>sentences</a> state. <dl class=domintro><dt><code><var>element</var>.<a href=#dom-autocapitalize id=dom-autocapitalize-dev>autocapitalize</a> [ = <var>value</var> ]</code><dd> <p>Returns the current autocapitalization state for the element, or an empty string if it hasn't been set. Note that for <code id=autocapitalization:the-input-element-3><a href=input.html#the-input-element>input</a></code> and <code id=autocapitalization:the-textarea-element-2><a href=form-elements.html#the-textarea-element>textarea</a></code> elements that inherit their state from a <code id=autocapitalization:the-form-element-3><a href=forms.html#the-form-element>form</a></code> element, this will return the autocapitalization state of the <code id=autocapitalization:the-form-element-4><a href=forms.html#the-form-element>form</a></code> element, but for an element in an editable region, this will not return the autocapitalization state of the editing host (unless this element is, in fact, the <a href=#editing-host id=autocapitalization:editing-host-2>editing host</a>).</p> <p>Can be set, to set the <code id=autocapitalization:attr-autocapitalize-5><a href=#attr-autocapitalize>autocapitalize</a></code> content attribute (and thereby change the autocapitalization behavior for the element).</p> </dl> <p>To compute the <dfn id=own-autocapitalization-hint>own autocapitalization hint</dfn> of an element <var>element</var>, run the following steps:</p> <ol><li><p>If the <code id=autocapitalization:attr-autocapitalize-6><a href=#attr-autocapitalize>autocapitalize</a></code> content attribute is present on <var>element</var>, and its value is not the empty string, return the state of the attribute.<li><p>If <var>element</var> is an <a href=forms.html#category-autocapitalize id=autocapitalization:category-autocapitalize-2>autocapitalize-and-autocorrect inheriting element</a> and has a non-null <a id=autocapitalization:form-owner href=form-control-infrastructure.html#form-owner>form owner</a>, return the <a href=#own-autocapitalization-hint id=autocapitalization:own-autocapitalization-hint>own autocapitalization hint</a> of <var>element</var>'s <a id=autocapitalization:form-owner-2 href=form-control-infrastructure.html#form-owner>form owner</a>.<li><p>Return <a href=#autocap-hint-default id=autocapitalization:autocap-hint-default-2>default</a>.</ol> <p>The <dfn data-dfn-for=HTMLElement id=dom-autocapitalize data-dfn-type=attribute><code>autocapitalize</code></dfn> getter steps are to:</p> <ol><li><p>Let <var>state</var> be the <a href=#own-autocapitalization-hint id=autocapitalization:own-autocapitalization-hint-2>own autocapitalization hint</a> of <a id=autocapitalization:this href=https://webidl.spec.whatwg.org/#this data-x-internal=this>this</a>.<li><p>If <var>state</var> is <a href=#autocap-hint-default id=autocapitalization:autocap-hint-default-3>default</a>, then return the empty string.<li><p>If <var>state</var> is <a href=#autocap-hint-none id=autocapitalization:autocap-hint-none-2>none</a>, then return "<code id=autocapitalization:attr-autocapitalize-none><a href=#attr-autocapitalize-none>none</a></code>".<li><p>If <var>state</var> is <a href=#autocap-hint-sentences id=autocapitalization:autocap-hint-sentences-3>sentences</a>, then return "<code id=autocapitalization:attr-autocapitalize-sentences><a href=#attr-autocapitalize-sentences>sentences</a></code>".<li><p>Return the keyword value corresponding to <var>state</var>.</ol> <p>The <code id=autocapitalization:dom-autocapitalize><a href=#dom-autocapitalize>autocapitalize</a></code> setter steps are to set the <code id=autocapitalization:attr-autocapitalize-7><a href=#attr-autocapitalize>autocapitalize</a></code> content attribute to the given value.</p> <hr> <p>User agents that support customizable autocapitalization behavior for a text input method and wish to allow web developers to control this functionality should, during text input into an element, compute the <dfn id=used-autocapitalization-hint>used autocapitalization hint</dfn> for the element. This will be an <a href=#autocapitalization-hint id=autocapitalization:autocapitalization-hint-3>autocapitalization hint</a> that describes the recommended autocapitalization behavior for text input into the element.</p> <p>User agents or input methods may choose to ignore or override the <a href=#used-autocapitalization-hint id=autocapitalization:used-autocapitalization-hint-3>used autocapitalization hint</a> in certain circumstances.</p> <p>The <a href=#used-autocapitalization-hint id=autocapitalization:used-autocapitalization-hint-4>used autocapitalization hint</a> for an element <var>element</var> is computed using the following algorithm:</p> <ol><li><p>If <var>element</var> is an <code id=autocapitalization:the-input-element-4><a href=input.html#the-input-element>input</a></code> element whose <code id=autocapitalization:attr-input-type-2><a href=input.html#attr-input-type>type</a></code> attribute is in one of the <a href="input.html#url-state-(type=url)" id="autocapitalization:url-state-(type=url)-2">URL</a>, <a href="input.html#email-state-(type=email)" id="autocapitalization:email-state-(type=email)-2">Email</a>, or <a href="input.html#password-state-(type=password)" id="autocapitalization:password-state-(type=password)-2">Password</a> states, then return <a href=#autocap-hint-default id=autocapitalization:autocap-hint-default-4>default</a>.<li><p>If <var>element</var> is an <code id=autocapitalization:the-input-element-5><a href=input.html#the-input-element>input</a></code> element or a <code id=autocapitalization:the-textarea-element-3><a href=form-elements.html#the-textarea-element>textarea</a></code> element, then return <var>element</var>'s <a href=#own-autocapitalization-hint id=autocapitalization:own-autocapitalization-hint-3>own autocapitalization hint</a>.<li><p>If <var>element</var> is an <a href=#editing-host id=autocapitalization:editing-host-3>editing host</a> or an <a id=autocapitalization:editable href=https://w3c.github.io/editing/docs/execCommand/#editable data-x-internal=editable>editable</a> element, then return the <a href=#own-autocapitalization-hint id=autocapitalization:own-autocapitalization-hint-4>own autocapitalization hint</a> of the <a id=autocapitalization:editing-host-of href=https://w3c.github.io/editing/docs/execCommand/#editing-host-of data-x-internal=editing-host-of>editing host of</a> <var>element</var>.<li><p><a id=autocapitalization:assert href=https://infra.spec.whatwg.org/#assert data-x-internal=assert>Assert</a>: this step is never reached, since text input only occurs in elements that meet one of the above criteria.</ol> <h4 id=autocorrection><span class=secno>6.8.8</span> Autocorrection<a href=#autocorrection class=self-link></a></h4> <p>Some methods of entering text assist users by automatically correcting misspelled words while typing, a process also known as autocorrection. User agents can support autocorrection of editable text, either in form controls (such as the value of <code id=autocorrection:the-textarea-element><a href=form-elements.html#the-textarea-element>textarea</a></code> elements), or in elements in an <a href=#editing-host id=autocorrection:editing-host>editing host</a> (e.g., using <code id=autocorrection:attr-contenteditable><a href=#attr-contenteditable>contenteditable</a></code>). Autocorrection may be accompanied by user interfaces indicating that text is about to be autocorrected or has been autocorrected, and is commonly performed when inserting punctuation characters, spaces, or new paragraphs after misspelled words. The <code id=autocorrection:attr-autocorrect><a href=#attr-autocorrect>autocorrect</a></code> attribute allows authors to control such behavior.</p> <p>The <code id=autocorrection:attr-autocorrect-2><a href=#attr-autocorrect>autocorrect</a></code> attribute can be used on an editing host to control autocorrection behavior for the hosted editable region, on an <code id=autocorrection:the-input-element><a href=input.html#the-input-element>input</a></code> or <code id=autocorrection:the-textarea-element-2><a href=form-elements.html#the-textarea-element>textarea</a></code> element to control the behavior when inserting text into that element, or on a <code id=autocorrection:the-form-element><a href=forms.html#the-form-element>form</a></code> element to control the default behavior for all <a href=forms.html#category-autocapitalize id=autocorrection:category-autocapitalize>autocapitalize-and-autocorrect inheriting elements</a> associated with the <code id=autocorrection:the-form-element-2><a href=forms.html#the-form-element>form</a></code> element.</p> <p>The <code id=autocorrection:attr-autocorrect-3><a href=#attr-autocorrect>autocorrect</a></code> attribute never causes autocorrection to be enabled for <code id=autocorrection:the-input-element-2><a href=input.html#the-input-element>input</a></code> elements whose <code id=autocorrection:attr-input-type><a href=input.html#attr-input-type>type</a></code> attribute is in one of the <a href="input.html#url-state-(type=url)" id="autocorrection:url-state-(type=url)">URL</a>, <a href="input.html#email-state-(type=email)" id="autocorrection:email-state-(type=email)">E-mail</a>, or <a href="input.html#password-state-(type=password)" id="autocorrection:password-state-(type=password)">Password</a> states. (This behavior is included in the <a href=#used-autocorrection-state id=autocorrection:used-autocorrection-state>used autocorrection state</a> algorithm below.)</p> <p>The <dfn data-dfn-for=html-global id=attr-autocorrect data-dfn-type=element-attr><code>autocorrect</code></dfn> attribute is an enumerated attribute with the following keywords and states:</p> <table><thead><tr><th>Keyword <th>State <th>Brief description <tbody><tr><td><dfn data-dfn-for=html-global/autocorrect id=attr-autocorrect-on data-dfn-type=attr-value><code>on</code></dfn> <td rowspan=2><dfn id=concept-autocorrection-on>on</dfn> <td rowspan=2>The user agent is permitted to automatically correct spelling errors while the user types. Whether spelling is automatically corrected while typing left is for the user agent to decide, and may depend on the element as well as the user's preferences. <tr><td>(the empty string) <tr><td><dfn data-dfn-for=html-global/autocorrect id=attr-autocorrect-off data-dfn-type=attr-value><code>off</code></dfn> <td><dfn id=concept-autocorrection-off>off</dfn> <td>The user agent is not allowed to automatically correct spelling while the user types. </table> <p>The attribute's <i id=autocorrection:invalid-value-default><a href=common-microsyntaxes.html#invalid-value-default>invalid value default</a></i> and <i id=autocorrection:missing-value-default><a href=common-microsyntaxes.html#missing-value-default>missing value default</a></i> are both the <a href=#concept-autocorrection-on id=autocorrection:concept-autocorrection-on>on</a> state.</p> <p>The <dfn data-dfn-for=HTMLElement id=dom-autocorrect data-dfn-type=attribute><code>autocorrect</code></dfn> getter steps are: return true if the element's <a href=#used-autocorrection-state id=autocorrection:used-autocorrection-state-2>used autocorrection state</a> is <a href=#concept-autocorrection-on id=autocorrection:concept-autocorrection-on-2>on</a> and false if the element's <a href=#used-autocorrection-state id=autocorrection:used-autocorrection-state-3>used autocorrection state</a> is <a href=#concept-autocorrection-on id=autocorrection:concept-autocorrection-on-3>off</a>. The setter steps are: if the given value is true, then the element's <code id=autocorrection:attr-autocorrect-4><a href=#attr-autocorrect>autocorrect</a></code> attribute must be set to "<code>on</code>"; otherwise it must be set to "<code>off</code>".</p> <p>To compute the <dfn id=used-autocorrection-state>used autocorrection state</dfn> of an element <var>element</var>, run these steps:</p> <ol><li><p>If <var>element</var> is an <code id=autocorrection:the-input-element-3><a href=input.html#the-input-element>input</a></code> element whose <code id=autocorrection:attr-input-type-2><a href=input.html#attr-input-type>type</a></code> attribute is in one of the <a href="input.html#url-state-(type=url)" id="autocorrection:url-state-(type=url)-2">URL</a>, <a href="input.html#email-state-(type=email)" id="autocorrection:email-state-(type=email)-2">E-mail</a>, or <a href="input.html#password-state-(type=password)" id="autocorrection:password-state-(type=password)-2">Password</a> states, then return <a href=#concept-autocorrection-on id=autocorrection:concept-autocorrection-on-4>off</a>.<li><p>If the <code id=autocorrection:attr-autocorrect-5><a href=#attr-autocorrect>autocorrect</a></code> content attribute is present on <var>element</var>, then return the state of the attribute.<li><p>If <var>element</var> is an <a href=forms.html#category-autocapitalize id=autocorrection:category-autocapitalize-2>autocapitalize-and-autocorrect inheriting element</a> and has a non-null <a id=autocorrection:form-owner href=form-control-infrastructure.html#form-owner>form owner</a>, then return the state of <var>element</var>'s <a id=autocorrection:form-owner-2 href=form-control-infrastructure.html#form-owner>form owner</a>'s <code id=autocorrection:attr-autocorrect-6><a href=#attr-autocorrect>autocorrect</a></code> attribute.<li><p>Return <a href=#concept-autocorrection-on id=autocorrection:concept-autocorrection-on-5>on</a>.</ol> <dl class=domintro><dt><var>element</var> . <code id=dom-autocorrect-dev><a href=#dom-autocorrect>autocorrect</a></code><dd><p>Returns the autocorrection behavior of the element. Note that for <a href=forms.html#category-autocapitalize id=autocorrection:category-autocapitalize-3>autocapitalize-and-autocorrect inheriting elements</a> that inherit their state from a <code id=autocorrection:the-form-element-3><a href=forms.html#the-form-element>form</a></code> element, this will return the autocorrection behavior of the <code id=autocorrection:the-form-element-4><a href=forms.html#the-form-element>form</a></code> element, but for an element in an editable region, this will not return the autocorrection behavior of the <a href=#editing-host id=autocorrection:editing-host-2>editing host</a> (unless this element is, in fact, the <a href=#editing-host id=autocorrection:editing-host-3>editing host</a>).<dt><var>element</var> . <code id=autocorrection:dom-autocorrect><a href=#dom-autocorrect>autocorrect</a></code> = <var>value</var><dd><p>Updates the <code id=autocorrection:attr-autocorrect-7><a href=#attr-autocorrect>autocorrect</a></code> content attribute (and thereby changes the autocorrection behavior of the element).</dl> <div class=example> <p>The <code id=autocorrection:the-input-element-4><a href=input.html#the-input-element>input</a></code> element in the following example would not allow autocorrection, since it does not have an <code id=autocorrection:attr-autocorrect-8><a href=#attr-autocorrect>autocorrect</a></code> content attribute and therefore inherits from the <code id=autocorrection:the-form-element-5><a href=forms.html#the-form-element>form</a></code> element, which has an attribute of "<code id=autocorrection:attr-autocorrect-off><a href=#attr-autocorrect-off>off</a></code>". However, the <code id=autocorrection:the-textarea-element-3><a href=form-elements.html#the-textarea-element>textarea</a></code> element would allow autocorrection, since it has an <code id=autocorrection:attr-autocorrect-9><a href=#attr-autocorrect>autocorrect</a></code> content attribute with a value of "<code id=autocorrection:attr-autocorrect-on><a href=#attr-autocorrect-on>on</a></code>".</p> <pre><code class='html'><c- p>&lt;</c-><c- f>form</c-> <c- e>autocorrect</c-><c- o>=</c-><c- s>&quot;off&quot;</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>input</c-> <c- e>type</c-><c- o>=</c-><c- s>&quot;search&quot;</c-><c- p>&gt;</c-> <c- p>&lt;</c-><c- f>textarea</c-> <c- e>autocorrect</c-><c- o>=</c-><c- s>&quot;on&quot;</c-><c- p>&gt;&lt;/</c-><c- f>textarea</c-><c- p>&gt;</c-> <c- p>&lt;/</c-><c- f>form</c-><c- p>&gt;</c-></code></pre> </div> <h4 id=input-modalities:-the-inputmode-attribute><span class=secno>6.8.9</span> Input modalities: the <code id=input-modalities:-the-inputmode-attribute:attr-inputmode><a href=#attr-inputmode>inputmode</a></code> attribute<a href=#input-modalities:-the-inputmode-attribute class=self-link></a></h4> <p>User agents can support the <code id=input-modalities:-the-inputmode-attribute:attr-inputmode-2><a href=#attr-inputmode>inputmode</a></code> attribute on form controls (such as the value of <code id=input-modalities:-the-inputmode-attribute:the-textarea-element><a href=form-elements.html#the-textarea-element>textarea</a></code> elements), or in elements in an <a href=#editing-host id=input-modalities:-the-inputmode-attribute:editing-host>editing host</a> (e.g., using <code id=input-modalities:-the-inputmode-attribute:attr-contenteditable><a href=#attr-contenteditable>contenteditable</a></code>).</p> <div class="mdn-anno wrapped before"><button onclick=toggleStatus(this) class=mdn-anno-btn><b title="Support in all current engines." class=all-engines-flag>✔</b><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/inputmode title="The inputmode global attribute is an enumerated attribute that hints at the type of data that might be entered by the user while editing the element or its contents. This allows a browser to display an appropriate virtual keyboard.">Global_attributes/inputmode</a><p class=all-engines-text>Support in all current engines.<div class=support><span class="firefox yes"><span>Firefox</span><span>95+</span></span><span class="safari no"><span>Safari</span><span>No</span></span><span class="chrome yes"><span>Chrome</span><span>66+</span></span><hr><span class="opera unknown"><span>Opera</span><span>?</span></span><span class="edge_blink yes"><span>Edge</span><span>79+</span></span><hr><span class="edge unknown"><span>Edge (Legacy)</span><span>?</span></span><span class="ie no"><span>Internet Explorer</span><span>No</span></span><hr><span class="firefox_android yes"><span>Firefox Android</span><span>79+</span></span><span class="safari_ios yes"><span>Safari iOS</span><span>12.2+</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android unknown"><span>WebView Android</span><span>?</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android unknown"><span>Opera Android</span><span>?</span></span></div></div></div><p>The <dfn data-dfn-for=html-global id=attr-inputmode data-dfn-type=element-attr><code>inputmode</code></dfn> content attribute is an <a id=input-modalities:-the-inputmode-attribute:enumerated-attribute href=common-microsyntaxes.html#enumerated-attribute>enumerated attribute</a> that specifies what kind of input mechanism would be most helpful for users entering content.</p> <table><thead><tr><th> Keyword <th> Description <tbody><tr><td><dfn data-dfn-for=html-global/inputmode id=attr-inputmode-keyword-none data-dfn-type=attr-value><code>none</code></dfn> <td>The user agent should not display a virtual keyboard. This keyword is useful for content that renders its own keyboard control. <tr><td><dfn data-dfn-for=html-global/inputmode id=attr-inputmode-keyword-text data-dfn-type=attr-value><code>text</code></dfn> <td>The user agent should display a virtual keyboard capable of text input in the user's locale. <tr><td><dfn data-dfn-for=html-global/inputmode id=attr-inputmode-keyword-tel data-dfn-type=attr-value><code>tel</code></dfn> <td> The user agent should display a virtual keyboard capable of telephone number input. This should including keys for the digits 0 to 9, the "#" character, and the "*" character. In some locales, this can also include alphabetic mnemonic labels (e.g., in the US, the key labeled "2" is historically also labeled with the letters A, B, and C). <tr><td><dfn data-dfn-for=html-global/inputmode id=attr-inputmode-keyword-url data-dfn-type=attr-value><code>url</code></dfn> <td>The user agent should display a virtual keyboard capable of text input in the user's locale, with keys for aiding in the input of <a href=https://url.spec.whatwg.org/#concept-url id=input-modalities:-the-inputmode-attribute:url data-x-internal=url>URLs</a>, such as that for the "/" and "." characters and for quick input of strings commonly found in domain names such as "www." or ".com". <tr><td><dfn data-dfn-for=html-global/inputmode id=attr-inputmode-keyword-email data-dfn-type=attr-value><code>email</code></dfn> <td>The user agent should display a virtual keyboard capable of text input in the user's locale, with keys for aiding in the input of email addresses, such as that for the "@" character and the "." character. <tr><td><dfn data-dfn-for=html-global/inputmode id=attr-inputmode-keyword-numeric data-dfn-type=attr-value><code>numeric</code></dfn> <td> The user agent should display a virtual keyboard capable of numeric input. This keyword is useful for PIN entry. <tr><td><dfn data-dfn-for=html-global/inputmode id=attr-inputmode-keyword-decimal data-dfn-type=attr-value><code>decimal</code></dfn> <td> The user agent should display a virtual keyboard capable of fractional numeric input. Numeric keys and the format separator for the locale should be shown. <tr><td><dfn data-dfn-for=html-global/inputmode id=attr-inputmode-keyword-search data-dfn-type=attr-value><code>search</code></dfn> <td>The user agent should display a virtual keyboard optimized for search. </table> <div class="mdn-anno wrapped before"><button onclick=toggleStatus(this) class=mdn-anno-btn><b title="Support in all current engines." class=all-engines-flag>✔</b><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/inputMode title="The HTMLElement property inputMode reflects the value of the element's inputmode attribute.">HTMLElement/inputMode</a><p class=all-engines-text>Support in all current engines.<div class=support><span class="firefox yes"><span>Firefox</span><span>95+</span></span><span class="safari yes"><span>Safari</span><span>12.1+</span></span><span class="chrome yes"><span>Chrome</span><span>66+</span></span><hr><span class="opera unknown"><span>Opera</span><span>?</span></span><span class="edge_blink yes"><span>Edge</span><span>79+</span></span><hr><span class="edge unknown"><span>Edge (Legacy)</span><span>?</span></span><span class="ie no"><span>Internet Explorer</span><span>No</span></span><hr><span class="firefox_android yes"><span>Firefox Android</span><span>79+</span></span><span class="safari_ios unknown"><span>Safari iOS</span><span>?</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android unknown"><span>WebView Android</span><span>?</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android unknown"><span>Opera Android</span><span>?</span></span></div></div></div><p>The <dfn data-dfn-for=ElementContentEditable id=dom-inputmode data-dfn-type=attribute><code>inputMode</code></dfn> IDL attribute must <a id=input-modalities:-the-inputmode-attribute:reflect href=common-dom-interfaces.html#reflect>reflect</a> the <code id=input-modalities:-the-inputmode-attribute:attr-inputmode-3><a href=#attr-inputmode>inputmode</a></code> content attribute, <a id=input-modalities:-the-inputmode-attribute:limited-to-only-known-values href=common-dom-interfaces.html#limited-to-only-known-values>limited to only known values</a>.</p> <p>When <code id=input-modalities:-the-inputmode-attribute:attr-inputmode-4><a href=#attr-inputmode>inputmode</a></code> is unspecified (or is in a state not supported by the user agent), the user agent should determine the default virtual keyboard to be shown. Contextual information such as the input <code id=input-modalities:-the-inputmode-attribute:attr-input-type><a href=input.html#attr-input-type>type</a></code> or <code id=input-modalities:-the-inputmode-attribute:attr-input-pattern><a href=input.html#attr-input-pattern>pattern</a></code> attributes should be used to determine which type of virtual keyboard should be presented to the user.</p> <h4 id=input-modalities:-the-enterkeyhint-attribute><span class=secno>6.8.10</span> Input modalities: the <code id=input-modalities:-the-enterkeyhint-attribute:attr-enterkeyhint><a href=#attr-enterkeyhint>enterkeyhint</a></code> attribute<a href=#input-modalities:-the-enterkeyhint-attribute class=self-link></a></h4> <p>User agents can support the <code id=input-modalities:-the-enterkeyhint-attribute:attr-enterkeyhint-2><a href=#attr-enterkeyhint>enterkeyhint</a></code> attribute on form controls (such as the value of <code id=input-modalities:-the-enterkeyhint-attribute:the-textarea-element><a href=form-elements.html#the-textarea-element>textarea</a></code> elements), or in elements in an <a href=#editing-host id=input-modalities:-the-enterkeyhint-attribute:editing-host>editing host</a> (e.g., using <code id=input-modalities:-the-enterkeyhint-attribute:attr-contenteditable><a href=#attr-contenteditable>contenteditable</a></code>).</p> <div class="mdn-anno wrapped before"><button onclick=toggleStatus(this) class=mdn-anno-btn><b title="Support in all current engines." class=all-engines-flag>✔</b><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/enterkeyhint title="The enterkeyhint global attribute is an enumerated attribute defining what action label (or icon) to present for the enter key on virtual keyboards.">Global_attributes/enterkeyhint</a><p class=all-engines-text>Support in all current engines.<div class=support><span class="firefox yes"><span>Firefox</span><span>94+</span></span><span class="safari yes"><span>Safari</span><span>13.1+</span></span><span class="chrome yes"><span>Chrome</span><span>77+</span></span><hr><span class="opera yes"><span>Opera</span><span>66+</span></span><span class="edge_blink yes"><span>Edge</span><span>79+</span></span><hr><span class="edge unknown"><span>Edge (Legacy)</span><span>?</span></span><span class="ie no"><span>Internet Explorer</span><span>No</span></span><hr><span class="firefox_android unknown"><span>Firefox Android</span><span>?</span></span><span class="safari_ios unknown"><span>Safari iOS</span><span>?</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android unknown"><span>WebView Android</span><span>?</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android yes"><span>Opera Android</span><span>57+</span></span></div></div></div><p>The <dfn data-dfn-for=html-global id=attr-enterkeyhint data-dfn-type=element-attr><code>enterkeyhint</code></dfn> content attribute is an <a id=input-modalities:-the-enterkeyhint-attribute:enumerated-attribute href=common-microsyntaxes.html#enumerated-attribute>enumerated attribute</a> that specifies what action label (or icon) to present for the enter key on virtual keyboards. This allows authors to customize the presentation of the enter key in order to make it more helpful for users.</p> <table><thead><tr><th> Keyword <th> Description <tbody><tr><td><dfn data-dfn-for=html-global/enterkeyhint id=attr-enterkeyhint-keyword-enter data-dfn-type=attr-value><code>enter</code></dfn> <td>The user agent should present a cue for the operation 'enter', typically inserting a new line. <tr><td><dfn data-dfn-for=html-global/enterkeyhint id=attr-enterkeyhint-keyword-done data-dfn-type=attr-value><code>done</code></dfn> <td>The user agent should present a cue for the operation 'done', typically meaning there is nothing more to input and the input method editor (IME) will be closed. <tr><td><dfn data-dfn-for=html-global/enterkeyhint id=attr-enterkeyhint-keyword-go data-dfn-type=attr-value><code>go</code></dfn> <td> The user agent should present a cue for the operation 'go', typically meaning to take the user to the target of the text they typed. <tr><td><dfn data-dfn-for=html-global/enterkeyhint id=attr-enterkeyhint-keyword-next data-dfn-type=attr-value><code>next</code></dfn> <td>The user agent should present a cue for the operation 'next', typically taking the user to the next field that will accept text. <tr><td><dfn data-dfn-for=html-global/enterkeyhint id=attr-enterkeyhint-keyword-previous data-dfn-type=attr-value><code>previous</code></dfn> <td>The user agent should present a cue for the operation 'previous', typically taking the user to the previous field that will accept text. <tr><td><dfn data-dfn-for=html-global/enterkeyhint id=attr-enterkeyhint-keyword-search data-dfn-type=attr-value><code>search</code></dfn> <td>The user agent should present a cue for the operation 'search', typically taking the user to the results of searching for the text they have typed. <tr><td><dfn data-dfn-for=html-global/enterkeyhint id=attr-enterkeyhint-keyword-send data-dfn-type=attr-value><code>send</code></dfn> <td> The user agent should present a cue for the operation 'send', typically delivering the text to its target. </table> <div class="mdn-anno wrapped before"><button onclick=toggleStatus(this) class=mdn-anno-btn><b title="Support in all current engines." class=all-engines-flag>✔</b><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/enterKeyHint title="The enterKeyHint property is an enumerated property defining what action label (or icon) to present for the enter key on virtual keyboards. It reflects the enterkeyhint HTML global attribute and is an enumerated property, only accepting the following values as a string:">HTMLElement/enterKeyHint</a><p class=all-engines-text>Support in all current engines.<div class=support><span class="firefox yes"><span>Firefox</span><span>94+</span></span><span class="safari yes"><span>Safari</span><span>13.1+</span></span><span class="chrome yes"><span>Chrome</span><span>77+</span></span><hr><span class="opera unknown"><span>Opera</span><span>?</span></span><span class="edge_blink yes"><span>Edge</span><span>79+</span></span><hr><span class="edge unknown"><span>Edge (Legacy)</span><span>?</span></span><span class="ie no"><span>Internet Explorer</span><span>No</span></span><hr><span class="firefox_android unknown"><span>Firefox Android</span><span>?</span></span><span class="safari_ios unknown"><span>Safari iOS</span><span>?</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android unknown"><span>WebView Android</span><span>?</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android unknown"><span>Opera Android</span><span>?</span></span></div></div></div><p>The <dfn data-dfn-for=ElementContentEditable id=dom-enterkeyhint data-dfn-type=attribute><code>enterKeyHint</code></dfn> IDL attribute must <a id=input-modalities:-the-enterkeyhint-attribute:reflect href=common-dom-interfaces.html#reflect>reflect</a> the <code id=input-modalities:-the-enterkeyhint-attribute:attr-enterkeyhint-3><a href=#attr-enterkeyhint>enterkeyhint</a></code> content attribute, <a id=input-modalities:-the-enterkeyhint-attribute:limited-to-only-known-values href=common-dom-interfaces.html#limited-to-only-known-values>limited to only known values</a>.</p> <p>When <code id=input-modalities:-the-enterkeyhint-attribute:attr-enterkeyhint-4><a href=#attr-enterkeyhint>enterkeyhint</a></code> is unspecified (or is in a state not supported by the user agent), the user agent should determine the default action label (or icon) to present. Contextual information such as the <code id=input-modalities:-the-enterkeyhint-attribute:attr-inputmode><a href=#attr-inputmode>inputmode</a></code>, <code id=input-modalities:-the-enterkeyhint-attribute:attr-input-type><a href=input.html#attr-input-type>type</a></code>, or <code id=input-modalities:-the-enterkeyhint-attribute:attr-input-pattern><a href=input.html#attr-input-pattern>pattern</a></code> attributes should be used to determine which action label (or icon) to present on the virtual keyboard.</p> <h3 id=find-in-page><span class=secno>6.9</span> Find-in-page<a href=#find-in-page class=self-link></a></h3> <h4 id=introduction-10><span class=secno>6.9.1</span> Introduction<a href=#introduction-10 class=self-link></a></h4> <p>This section defines <dfn id=find-in-page-2>find-in-page</dfn> — a common user-agent mechanism which allows users to search through the contents of the page for particular information.</p> <p>Access to the <a href=#find-in-page-2 id=introduction-10:find-in-page-2>find-in-page</a> feature is provided via a <dfn id=find-in-page-interface>find-in-page interface</dfn>. This is a user-agent provided user interface, which allows the user to specify input and the parameters of the search. This interface can appear as a result of a shortcut or a menu selection.</p> <p>A combination of text input and settings in the <a href=#find-in-page-interface id=introduction-10:find-in-page-interface>find-in-page interface</a> represents the user <dfn id=fip-query>query</dfn>. This typically includes the text that the user wants to search for, as well as optional settings (e.g., the ability to restrict the search to whole words only).</p> <p>The user-agent processes page contents for a given <a href=#fip-query id=introduction-10:fip-query>query</a>, and identifies zero or more <dfn id=fip-matches>matches</dfn>, which are content ranges that satisfy the user <a href=#fip-query id=introduction-10:fip-query-2>query</a>.</p> <p>One of the <a href=#fip-matches id=introduction-10:fip-matches>matches</a> is identified to the user as the <dfn id=fip-active-match>active match</dfn>. It is highlighted and scrolled into view. The user can navigate through the <a href=#fip-matches id=introduction-10:fip-matches-2>matches</a> by advancing the <a href=#fip-active-match id=introduction-10:fip-active-match>active match</a> using the <a href=#find-in-page-interface id=introduction-10:find-in-page-interface-2>find-in-page interface</a>.</p> <p class=XXX><a href=https://github.com/whatwg/html/issues/3539>Issue #3539</a> tracks standardizing how <a href=#find-in-page-2 id=introduction-10:find-in-page-2-2>find-in-page</a> underlies the currently-unspecified <code>window.find()</code> API.</p> <h4 id="interaction-with-details-and-hidden=until-found"><span class=secno>6.9.2</span> Interaction with <code id="interaction-with-details-and-hidden=until-found:the-details-element"><a href=interactive-elements.html#the-details-element>details</a></code> and <code id="interaction-with-details-and-hidden=until-found:attr-hidden-until-found-state"><a href=#attr-hidden-until-found-state>hidden=until-found</a></code><a href="#interaction-with-details-and-hidden=until-found" class=self-link></a></h4> <p>When find-in-page begins searching for matches, all <code id="interaction-with-details-and-hidden=until-found:the-details-element-2"><a href=interactive-elements.html#the-details-element>details</a></code> elements in the page which do not have their <code id="interaction-with-details-and-hidden=until-found:attr-details-open"><a href=interactive-elements.html#attr-details-open>open</a></code> attribute set should have the <a href=https://drafts.csswg.org/css-contain/#skips-its-contents id="interaction-with-details-and-hidden=until-found:skips-its-contents" data-x-internal=skips-its-contents>skipped contents</a> of their second slot become accessible, without modifying the <code id="interaction-with-details-and-hidden=until-found:attr-details-open-2"><a href=interactive-elements.html#attr-details-open>open</a></code> attribute, in order to make find-in-page able to search through it. Similarly, all HTML elements with the <code id="interaction-with-details-and-hidden=until-found:attr-hidden"><a href=#attr-hidden>hidden</a></code> attribute in the <a href=#attr-hidden-until-found-state id="interaction-with-details-and-hidden=until-found:attr-hidden-until-found-state-2">hidden until found</a> state should have their <a href=https://drafts.csswg.org/css-contain/#skips-its-contents id="interaction-with-details-and-hidden=until-found:skips-its-contents-2" data-x-internal=skips-its-contents>skipped contents</a> become accessible without modifying the <code id="interaction-with-details-and-hidden=until-found:attr-hidden-2"><a href=#attr-hidden>hidden</a></code> attribute in order to make find-in-page able to search through them. After find-in-page finishes searching for matches, the <code id="interaction-with-details-and-hidden=until-found:the-details-element-3"><a href=interactive-elements.html#the-details-element>details</a></code> elements and the elements with the <code id="interaction-with-details-and-hidden=until-found:attr-hidden-3"><a href=#attr-hidden>hidden</a></code> attribute in the <a href=#attr-hidden-until-found-state id="interaction-with-details-and-hidden=until-found:attr-hidden-until-found-state-3">hidden until found</a> state should have their contents become skipped again. This entire process must happen synchronously (and so is not observable to users or to author code). <a href=references.html#refsCSSCONTAIN>[CSSCONTAIN]</a></p> <p>When find-in-page chooses a new <a href=#fip-active-match id="interaction-with-details-and-hidden=until-found:fip-active-match">active match</a>, perform the following steps:</p> <ol><li><p>Let <var>node</var> be the first node in the <a href=#fip-active-match id="interaction-with-details-and-hidden=until-found:fip-active-match-2">active match</a>.<li><p><a id="interaction-with-details-and-hidden=until-found:queue-a-global-task" href=webappapis.html#queue-a-global-task>Queue a global task</a> on the <a id="interaction-with-details-and-hidden=until-found:user-interaction-task-source" href=webappapis.html#user-interaction-task-source>user interaction task source</a> given <var>node</var>'s <a id="interaction-with-details-and-hidden=until-found:concept-relevant-global" href=webappapis.html#concept-relevant-global>relevant global object</a> to run the following steps:</p> <ol><li><p>Run the <a id="interaction-with-details-and-hidden=until-found:ancestor-details-revealing-algorithm" href=interactive-elements.html#ancestor-details-revealing-algorithm>ancestor details revealing algorithm</a> on <var>node</var>.<li><p>Run the <a href=#ancestor-hidden-until-found-revealing-algorithm id="interaction-with-details-and-hidden=until-found:ancestor-hidden-until-found-revealing-algorithm">ancestor hidden-until-found revealing algorithm</a> on <var>node</var>.</ol> </ol> <p class=warning> <a id="interaction-with-details-and-hidden=until-found:tracking-vector" title="There is a tracking vector here." href=https://infra.spec.whatwg.org/#tracking-vector class=tracking-vector data-x-internal=tracking-vector><img width=46 alt="(This is a tracking vector.)" crossorigin="" src=https://resources.whatwg.org/tracking-vector.svg height=64></a> When find-in-page auto-expands a <code id="interaction-with-details-and-hidden=until-found:the-details-element-4"><a href=interactive-elements.html#the-details-element>details</a></code> element like this, it will fire a <code id="interaction-with-details-and-hidden=until-found:event-toggle"><a href=indices.html#event-toggle>toggle</a></code> event. As with the separate <code id="interaction-with-details-and-hidden=until-found:event-scroll"><a data-x-internal=event-scroll href=https://drafts.csswg.org/cssom-view/#eventdef-document-scroll>scroll</a></code> event that find-in-page fires, this event could be used by the page to discover what the user is typing into the find-in-page dialog. If the page creates a tiny scrollable area with the current search term and every possible next character the user could type separated by a gap, and observes which one the browser scrolls to, it can add that character to the search term and update the scrollable area to incrementally build the search term. By wrapping each possible next match in a closed <code id="interaction-with-details-and-hidden=until-found:the-details-element-5"><a href=interactive-elements.html#the-details-element>details</a></code> element, the page could listen to <code id="interaction-with-details-and-hidden=until-found:event-toggle-2"><a href=indices.html#event-toggle>toggle</a></code> events instead of <code id="interaction-with-details-and-hidden=until-found:event-scroll-2"><a data-x-internal=event-scroll href=https://drafts.csswg.org/cssom-view/#eventdef-document-scroll>scroll</a></code> events. This attack could be addressed for both events by not acting on every character the user types into the find-in-page dialog.</p> <h4 id=interaction-with-selection><span class=secno>6.9.3</span> Interaction with selection<a href=#interaction-with-selection class=self-link></a></h4> <p>The find-in-page process is invoked in the context of a document, and may have an effect on the <a href=https://w3c.github.io/selection-api/#dfn-selection id=interaction-with-selection:document-selection data-x-internal=document-selection>selection</a> of that document. Specifically, the range that defines the <a href=#fip-active-match id=interaction-with-selection:fip-active-match>active match</a> can dictate the current selection. These selection updates, however, can happen at different times during the find-in-page process (e.g. upon the <a href=#find-in-page-interface id=interaction-with-selection:find-in-page-interface>find-in-page interface</a> dismissal or upon a change in the <a href=#fip-active-match id=interaction-with-selection:fip-active-match-2>active match</a> range). <h3 id=close-requests-and-close-watchers><span class=secno>6.10</span> Close requests and close watchers<a href=#close-requests-and-close-watchers class=self-link></a></h3> <h4 id=close-requests><span class=secno>6.10.1</span> Close requests<a href=#close-requests class=self-link></a></h4> <p>In an <a id=close-requests:implementation-defined href=https://infra.spec.whatwg.org/#implementation-defined data-x-internal=implementation-defined>implementation-defined</a> (and likely device-specific) manner, a user can send a <dfn id=close-request data-export="">close request</dfn> to the user agent. This indicates that the user wishes to close something that is currently being shown on the screen, such as a popover, menu, dialog, picker, or display mode.</p> <div class=example> <p>Some example close requests are:</p> <ul><li><p>The <kbd>Esc</kbd> key on desktop platforms.<li><p>The back button or gesture on certain mobile platforms such as Android.<li><p>Any assistive technology's dismiss gesture, such as iOS VoiceOver's two-finger scrub "z" gesture.<li><p>A game controller's canonical "back" button, such as the circle button on a DualShock gamepad.</ul> </div> <p>Whenever the user agent receives a potential close request targeted at a <code id=close-requests:document><a href=dom.html#document>Document</a></code> <var>document</var>, it must <a id=close-requests:queue-a-global-task href=webappapis.html#queue-a-global-task>queue a global task</a> on the <a id=close-requests:user-interaction-task-source href=webappapis.html#user-interaction-task-source>user interaction task source</a> given <var>document</var>'s <a id=close-requests:concept-relevant-global href=webappapis.html#concept-relevant-global>relevant global object</a> to perform the following <dfn id=close-request-steps data-export="">close request steps</dfn>:</p> <ol><li> <p>If <var>document</var>'s <a id=close-requests:fullscreen-element href=https://fullscreen.spec.whatwg.org/#fullscreen-element data-x-internal=fullscreen-element>fullscreen element</a> is not null, then:</p> <ol><li><p><a id=close-requests:fully-exit-fullscreen href=https://fullscreen.spec.whatwg.org/#fully-exit-fullscreen data-x-internal=fully-exit-fullscreen>Fully exit fullscreen</a> given <var>document</var>'s <a id=close-requests:node-navigable href=document-sequences.html#node-navigable>node navigable</a>'s <a href=document-sequences.html#nav-top id=close-requests:nav-top>top-level traversable</a>'s <a href=document-sequences.html#nav-document id=close-requests:nav-document>active document</a>.<li><p>Return.</p> </ol> <p class=note>This does <em>not</em> fire any relevant event, such as <code id=close-requests:event-keydown><a data-x-internal=event-keydown href=https://w3c.github.io/uievents/#event-type-keydown>keydown</a></code>; it only causes <code id=close-requests:event-fullscreenchange><a data-x-internal=event-fullscreenchange href=https://fullscreen.spec.whatwg.org/#eventdef-document-fullscreenchange>fullscreenchange</a></code> to be eventually fired.</p> <li> <p>Optionally, skip to the step labeled <a href=#close-request-fallback>alternative processing</a>.</p> <p class=note>For example, if the user agent detects user frustration at repeated close request interception by the current web page, it might take this path.</p> <li> <p>Fire any relevant events, per <cite>UI Events</cite> or other relevant specifications. <a href=references.html#refsUIEVENTS>[UIEVENTS]</a></p> <p class=example>An example of a relevant event in the <cite>UI Events</cite> model would be the <code id=close-requests:event-keydown-2><a data-x-internal=event-keydown href=https://w3c.github.io/uievents/#event-type-keydown>keydown</a></code> event that <cite>UI Events</cite> <a href=https://w3c.github.io/uievents/#events-keyboard-event-order>suggests</a> firing when the user presses the <kbd>Esc</kbd> key on their keyboard. On most platforms with keyboards, this is treated as a <a href=#close-request id=close-requests:close-request>close request</a>, and so would trigger these <a href=#close-request-steps id=close-requests:close-request-steps>close request steps</a>.</p> <p class=example>An example of relevant events that are outside of the model given in <cite>UI Events</cite> would be assistive technology synthesizing an <kbd>Esc</kbd> <code id=close-requests:event-keydown-3><a data-x-internal=event-keydown href=https://w3c.github.io/uievents/#event-type-keydown>keydown</a></code> event when the user sends a <a href=#close-request id=close-requests:close-request-2>close request</a> by using a dismiss gesture.</p> <li><p>Let <var>event</var> be null if no such events are fired, or the <code id=close-requests:event><a data-x-internal=event href=https://dom.spec.whatwg.org/#interface-event>Event</a></code> object representing one of the fired events otherwise. If multiple events are fired, which one is chosen is <a id=close-requests:implementation-defined-2 href=https://infra.spec.whatwg.org/#implementation-defined data-x-internal=implementation-defined>implementation-defined</a>.<li><p>If <var>event</var> is not null, and its <a id=close-requests:canceled-flag href=https://dom.spec.whatwg.org/#canceled-flag data-x-internal=canceled-flag>canceled flag</a> is set, then return.<li> <p>If <var>document</var> is not <a id=close-requests:fully-active href=document-sequences.html#fully-active>fully active</a>, then return.</p> <p class=note>This step is necessary because, if <var>event</var> is not null, then an event listener might have caused <var>document</var> to no longer be <a id=close-requests:fully-active-2 href=document-sequences.html#fully-active>fully active</a>.</p> <li><p>Let <var>closedSomething</var> be the result of <a href=#process-close-watchers id=close-requests:process-close-watchers>processing close watchers</a> on <var>document</var>'s <a id=close-requests:concept-relevant-global-2 href=webappapis.html#concept-relevant-global>relevant global object</a>.<li><p>If <var>closedSomething</var> is true, then return.<li id=close-request-fallback><p><i>Alternative processing</i>: Otherwise, there was nothing watching for a <a href=#close-request id=close-requests:close-request-3>close request</a>. The user agent may instead interpret this interaction as some other action, instead of interpreting it as a close request.</ol> <p>On platforms where pressing the <kbd>Esc</kbd> key is interpreted as a <a href=#close-request id=close-requests:close-request-4>close request</a>, the user agent must interpret the key being pressed <em>down</em> as the close request, instead of the key being released. Thus, in the above algorithm, the "relevant events" that are fired must be the single <code id=close-requests:event-keydown-4><a data-x-internal=event-keydown href=https://w3c.github.io/uievents/#event-type-keydown>keydown</a></code> event.</p> <p class=example>On platforms where <kbd>Esc</kbd> is the <a href=#close-request id=close-requests:close-request-5>close request</a>, the user agent will first fire an appropriately-initialized <code id=close-requests:event-keydown-5><a data-x-internal=event-keydown href=https://w3c.github.io/uievents/#event-type-keydown>keydown</a></code> event. If the web developer cancels the event by calling <code id=close-requests:dom-event-preventdefault><a data-x-internal=dom-event-preventdefault href=https://dom.spec.whatwg.org/#dom-event-preventdefault>preventDefault()</a></code>, then nothing further happens. But if the event fires without being canceled, then the user agent proceeds to <a href=#process-close-watchers id=close-requests:process-close-watchers-2>process close watchers</a>.</p> <p class=example>On platforms where a back button is a potential <a href=#close-request id=close-requests:close-request-6>close request</a>, no event is involved, so when the back button is pressed, the user agent proceeds directly to <a href=#process-close-watchers id=close-requests:process-close-watchers-3>process close watchers</a>. If there is an <a href=#close-watcher-active id=close-requests:close-watcher-active>active</a> <a href=#close-watcher id=close-requests:close-watcher>close watcher</a>, then that will get triggered. If there is not, then the user agent can interpret the back button press in another way, for example as a request to <a id=close-requests:traverse-the-history-by-a-delta href=browsing-the-web.html#traverse-the-history-by-a-delta>traverse the history by a delta</a> of −1.</p> <h4 id=close-watcher-infrastructure><span class=secno>6.10.2</span> Close watcher infrastructure<a href=#close-watcher-infrastructure class=self-link></a></h4> <p>Each <code id=close-watcher-infrastructure:window><a href=nav-history-apis.html#window>Window</a></code> has a <dfn id=close-watcher-manager>close watcher manager</dfn>, which is a <a id=close-watcher-infrastructure:struct href=https://infra.spec.whatwg.org/#struct data-x-internal=struct>struct</a> with the following <a href=https://infra.spec.whatwg.org/#struct-item id=close-watcher-infrastructure:struct-item data-x-internal=struct-item>items</a>:</p> <ul><li><p><dfn id=close-watcher-manager-groups>Groups</dfn>, a <a id=close-watcher-infrastructure:list href=https://infra.spec.whatwg.org/#list data-x-internal=list>list</a> of <a href=https://infra.spec.whatwg.org/#list id=close-watcher-infrastructure:list-2 data-x-internal=list>lists</a> of <a href=#close-watcher id=close-watcher-infrastructure:close-watcher>close watchers</a>, initially empty.<li><p><dfn id=close-watcher-manager-allowed-number-of-groups>Allowed number of groups</dfn>, a number, initially 1.<li><p><dfn id=close-watcher-manager-next>Next user interaction allows a new group</dfn>, a boolean, initially true.</ul> <p>Most of the complexity of the <a href=#close-watcher-manager id=close-watcher-infrastructure:close-watcher-manager>close watcher manager</a> comes from anti-abuse protections designed to prevent developers from disabling users' history traversal abilities, for platforms where a <a href=#close-request id=close-watcher-infrastructure:close-request>close request</a>'s <a href=#close-request-fallback>fallback action</a> is the main mechanism of history traversal. In particular:</p> <p>The grouping of <a href=#close-watcher id=close-watcher-infrastructure:close-watcher-2>close watchers</a> is designed so that if multiple close watchers are created without <a href=#history-action-activation id=close-watcher-infrastructure:history-action-activation>history-action activation</a>, they are grouped together, so that a user-triggered <a href=#close-request id=close-watcher-infrastructure:close-request-2>close request</a> will close all of the close watchers in a group. This ensures that web developers can't intercept an unlimited number of close requests by creating close watchers; instead they can create a number equal to at most 1 + the number of times the <a href=#tracking-user-activation id=close-watcher-infrastructure:tracking-user-activation>user activates the page</a>.</p> <p>The <a href=#close-watcher-manager-next id=close-watcher-infrastructure:close-watcher-manager-next>next user interaction allows a new group</a> boolean encourages web developers to create <a href=#close-watcher id=close-watcher-infrastructure:close-watcher-3>close watchers</a> in a way that is tied to individual <a href=#tracking-user-activation id=close-watcher-infrastructure:tracking-user-activation-2>user activations</a>. Without it, each user activation would increase the <a href=#close-watcher-manager-allowed-number-of-groups id=close-watcher-infrastructure:close-watcher-manager-allowed-number-of-groups>allowed number of groups</a>, even if the web developer isn't "using" those user activations to create close watchers. In short:</p> <ul><li><p>Allowed: user interaction; create a close watcher in its own group; user interaction; create a close watcher in a second independent group.<li><p>Disallowed: user interaction; user interaction; create a close watcher in its own group; create a close watcher in a second independent group.<li><p>Allowed: user interaction; user interaction; create a close watcher in its own group; create a close watcher grouped with the previous one.</ul> <p>This protection is <em>not</em> important for upholding our desired invariant of creating at most (1 + the number of times the <a href=#tracking-user-activation id=close-watcher-infrastructure:tracking-user-activation-3>user activates the page</a>) groups. A determined abuser will just create one close watcher per user interaction, "banking" them for future abuse. But this system causes more predictable behavior for the normal case, and encourages non-abusive developers to create close watchers directly in response to user interactions.</p> <p>To <dfn id=notify-the-close-watcher-manager-about-user-activation>notify the close watcher manager about user activation</dfn> given a <code id=close-watcher-infrastructure:window-2><a href=nav-history-apis.html#window>Window</a></code> <var>window</var>:</p> <ol><li><p>Let <var>manager</var> be <var>window</var>'s <a href=#close-watcher-manager id=close-watcher-infrastructure:close-watcher-manager-2>close watcher manager</a>.<li><p>If <var>manager</var>'s <a href=#close-watcher-manager-next id=close-watcher-infrastructure:close-watcher-manager-next-2>next user interaction allows a new group</a> is true, then increment <var>manager</var>'s <a href=#close-watcher-manager-allowed-number-of-groups id=close-watcher-infrastructure:close-watcher-manager-allowed-number-of-groups-2>allowed number of groups</a>.<li><p>Set <var>manager</var>'s <a href=#close-watcher-manager-next id=close-watcher-infrastructure:close-watcher-manager-next-3>next user interaction allows a new group</a> to false.</ol> <hr> <p>A <dfn id=close-watcher data-export="">close watcher</dfn> is a <a id=close-watcher-infrastructure:struct-2 href=https://infra.spec.whatwg.org/#struct data-x-internal=struct>struct</a> with the following <a href=https://infra.spec.whatwg.org/#struct-item id=close-watcher-infrastructure:struct-item-2 data-x-internal=struct-item>items</a>:</p> <ul><li><p>A <dfn id=close-watcher-window>window</dfn>, a <code id=close-watcher-infrastructure:window-3><a href=nav-history-apis.html#window>Window</a></code>.<li><p>A <dfn id=close-watcher-cancel-action>cancel action</dfn>, an algorithm accepting a boolean argument and returning a boolean. The argument indicates whether or not the cancel action algorithm can prevent the close request from proceeding via the algorithm's return value. If the boolean argument is true, then the algorithm can return either true to indicate that the caller will proceed to the <a href=#close-watcher-close-action id=close-watcher-infrastructure:close-watcher-close-action>close action</a>, or false to indicate that the caller will bail out. If the argument is false, then the return value is always false. This algorithm can never throw an exception.<li><p>A <dfn id=close-watcher-close-action>close action</dfn>, an algorithm accepting no arguments and returning nothing. This algorithm can never throw an exception.<li><p>An <dfn id=close-watcher-is-running-cancel>is running cancel action</dfn> boolean.</ul> <p>A <a href=#close-watcher id=close-watcher-infrastructure:close-watcher-4>close watcher</a> <var>closeWatcher</var> <dfn id=close-watcher-active>is active</dfn> if <var>closeWatcher</var>'s <a href=#close-watcher-window id=close-watcher-infrastructure:close-watcher-window>window</a>'s <a href=#close-watcher-manager id=close-watcher-infrastructure:close-watcher-manager-3>close watcher manager</a> <a href=https://infra.spec.whatwg.org/#list-contain id=close-watcher-infrastructure:list-contains data-x-internal=list-contains>contains</a> any list which <a href=https://infra.spec.whatwg.org/#list-contain id=close-watcher-infrastructure:list-contains-2 data-x-internal=list-contains>contains</a> <var>closeWatcher</var>.</p> <hr> <p>To <dfn id=establish-a-close-watcher>establish a close watcher</dfn> given a <code id=close-watcher-infrastructure:window-4><a href=nav-history-apis.html#window>Window</a></code> <var>window</var>, a list of steps <dfn id=create-close-watcher-cancelaction><var>cancelAction</var></dfn>, and a list of steps <dfn id=create-close-watcher-closeaction><var>closeAction</var></dfn>:</p> <ol><li><p><a id=close-watcher-infrastructure:assert href=https://infra.spec.whatwg.org/#assert data-x-internal=assert>Assert</a>: <var>window</var>'s <a href=nav-history-apis.html#concept-document-window id=close-watcher-infrastructure:concept-document-window>associated <code>Document</code></a> is <a id=close-watcher-infrastructure:fully-active href=document-sequences.html#fully-active>fully active</a>.<li> <p>Let <var>closeWatcher</var> be a new <a href=#close-watcher id=close-watcher-infrastructure:close-watcher-5>close watcher</a>, with</p> <dl class=props><dt><a href=#close-watcher-window id=close-watcher-infrastructure:close-watcher-window-2>window</a><dd><var>window</var><dt><a href=#close-watcher-cancel-action id=close-watcher-infrastructure:close-watcher-cancel-action>cancel action</a><dd><var>cancelAction</var><dt><a href=#close-watcher-close-action id=close-watcher-infrastructure:close-watcher-close-action-2>close action</a><dd><var>closeAction</var><dt><a href=#close-watcher-is-running-cancel id=close-watcher-infrastructure:close-watcher-is-running-cancel>is running cancel action</a><dd>false</dl> <li><p>Let <var>manager</var> be <var>window</var>'s <a href=#close-watcher-manager id=close-watcher-infrastructure:close-watcher-manager-4>close watcher manager</a>.<li><p>If <var>manager</var>'s <a href=#close-watcher-manager-groups id=close-watcher-infrastructure:close-watcher-manager-groups>groups</a>'s <a href=https://infra.spec.whatwg.org/#list-size id=close-watcher-infrastructure:list-size data-x-internal=list-size>size</a> is less than <var>manager</var>'s <a href=#close-watcher-manager-allowed-number-of-groups id=close-watcher-infrastructure:close-watcher-manager-allowed-number-of-groups-3>allowed number of groups</a>, then <a href=https://infra.spec.whatwg.org/#list-append id=close-watcher-infrastructure:list-append data-x-internal=list-append>append</a> « <var>closeWatcher</var> » to <var>manager</var>'s <a href=#close-watcher-manager-groups id=close-watcher-infrastructure:close-watcher-manager-groups-2>groups</a>.<li> <p>Otherwise:</p> <ol><li><p><a id=close-watcher-infrastructure:assert-2 href=https://infra.spec.whatwg.org/#assert data-x-internal=assert>Assert</a>: <var>manager</var>'s <a href=#close-watcher-manager-groups id=close-watcher-infrastructure:close-watcher-manager-groups-3>groups</a>'s <a href=https://infra.spec.whatwg.org/#list-size id=close-watcher-infrastructure:list-size-2 data-x-internal=list-size>size</a> is at least 1 in this branch, since <var>manager</var>'s <a href=#close-watcher-manager-allowed-number-of-groups id=close-watcher-infrastructure:close-watcher-manager-allowed-number-of-groups-4>allowed number of groups</a> is always at least 1.<li><p><a href=https://infra.spec.whatwg.org/#list-append id=close-watcher-infrastructure:list-append-2 data-x-internal=list-append>Append</a> <var>closeWatcher</var> to <var>manager</var>'s <a href=#close-watcher-manager-groups id=close-watcher-infrastructure:close-watcher-manager-groups-4>groups</a>'s last <a href=https://infra.spec.whatwg.org/#list-item id=close-watcher-infrastructure:list-item data-x-internal=list-item>item</a>.</ol> <li><p>Set <var>manager</var>'s <a href=#close-watcher-manager-next id=close-watcher-infrastructure:close-watcher-manager-next-4>next user interaction allows a new group</a> to true.<li><p>Return <var>closeWatcher</var>.</ol> <p>To <dfn id=close-watcher-request-close>request to close</dfn> a <a href=#close-watcher id=close-watcher-infrastructure:close-watcher-6>close watcher</a> <var>closeWatcher</var>:</p> <ol><li><p>If <var>closeWatcher</var> <a href=#close-watcher-active id=close-watcher-infrastructure:close-watcher-active>is not active</a>, then return true.<li><p>If <var>closeWatcher</var>'s <a href=#close-watcher-is-running-cancel id=close-watcher-infrastructure:close-watcher-is-running-cancel-2>is running cancel action</a> is true, then return true.<li><p>Let <var>window</var> be <var>closeWatcher</var>'s <a href=#close-watcher-window id=close-watcher-infrastructure:close-watcher-window-3>window</a>.<li><p>If <var>window</var>'s <a href=nav-history-apis.html#concept-document-window id=close-watcher-infrastructure:concept-document-window-2>associated <code>Document</code></a> is not <a id=close-watcher-infrastructure:fully-active-2 href=document-sequences.html#fully-active>fully active</a>, then return true.<li><p>Let <var>canPreventClose</var> be true if <var>window</var>'s <a href=#close-watcher-manager id=close-watcher-infrastructure:close-watcher-manager-5>close watcher manager</a>'s <a href=#close-watcher-manager-groups id=close-watcher-infrastructure:close-watcher-manager-groups-5>groups</a>'s <a href=https://infra.spec.whatwg.org/#list-size id=close-watcher-infrastructure:list-size-3 data-x-internal=list-size>size</a> is less than <var>window</var>'s <a href=#close-watcher-manager id=close-watcher-infrastructure:close-watcher-manager-6>close watcher manager</a>'s <a href=#close-watcher-manager-allowed-number-of-groups id=close-watcher-infrastructure:close-watcher-manager-allowed-number-of-groups-5>allowed number of groups</a>, and <var>window</var> has <a href=#history-action-activation id=close-watcher-infrastructure:history-action-activation-2>history-action activation</a>; otherwise false.<li><p>Set <var>closeWatcher</var>'s <a href=#close-watcher-is-running-cancel id=close-watcher-infrastructure:close-watcher-is-running-cancel-3>is running cancel action</a> to true.<li><p>Let <var>shouldContinue</var> be the result of running <var>closeWatcher</var>'s <a href=#close-watcher-cancel-action id=close-watcher-infrastructure:close-watcher-cancel-action-2>cancel action</a> given <var>canPreventClose</var>.<li><p>Set <var>closeWatcher</var>'s <a href=#close-watcher-is-running-cancel id=close-watcher-infrastructure:close-watcher-is-running-cancel-4>is running cancel action</a> to false.<li> <p>If <var>shouldContinue</var> is false, then:</p> <ol><li><p><a id=close-watcher-infrastructure:assert-3 href=https://infra.spec.whatwg.org/#assert data-x-internal=assert>Assert</a>: <var>canPreventClose</var> is true.<li><p><a href=#consume-history-action-user-activation id=close-watcher-infrastructure:consume-history-action-user-activation>Consume history-action user activation</a> given <var>window</var>.<li><p>Return false.</ol> <p class=note>Note that since these substeps <a href=#consume-history-action-user-activation id=close-watcher-infrastructure:consume-history-action-user-activation-2>consume history-action user activation</a>, <a href=#close-watcher-request-close id=close-watcher-infrastructure:close-watcher-request-close>requesting to close</a> a <a href=#close-watcher id=close-watcher-infrastructure:close-watcher-7>close watcher</a> twice without any intervening <a href=#tracking-user-activation id=close-watcher-infrastructure:tracking-user-activation-4>user activation</a> will result in <var>canPreventClose</var> being false the second time.</p> <li><p><a href=#close-watcher-close id=close-watcher-infrastructure:close-watcher-close>Close</a> <var>closeWatcher</var>.<li><p>Return true.</ol> <p>To <dfn id=close-watcher-close>close</dfn> a <a href=#close-watcher id=close-watcher-infrastructure:close-watcher-8>close watcher</a> <var>closeWatcher</var>:</p> <ol><li><p>If <var>closeWatcher</var> <a href=#close-watcher-active id=close-watcher-infrastructure:close-watcher-active-2>is not active</a>, then return.<li><p>If <var>closeWatcher</var>'s <a href=#close-watcher-window id=close-watcher-infrastructure:close-watcher-window-4>window</a>'s <a href=nav-history-apis.html#concept-document-window id=close-watcher-infrastructure:concept-document-window-3>associated <code>Document</code></a> is not <a id=close-watcher-infrastructure:fully-active-3 href=document-sequences.html#fully-active>fully active</a>, then return.<li><p><a href=#close-watcher-destroy id=close-watcher-infrastructure:close-watcher-destroy>Destroy</a> <var>closeWatcher</var>.<li><p>Run <var>closeWatcher</var>'s <a href=#close-watcher-close-action id=close-watcher-infrastructure:close-watcher-close-action-3>close action</a>.</ol> <p>To <dfn id=close-watcher-destroy>destroy</dfn> a <a href=#close-watcher id=close-watcher-infrastructure:close-watcher-9>close watcher</a> <var>closeWatcher</var>:</p> <ol><li><p>Let <var>manager</var> be <var>closeWatcher</var>'s <a href=#close-watcher-window id=close-watcher-infrastructure:close-watcher-window-5>window</a>'s <a href=#close-watcher-manager id=close-watcher-infrastructure:close-watcher-manager-7>close watcher manager</a>.<li><p><a href=https://infra.spec.whatwg.org/#list-iterate id=close-watcher-infrastructure:list-iterate data-x-internal=list-iterate>For each</a> <var>group</var> of <var>manager</var>'s <a href=#close-watcher-manager-groups id=close-watcher-infrastructure:close-watcher-manager-groups-6>groups</a>: <a href=https://infra.spec.whatwg.org/#list-remove id=close-watcher-infrastructure:list-remove data-x-internal=list-remove>remove</a> <var>closeWatcher</var> from <var>group</var>.<li><p><a href=https://infra.spec.whatwg.org/#list-remove id=close-watcher-infrastructure:list-remove-2 data-x-internal=list-remove>Remove</a> any item from <var>manager</var>'s <a href=#close-watcher-manager-groups id=close-watcher-infrastructure:close-watcher-manager-groups-7>groups</a> that <a href=https://infra.spec.whatwg.org/#list-is-empty id=close-watcher-infrastructure:list-is-empty data-x-internal=list-is-empty>is empty</a>.</ol> <hr> <p>To <dfn id=process-close-watchers>process close watchers</dfn> given a <code id=close-watcher-infrastructure:window-5><a href=nav-history-apis.html#window>Window</a></code> <var>window</var>:</p> <ol><li><p>Let <var>processedACloseWatcher</var> be false.<li> <p>If <var>window</var>'s <a href=#close-watcher-manager id=close-watcher-infrastructure:close-watcher-manager-8>close watcher manager</a>'s <a href=#close-watcher-manager-groups id=close-watcher-infrastructure:close-watcher-manager-groups-8>groups</a> is not empty:</p> <ol><li><p>Let <var>group</var> be the last <a href=https://infra.spec.whatwg.org/#list-item id=close-watcher-infrastructure:list-item-2 data-x-internal=list-item>item</a> in <var>window</var>'s <a href=#close-watcher-manager id=close-watcher-infrastructure:close-watcher-manager-9>close watcher manager</a>'s <a href=#close-watcher-manager-groups id=close-watcher-infrastructure:close-watcher-manager-groups-9>groups</a>.<li> <p><a href=https://infra.spec.whatwg.org/#list-iterate id=close-watcher-infrastructure:list-iterate-2 data-x-internal=list-iterate>For each</a> <var>closeWatcher</var> of <var>group</var>, in reverse order:</p> <ol><li><p>Set <var>processedACloseWatcher</var> to true.<li><p>Let <var>shouldProceed</var> be the result of <a href=#close-watcher-request-close id=close-watcher-infrastructure:close-watcher-request-close-2>requesting to close</a> <var>closeWatcher</var>.<li><p>If <var>shouldProceed</var> is false, then <a id=close-watcher-infrastructure:break href=https://infra.spec.whatwg.org/#iteration-break data-x-internal=break>break</a>.</ol> </ol> <li><p>If <var>window</var>'s <a href=#close-watcher-manager id=close-watcher-infrastructure:close-watcher-manager-10>close watcher manager</a>'s <a href=#close-watcher-manager-allowed-number-of-groups id=close-watcher-infrastructure:close-watcher-manager-allowed-number-of-groups-6>allowed number of groups</a> is greater than 1, decrement it by 1.<li><p>Return <var>processedACloseWatcher</var>.</ol> <h4 id=the-closewatcher-interface><span class=secno>6.10.3</span> The <code id=the-closewatcher-interface:closewatcher><a href=#closewatcher>CloseWatcher</a></code> interface<a href=#the-closewatcher-interface class=self-link></a></h4> <pre><code class='idl'>[<c- g>Exposed</c->=<c- n>Window</c->] <c- b>interface</c-> <dfn id='closewatcher' data-dfn-type='interface'><c- g>CloseWatcher</c-></dfn> : <a id='the-closewatcher-interface:eventtarget' href='https://dom.spec.whatwg.org/#interface-eventtarget' data-x-internal='eventtarget'><c- n>EventTarget</c-></a> { <a href='#dom-closewatcher' id='the-closewatcher-interface:dom-closewatcher'><c- g>constructor</c-></a>(<c- b>optional</c-> <a href='#closewatcheroptions' id='the-closewatcher-interface:closewatcheroptions'><c- n>CloseWatcherOptions</c-></a> <c- g>options</c-> = {}); <c- b>undefined</c-> <a href='#dom-closewatcher-requestclose' id='the-closewatcher-interface:dom-closewatcher-requestclose'><c- g>requestClose</c-></a>(); <c- b>undefined</c-> <a href='#dom-closewatcher-close' id='the-closewatcher-interface:dom-closewatcher-close'><c- g>close</c-></a>(); <c- b>undefined</c-> <a href='#dom-closewatcher-destroy' id='the-closewatcher-interface:dom-closewatcher-destroy'><c- g>destroy</c-></a>(); <c- b>attribute</c-> <a id='the-closewatcher-interface:eventhandler' href='webappapis.html#eventhandler'><c- n>EventHandler</c-></a> <a href='#handler-closewatcher-oncancel' id='the-closewatcher-interface:handler-closewatcher-oncancel'><c- g>oncancel</c-></a>; <c- b>attribute</c-> <a id='the-closewatcher-interface:eventhandler-2' href='webappapis.html#eventhandler'><c- n>EventHandler</c-></a> <a href='#handler-closewatcher-oncancel' id='the-closewatcher-interface:handler-closewatcher-oncancel-2'><c- g>onclose</c-></a>; }; <c- b>dictionary</c-> <dfn id='closewatcheroptions' data-dfn-type='dictionary'><c- g>CloseWatcherOptions</c-></dfn> { <a id='the-closewatcher-interface:abortsignal' href='https://dom.spec.whatwg.org/#abortsignal' data-x-internal='abortsignal'><c- n>AbortSignal</c-></a> <dfn data-dfn-for='CloseWatcherOptions' id='dom-closewatcheroptions-signal' data-dfn-type='dict-member'><c- g>signal</c-></dfn>; };</code></pre> <dl class=domintro><dt><code><var>watcher</var> = new <a href=#dom-closewatcher id=dom-closewatcher-dev>CloseWatcher</a>()</code><dt><code><var>watcher</var> = new <a href=#dom-closewatcher id=the-closewatcher-interface:dom-closewatcher-2>CloseWatcher</a>({ <a href=#dom-closewatcheroptions-signal id=dom-closewatcheroptions-signal-dev>signal</a> })</code><dd> <p>Creates a new <code id=the-closewatcher-interface:closewatcher-2><a href=#closewatcher>CloseWatcher</a></code> instance.</p> <p>If the <code id=the-closewatcher-interface:dom-closewatcheroptions-signal><a href=#dom-closewatcheroptions-signal>signal</a></code> option is provided, then <var>watcher</var> can be destroyed (as if by <code id=the-closewatcher-interface:dom-closewatcher-destroy-2><a href=#dom-closewatcher-destroy>watcher.destroy()</a></code>) by aborting the given <code id=the-closewatcher-interface:abortsignal-2><a data-x-internal=abortsignal href=https://dom.spec.whatwg.org/#abortsignal>AbortSignal</a></code>.</p> <p>If any <a href=#close-watcher id=the-closewatcher-interface:close-watcher>close watcher</a> is already active, and the <code id=the-closewatcher-interface:window><a href=nav-history-apis.html#window>Window</a></code> does not have <a href=#history-action-activation id=the-closewatcher-interface:history-action-activation>history-action activation</a>, then the resulting <code id=the-closewatcher-interface:closewatcher-3><a href=#closewatcher>CloseWatcher</a></code> will be closed together with that already-active <a href=#close-watcher id=the-closewatcher-interface:close-watcher-2>close watcher</a> in response to any <a href=#close-request id=the-closewatcher-interface:close-request>close request</a>. (This already-active <a href=#close-watcher id=the-closewatcher-interface:close-watcher-3>close watcher</a> does not necessarily have to be a <code id=the-closewatcher-interface:closewatcher-4><a href=#closewatcher>CloseWatcher</a></code> object; it could be a modal <code id=the-closewatcher-interface:the-dialog-element><a href=interactive-elements.html#the-dialog-element>dialog</a></code> element, or a popover generated by an element with the <code id=the-closewatcher-interface:attr-popover><a href=popover.html#attr-popover>popover</a></code> attribute.)</p> <dt><code><var>watcher</var>.<a href=#dom-closewatcher-requestclose id=dom-closewatcher-requestclose-dev>requestClose</a>()</code><dd> <p>Acts as if a <a href=#close-request id=the-closewatcher-interface:close-request-2>close request</a> was sent targeting <var>watcher</var>, by first firing a <code id=the-closewatcher-interface:event-cancel><a href=indices.html#event-cancel>cancel</a></code> event, and if that event is not canceled with <code id=the-closewatcher-interface:dom-event-preventdefault><a data-x-internal=dom-event-preventdefault href=https://dom.spec.whatwg.org/#dom-event-preventdefault>preventDefault()</a></code>, proceeding to fire a <code id=the-closewatcher-interface:event-close><a href=indices.html#event-close>close</a></code> event before deactivating the close watcher as if <code id=the-closewatcher-interface:dom-closewatcher-destroy-3><a href=#dom-closewatcher-destroy>watcher.destroy()</a></code> was called.</p> <p>This is a helper utility that can be used to consolidate cancelation and closing logic into the <code id=the-closewatcher-interface:event-cancel-2><a href=indices.html#event-cancel>cancel</a></code> and <code id=the-closewatcher-interface:event-close-2><a href=indices.html#event-close>close</a></code> event handlers, by having all non-<a href=#close-request id=the-closewatcher-interface:close-request-3>close request</a> closing affordances call this method.</p> <dt><code><var>watcher</var>.<a href=#dom-closewatcher-close id=dom-closewatcher-close-dev>close</a>()</code><dd> <p>Immediately fires the <code id=the-closewatcher-interface:event-close-3><a href=indices.html#event-close>close</a></code> event, and then deactivates the close watcher as if <code id=the-closewatcher-interface:dom-closewatcher-destroy-4><a href=#dom-closewatcher-destroy>watcher.destroy()</a></code> was called.</p> <p>This is a helper utility that can be used trigger the closing logic into the <code id=the-closewatcher-interface:event-close-4><a href=indices.html#event-close>close</a></code> event handler, skipping any logic in the <code id=the-closewatcher-interface:event-cancel-3><a href=indices.html#event-cancel>cancel</a></code> event handler.</p> <dt><code><var>watcher</var>.<a href=#dom-closewatcher-destroy id=dom-closewatcher-destroy-dev>destroy</a>()</code><dd> <p>Deactivates <var>watcher</var>, so that it will no longer receive <code id=the-closewatcher-interface:event-close-5><a href=indices.html#event-close>close</a></code> events and so that new independent <code id=the-closewatcher-interface:closewatcher-5><a href=#closewatcher>CloseWatcher</a></code> instances can be constructed.</p> <p>This is intended to be called if the relevant UI element is torn down in some other way than being closed.</p> </dl> <p>Each <code id=the-closewatcher-interface:closewatcher-6><a href=#closewatcher>CloseWatcher</a></code> instance has an <dfn id=internal-close-watcher>internal close watcher</dfn>, which is a <a href=#close-watcher id=the-closewatcher-interface:close-watcher-4>close watcher</a>.</p> <p>The <dfn id=dom-closewatcher><code>new CloseWatcher(<var>options</var>)</code></dfn> constructor steps are:</p> <ol><li><p>If <a id=the-closewatcher-interface:this href=https://webidl.spec.whatwg.org/#this data-x-internal=this>this</a>'s <a id=the-closewatcher-interface:concept-relevant-global href=webappapis.html#concept-relevant-global>relevant global object</a>'s <a href=nav-history-apis.html#concept-document-window id=the-closewatcher-interface:concept-document-window>associated <code>Document</code></a> is not <a id=the-closewatcher-interface:fully-active href=document-sequences.html#fully-active>fully active</a>, then throw an <a id=the-closewatcher-interface:invalidstateerror href=https://webidl.spec.whatwg.org/#invalidstateerror data-x-internal=invalidstateerror>"<code>InvalidStateError</code>"</a> <code id=the-closewatcher-interface:domexception><a data-x-internal=domexception href=https://webidl.spec.whatwg.org/#dfn-DOMException>DOMException</a></code>.<li> <p>Let <var>closeWatcher</var> be the result of <a href=#establish-a-close-watcher id=the-closewatcher-interface:establish-a-close-watcher>establishing a close watcher</a> given <a id=the-closewatcher-interface:this-2 href=https://webidl.spec.whatwg.org/#this data-x-internal=this>this</a>'s <a id=the-closewatcher-interface:concept-relevant-global-2 href=webappapis.html#concept-relevant-global>relevant global object</a>, with:</p> <ul><li><p><i id=the-closewatcher-interface:create-close-watcher-cancelaction><a href=#create-close-watcher-cancelaction>cancelAction</a></i> given <var>canPreventClose</var> being to return the result of <a href=https://dom.spec.whatwg.org/#concept-event-fire id=the-closewatcher-interface:concept-event-fire data-x-internal=concept-event-fire>firing an event</a> named <code id=the-closewatcher-interface:event-cancel-4><a href=indices.html#event-cancel>cancel</a></code> at <a id=the-closewatcher-interface:this-3 href=https://webidl.spec.whatwg.org/#this data-x-internal=this>this</a>, with the <code id=the-closewatcher-interface:dom-event-cancelable><a data-x-internal=dom-event-cancelable href=https://dom.spec.whatwg.org/#dom-event-cancelable>cancelable</a></code> attribute initialized to <var>canPreventClose</var>.<li><p><i id=the-closewatcher-interface:create-close-watcher-closeaction><a href=#create-close-watcher-closeaction>closeAction</a></i> being to <a href=https://dom.spec.whatwg.org/#concept-event-fire id=the-closewatcher-interface:concept-event-fire-2 data-x-internal=concept-event-fire>fire an event</a> named <code id=the-closewatcher-interface:event-close-6><a href=indices.html#event-close>close</a></code> at <a id=the-closewatcher-interface:this-4 href=https://webidl.spec.whatwg.org/#this data-x-internal=this>this</a>.</ul> <li> <p>If <var>options</var>["<code id=the-closewatcher-interface:dom-closewatcheroptions-signal-2><a href=#dom-closewatcheroptions-signal>signal</a></code>"] <a href=https://infra.spec.whatwg.org/#map-exists id=the-closewatcher-interface:map-exists data-x-internal=map-exists>exists</a>, then:</p> <ol><li><p>If <var>options</var>["<code id=the-closewatcher-interface:dom-closewatcheroptions-signal-3><a href=#dom-closewatcheroptions-signal>signal</a></code>"] is <a href=https://dom.spec.whatwg.org/#abortsignal-aborted id=the-closewatcher-interface:abortsignal-aborted data-x-internal=abortsignal-aborted>aborted</a>, then <a href=#close-watcher-destroy id=the-closewatcher-interface:close-watcher-destroy>destroy</a> <var>closeWatcher</var>.<li> <p><a href=https://dom.spec.whatwg.org/#abortsignal-add id=the-closewatcher-interface:abortsignal-add data-x-internal=abortsignal-add>Add</a> the following steps to <var>options</var>["<code id=the-closewatcher-interface:dom-closewatcheroptions-signal-4><a href=#dom-closewatcheroptions-signal>signal</a></code>"]:</p> <ol><li><p><a href=#close-watcher-destroy id=the-closewatcher-interface:close-watcher-destroy-2>Destroy</a> <var>closeWatcher</var>.</ol> </ol> <li><p>Set <a id=the-closewatcher-interface:this-5 href=https://webidl.spec.whatwg.org/#this data-x-internal=this>this</a>'s <a href=#internal-close-watcher id=the-closewatcher-interface:internal-close-watcher>internal close watcher</a> to <var>closeWatcher</var>.</ol> <p>The <dfn data-dfn-for=CloseWatcher id=dom-closewatcher-requestclose data-dfn-type=method><code>requestClose()</code></dfn> method steps are to <a href=#close-watcher-request-close id=the-closewatcher-interface:close-watcher-request-close>request to close</a> <a id=the-closewatcher-interface:this-6 href=https://webidl.spec.whatwg.org/#this data-x-internal=this>this</a>'s <a href=#internal-close-watcher id=the-closewatcher-interface:internal-close-watcher-2>internal close watcher</a>.</p> <p>The <dfn data-dfn-for=CloseWatcher id=dom-closewatcher-close data-dfn-type=method><code>close()</code></dfn> method steps are to <a href=#close-watcher-close id=the-closewatcher-interface:close-watcher-close>close</a> <a id=the-closewatcher-interface:this-7 href=https://webidl.spec.whatwg.org/#this data-x-internal=this>this</a>'s <a href=#internal-close-watcher id=the-closewatcher-interface:internal-close-watcher-3>internal close watcher</a>.</p> <p>The <dfn data-dfn-for=CloseWatcher id=dom-closewatcher-destroy data-dfn-type=method><code>destroy()</code></dfn> method steps are to <a href=#close-watcher-destroy id=the-closewatcher-interface:close-watcher-destroy-3>destroy</a> <a id=the-closewatcher-interface:this-8 href=https://webidl.spec.whatwg.org/#this data-x-internal=this>this</a>'s <a href=#internal-close-watcher id=the-closewatcher-interface:internal-close-watcher-4>internal close watcher</a>.</p> <p>The following are the <a id=the-closewatcher-interface:event-handlers href=webappapis.html#event-handlers>event handlers</a> (and their corresponding <a href=webappapis.html#event-handler-event-type id=the-closewatcher-interface:event-handler-event-type>event handler event types</a>) that must be supported, as <a id=the-closewatcher-interface:event-handler-idl-attributes href=webappapis.html#event-handler-idl-attributes>event handler IDL attributes</a>, by all objects implementing the <code id=the-closewatcher-interface:closewatcher-7><a href=#closewatcher>CloseWatcher</a></code> interface:</p> <table><thead><tr><th><a href=webappapis.html#event-handlers id=the-closewatcher-interface:event-handlers-2>Event handler</a> <th><a id=the-closewatcher-interface:event-handler-event-type-2 href=webappapis.html#event-handler-event-type>Event handler event type</a> <tbody><tr><td><dfn data-dfn-for=CloseWatcher id=handler-closewatcher-oncancel data-dfn-type=attribute><code>oncancel</code></dfn> <td> <code id=the-closewatcher-interface:event-cancel-5><a href=indices.html#event-cancel>cancel</a></code> <tr><td><dfn data-dfn-for=CloseWatcher id=handler-closewatcher-onclose data-dfn-type=attribute><code>onclose</code></dfn> <td> <code id=the-closewatcher-interface:event-close-7><a href=indices.html#event-close>close</a></code> </table> <div id=example-CloseWatcher-basic class=example> <p>If one wanted to implement a custom picker control, which closed itself on a user-provided <a href=#close-request id=the-closewatcher-interface:close-request-4>close request</a> as well as when a close button is pressed, the following code shows how one would use the <code id=the-closewatcher-interface:closewatcher-8><a href=#closewatcher>CloseWatcher</a></code> API to process close requests:</p> <pre><code class='js'><c- a>const</c-> watcher <c- o>=</c-> <c- k>new</c-> CloseWatcher<c- p>();</c-> <c- a>const</c-> picker <c- o>=</c-> setUpAndShowPickerDOMElement<c- p>();</c-> <c- a>let</c-> chosenValue <c- o>=</c-> <c- kc>null</c-><c- p>;</c-> watcher<c- p>.</c->onclose <c- o>=</c-> <c- p>()</c-> <c- p>=&gt;</c-> <c- p>{</c-> chosenValue <c- o>=</c-> picker<c- p>.</c->querySelector<c- p>(</c-><c- t>&apos;input&apos;</c-><c- p>).</c->value<c- p>;</c-> picker<c- p>.</c->remove<c- p>();</c-> <c- p>};</c-> picker<c- p>.</c->querySelector<c- p>(</c-><c- t>&apos;.close-button&apos;</c-><c- p>).</c->onclick <c- o>=</c-> <c- p>()</c-> <c- p>=&gt;</c-> watcher<c- p>.</c->requestClose<c- p>();</c-></code></pre> <p>Note how the logic to gather the chosen value is centralized in the <code id=the-closewatcher-interface:closewatcher-9><a href=#closewatcher>CloseWatcher</a></code> object's <code id=the-closewatcher-interface:event-close-8><a href=indices.html#event-close>close</a></code> event handler, with the <code id=the-closewatcher-interface:event-click><a data-x-internal=event-click href=https://w3c.github.io/uievents/#event-type-click>click</a></code> event handler for the close button delegating to that logic by calling <code id=the-closewatcher-interface:dom-closewatcher-requestclose-2><a href=#dom-closewatcher-requestclose>requestClose()</a></code>.</p> </div> <div id=example-CloseWatcher-cancel class=example> <p>The <code id=the-closewatcher-interface:event-cancel-6><a href=indices.html#event-cancel>cancel</a></code> event on <code id=the-closewatcher-interface:closewatcher-10><a href=#closewatcher>CloseWatcher</a></code> objects can be used to prevent the <code id=the-closewatcher-interface:event-close-9><a href=indices.html#event-close>close</a></code> event from firing, and the <code id=the-closewatcher-interface:closewatcher-11><a href=#closewatcher>CloseWatcher</a></code> from being destroying. A typical use case is as follows:</p> <pre><code class='js'>watcher<c- p>.</c->oncancel <c- o>=</c-> <c- k>async</c-> <c- p>(</c->e<c- p>)</c-> <c- p>=&gt;</c-> <c- p>{</c-> <c- k>if</c-> <c- p>(</c->hasUnsavedData <c- o>&amp;&amp;</c-> e<c- p>.</c->cancelable<c- p>)</c-> <c- p>{</c-> e<c- p>.</c->preventDefault<c- p>();</c-> <c- a>const</c-> userReallyWantsToClose <c- o>=</c-> <c- k>await</c-> askForConfirmation<c- p>(</c-><c- u>&quot;Are you sure you want to close?&quot;</c-><c- p>);</c-> <c- k>if</c-> <c- p>(</c->userReallyWantsToClose<c- p>)</c-> <c- p>{</c-> hasUnsavedData <c- o>=</c-> <c- kc>false</c-><c- p>;</c-> watcher<c- p>.</c->close<c- p>();</c-> <c- p>}</c-> <c- p>}</c-> <c- p>};</c-></code></pre> <p>For abuse prevention purposes, this event is only <code id=the-closewatcher-interface:dom-event-cancelable-2><a data-x-internal=dom-event-cancelable href=https://dom.spec.whatwg.org/#dom-event-cancelable>cancelable</a></code> if the page has <a href=#history-action-activation id=the-closewatcher-interface:history-action-activation-2>history-action activation</a>, which will be lost after any given <a href=#close-request id=the-closewatcher-interface:close-request-5>close request</a>. This ensures that if the user sends a close request twice in a row without any intervening user activation, the request definitely succeeds; the second request ignores any <code id=the-closewatcher-interface:event-cancel-7><a href=indices.html#event-cancel>cancel</a></code> event handler's attempt to call <code id=the-closewatcher-interface:dom-event-preventdefault-2><a data-x-internal=dom-event-preventdefault href=https://dom.spec.whatwg.org/#dom-event-preventdefault>preventDefault()</a></code> and proceeds to close the <code id=the-closewatcher-interface:closewatcher-12><a href=#closewatcher>CloseWatcher</a></code>.</p> </div> <p>Combined, the above two examples show how <code id=the-closewatcher-interface:dom-closewatcher-requestclose-3><a href=#dom-closewatcher-requestclose>requestClose()</a></code> and <code id=the-closewatcher-interface:dom-closewatcher-close-2><a href=#dom-closewatcher-close>close()</a></code> differ. Because we used <code id=the-closewatcher-interface:dom-closewatcher-requestclose-4><a href=#dom-closewatcher-requestclose>requestClose()</a></code> in the <code id=the-closewatcher-interface:event-click-2><a data-x-internal=event-click href=https://w3c.github.io/uievents/#event-type-click>click</a></code> event handler for the close button, clicking that button will trigger the <code id=the-closewatcher-interface:closewatcher-13><a href=#closewatcher>CloseWatcher</a></code>'s <code id=the-closewatcher-interface:event-cancel-8><a href=indices.html#event-cancel>cancel</a></code> event, and thus potentially ask the user for confirmation if there is unsaved data. If we had used <code id=the-closewatcher-interface:dom-closewatcher-close-3><a href=#dom-closewatcher-close>close()</a></code>, then this check would be skipped. Sometimes that is appropriate, but usually <code id=the-closewatcher-interface:dom-closewatcher-requestclose-5><a href=#dom-closewatcher-requestclose>requestClose()</a></code> is the better option for user-triggered close requests.</p> <div id=example-CloseWatcher-grouping class=example> <p>In addition to the <a href=#tracking-user-activation id=the-closewatcher-interface:tracking-user-activation>user activation</a> restrictions for <code id=the-closewatcher-interface:event-cancel-9><a href=indices.html#event-cancel>cancel</a></code> events, there is a more subtle form of user activation gating for <code id=the-closewatcher-interface:closewatcher-14><a href=#closewatcher>CloseWatcher</a></code> construction. If one creates more than one <code id=the-closewatcher-interface:closewatcher-15><a href=#closewatcher>CloseWatcher</a></code> without user activation, then the newly-created one will get grouped together with the most-recently-created <a href=#close-watcher id=the-closewatcher-interface:close-watcher-5>close watcher</a>, so that a single <a href=#close-request id=the-closewatcher-interface:close-request-6>close request</a> will close them both:</p> <pre><code class='js'>window<c- p>.</c->onload <c- o>=</c-> <c- p>()</c-> <c- p>=&gt;</c-> <c- p>{</c-> <c- c1>// This will work as normal: it is the first close watcher created without user activation.</c-> <c- p>(</c-><c- k>new</c-> CloseWatcher<c- p>()).</c->onclose <c- o>=</c-> <c- p>()</c-> <c- p>=&gt;</c-> <c- p>{</c-> <c- d>/* ... */</c-> <c- p>};</c-> <c- p>};</c-> button1<c- p>.</c->onclick <c- o>=</c-> <c- p>()</c-> <c- p>=&gt;</c-> <c- p>{</c-> <c- c1>// This will work as normal: the button click counts as user activation.</c-> <c- p>(</c-><c- k>new</c-> CloseWatcher<c- p>()).</c->onclose <c- o>=</c-> <c- p>()</c-> <c- p>=&gt;</c-> <c- p>{</c-> <c- d>/* ... */</c-> <c- p>};</c-> <c- p>};</c-> button2<c- p>.</c->onclick <c- o>=</c-> <c- p>()</c-> <c- p>=&gt;</c-> <c- p>{</c-> <c- c1>// These will be grouped together, and both will close in response to a single close request.</c-> <c- p>(</c-><c- k>new</c-> CloseWatcher<c- p>()).</c->onclose <c- o>=</c-> <c- p>()</c-> <c- p>=&gt;</c-> <c- p>{</c-> <c- d>/* ... */</c-> <c- p>};</c-> <c- p>(</c-><c- k>new</c-> CloseWatcher<c- p>()).</c->onclose <c- o>=</c-> <c- p>()</c-> <c- p>=&gt;</c-> <c- p>{</c-> <c- d>/* ... */</c-> <c- p>};</c-> <c- p>};</c-></code></pre> <p>This means that calling <code id=the-closewatcher-interface:dom-closewatcher-destroy-5><a href=#dom-closewatcher-destroy>destroy()</a></code>, <code id=the-closewatcher-interface:dom-closewatcher-close-4><a href=#dom-closewatcher-close>close()</a></code>, or <code id=the-closewatcher-interface:dom-closewatcher-requestclose-6><a href=#dom-closewatcher-requestclose>requestClose()</a></code> properly is important. Doing so is the only way to get back the "free" ungrouped close watcher slot. Such close watchers created without user activation are useful for cases like session inactivity timeout dialogs or urgent notifications of server-triggered events, which are not generated in response to user activation.</p> </div> <nav><a href=microdata.html>← 5 Microdata</a> — <a href=./>Table of Contents</a> — <a href=dnd.html>6.11 Drag and drop →</a></nav>

Pages: 1 2 3 4 5 6 7 8 9 10