Skip to: content, navigation

tabindex (HTML attribute)

Spec
Depr. Version
No HTML 3.02
Browser support (more…)
IE5.5+ FF1+ SA1.3+ OP9.2+
Full Full Full Full

Syntax

tabindex="number"

Description

The 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 attribute.

A 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 in error, the tabbing order of those affected elements will be as per the source markup order.

If a 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 which no tabindex has been set. As such, great care must be taken to ensure that adding a tabindex doesn’t harm the usability of the page as a whole.

If the disabled attribute is set on an element which has a tabindex, that tabindex will be ignored.

Example

The tabindex is set to "3" for the link below:

<p>You can try our <a href="cakes.html" tabindex="3">lovely
     range of cakes</a>.</p>

Value

This attribute can take any numeric value.

Compatibility

Internet Explorer Firefox Safari Opera
5.5 6.0 7.0 1.0 1.5 2.0 1.3 2.0 3.0 9.2 9.5
Full Full Full Full Full Full Full Full Full Full Full

It causes no compatibility issues, and has excellent support across all tested browsers.

User-contributed notes

ID:
#1
Contributed:
by AutisticCuckoo
Date:
Fri, 28 Mar 2008 10:09:55 GMT

It doesn't have to be an error to assign the same tabindex to multiple links; it may be quite deliberate.

You could assign tabindex="1" to all links in the main content column, tabindex="2" to all links in the sidebar and tabindex="3" to all navigation links, for instance. That way you can add new links to either column without having to renumber every subsequent link.

Add a note

To post a note on this topic, please log in with your SitePoint username and password. If you don't have an account yet, you can create a new account for free.

Related Products

Search