The neighbourhood head calls the Tab queue numbers on your page: the browser answers each candidate’s tabIndex and focus(), find out when a positive tabindex…
Why it matters
A scrambled Tab order leaves keyboard and screen reader users lost. A positive tabindex (often added "so it gets focus first") does the damage. Knowing 0, -1 and positive apart = custom widgets people can reach and focus management done right.
The key idea
Only 0 and -1 are safe; a positive one always jumps ahead
Common mistakes
A positive tabindex "so it gets focus first" That element jumps ahead of the whole page and breaks the keyboard order. Use only 0 or -1; if the order is wrong, move the element in the HTML.
tabindex="0" on a button or an a href They take focus naturally, so it is redundant. tabindex="0" is only for a non-interactive element made a widget, e.g. div role="button".
Forgetting a non-interactive element cannot take focus at all A div, a p or an <a> without href refuses focus() until it gets a tabindex. For a programmatic .focus() use -1.
Try it in this playground
Click the board, then press Tab a few times The log under the code records where focus lands, and whether the browser agrees with the queue numbers.
Open Positive tabindex and Tab from the top of the board Sandi (tabindex 1) is called first, though it sits in the middle.
Call .focus() on an element with tabindex="-1" Open An error message, add tabindex="-1" to its paragraph, then press the .focus() button in the table.
Look at an <a> without href in the tableel.tabIndex 0, yet focus() is refused: without href it is no link.