--- url: "https://webaim.org/discussion/mail_message?id=50716" titulek: "WebAIM: E-mail List Archives" h1: "E-mail List Archives" popis: "" jazyk: "en" kanonicka: "" drobecky: ["You are here:", "Home", "Community", "E-mail List Archives"] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-15 14:45:18" znaku: 4188 slov: 654 kodovani: "utf-8" sha256: "a41d4f28664852f7b8093d842f1e657237e245eba4b45911777b78c7933e853a" --- # E-mail List Archives You are here: [Home](/) > [Community](/community/) > [E-mail List Archives](/discussion/archives) > View Message **From:** Birkir R. Gunnarsson **Date:** Feb 23, 2025 6:34PM - **Next message:** [Mark Magennis: "Re: Is it no longer necessary to use tabindex="-1" to allow JavaScript focus movement?"](mail_message?id=50717) - **Previous message:** [jp Jamous: "Re: Is it no longer necessary to use tabindex="-1" to allow JavaScript focus movement?"](mail_message?id=50715) - **Next message in Thread:** [Mark Magennis: "Re: Is it no longer necessary to use tabindex="-1" to allow JavaScript focus movement?"](mail_message?id=50717) - **Previous message in Thread:** [jp Jamous: "Re: Is it no longer necessary to use tabindex="-1" to allow JavaScript focus movement?"](mail_message?id=50715) - [View all messages in this Thread](mail_thread?thread=11184) --- I was playing with the autofocus attribute, both on page load and when using HTML . In order to use the autofocus attribute on non-focusable elements ((such as the main element or the heading) you have to add tabindex="-1", else it doesn't work. So, based on the replies to this thread I'd say, yes, you still need tabindex="-1" on a non-focusable element if you want to send focus to it via Javascript, link or the autofocus attribute. On Sun, Feb 23, 2025 at 12:24 PM jp Jamous via WebAIM-Forum < > wrote: > Where did you hear that? > > Based on object oriented programming logic, an object must have a tabindex > in order for the browser to set the keyboard focus on it. What I mean is > that a non-focusable item would not obtain keyboard focus unless you > indicate to the browser that it should. If you use the value of 0, that > would cause the visible focus indicator to show. However, a value of -1 > would set the keyboard focus on that element as a starting point if you > will. In other words, the browser informs the keyboard that from this > tabindex="-1" jump to the next item in the tab order based on the tab order > array in the browser. > > If you set the focus on a non-focusable element using JS without > tabindex="-1", different screen readers might function differently. NVDA > might start from that non-element in the accessibility tree. Whereas, JAWS > might not honor that. Having tabindex="-1" would be honored by most if not > all Assistive Technologies including standard keyboard movement. > > I recently worked on a site where
had an ID but the "Skip to Main > Content" link would not set focus on it. It would fire a page refresh and > keep the screen reader cursor at the top of the DOM. Only TabIndex="-1" > allowed it to work. > > In another recent job, the same tag was obtaining focus using a JS > function. JS was not setting focus on the
tag, because it was not in > the tabindex array, since it is a non-focusable item. Only tabindex="-1" > allowed the JS function to work. > > I am not claiming that it may not work without tabindex. It depends on > what type of JS framework being used and whether the page is a part of a > SPA project. My claim above only represents standard HTML and JS. It does > not include any JS frameworks like React, JQuery, AJAX and many others. > Those might have different functionality to achieve the focusability on a > non-focusable item. You would need to understand what is happening behind > the scenes when the framework executes its functions and methods. --- - **Next message:** [Mark Magennis: "Re: Is it no longer necessary to use tabindex="-1" to allow JavaScript focus movement?"](mail_message?id=50717) - **Previous message:** [jp Jamous: "Re: Is it no longer necessary to use tabindex="-1" to allow JavaScript focus movement?"](mail_message?id=50715) - **Next message in Thread:** [Mark Magennis: "Re: Is it no longer necessary to use tabindex="-1" to allow JavaScript focus movement?"](mail_message?id=50717) - **Previous message in Thread:** [jp Jamous: "Re: Is it no longer necessary to use tabindex="-1" to allow JavaScript focus movement?"](mail_message?id=50715) - [View all messages in this Thread](mail_thread?thread=11184&id=50716#50716)