tabindex is used to define a
sequence that users follow when they use the Tab key to navigate through a
page. By default, the natural tabbing order will match the source order in
the markup. In certain circumstances it may be necessary to override the
default tabbing order, but it’s strongly recommended that you craft a page
in a logical flow and let the browser work through it in the default
order—an approach that negates the need for the
tabindex can start at 0 and
increment in any value. As such, the sequence 1, 2, 3, 4, 5 would be fine,
as would 10, 20, 30, 40, 50. If you need to introduce a
tabindex, it’s advisable to use a sequence that
contains intervals (like the second example provided), as this will give
you the opportunity to inject other controls later if need be (for
example, 10, 15, 20) without having to reindex all the
tabindex values on the page. Should a given
tabindex value be applied to more than one element
(e.g. all links in one section given a
"1", and sidebar links given a
"2"), the tabbing
order of those affected elements will be as per the source markup order.
Many people will choose to use this approach rather than a sequence with a
defined interval, such as 5, 10, 15, because it allows for additional
links or form controls to be added without the headache of re-numbering.
If a tabindex of
"-1" is used, the element it’s applied
to will no longer be keyboard focusable.
tabindex is set anywhere on a
page—even if it’s the hundredth link or the fiftieth form control—the tab
order will start at the element with the lowest
tabindex value, and work through the increments.
Only then will the tab order take in the remaining elements for
tabindex has been set. As such, great care
must be taken to ensure that adding a
doesn’t harm the usability of the page as a whole.
disabled attribute is set on
an element which has a
tabindex will be ignored.
is set for both form controls below:
<form> <label for="perfectday">Describe your perfect day:</label> <textarea id="perfectday" tabindex="1" name="perfectday" accesskey="d" cols="40" rows="10"> Sitting by the beach, sipping a cocktail</textarea> <input type="submit" value="Tell us" tabindex="2"/> </form>
This attribute accepts a number value only.
It causes no compatibility issues, and has excellent support across all tested browsers.
There are no comments yet.