A tabindex value of zeroĪ tabindex equals to exactly zero will place the element in the default focus order, determined by its position in the source HTML. Therefore, for readability and consistency, it is best to stick with -1. Since any negative value will remove the element from focus, there is no difference if the value is -1 or -99999. The exact negative value chosen doesn’t actually matter. Click me to start, then press the "tab" keyĬlick me to start, then press the "tab" key A user navigating the page using a keyboard will not be able to access the element at all. Negative tabindex valuesĪ negative tabindex, for example -1, will omit the element from the focus order entirely. The value of the attribute must be a valid integer and can either be negative, positive, or exactly zero. The tabindex attribute can be applied to almost any element, whether it is by default focusable or not. This is where the tabindex attribute becomes handy. The order in which these elements are placed in the source HTML document controls the order in which they become focusable when navigating with a keyboard.Īlthough this default behaviour covers most of the interaction we would need, there may be cases where we want to remove, add, or re-arrange items in the focus order.
Without any intervention, calling focus() on any other element simply will not work. There are six 1 HTML elements which, by default, are focusable:īy default, only these elements can be brought into focus either with a user tabbing around the page with a keyboard or via the focus() method in Javascript. To understand how the tabindex attribute works, we first need to understand how focus is controlled on a page.