Focus and Tabbing Order in HTML
Table of Content:
What is focus
When a web page featuring several links or several form controls loads, you may have noticed that you are able to use your Tab key to move between those elements (or Shift+Tab to move backward through elements). As you move between them, the web browser tends to add some type of border or highlighting to that element (be it a link or a form control). This is known as focus .
If you want to control the order in which elements can gain focus, you can use the tabindex
attribute to
give that element a number between 0 and 32767, which becomes part of the tabbing order. Every time
the user presses the Tab key, the focus moves to the element with the next highest tabbing order (and
again, Shift+Tab moves focus in reverse order).
The following elements can carry a tabindex
attribute:
In this example, the checkboxes receive focus in the following order: 4, 8, 1, 3, 10, 6, 2, 9, 5, 7
Elements that could gain focus but do not have a tabindex
attribute are automatically given a value
of 0 ; therefore, when you specify a tabindex value, it should be 1 or higher, rather than 0 .
If two elements have the same value for a tabindex attribute, they will be navigated in the order in which they appear in the document.