HTML tabindex Global Attribute
The tabindex attribute makes an element focusable and sets its place in the Tab order: -1 for script focus only, 0 for the normal order. Avoid positive values.
Description
The tabindex global attribute allows developers to control the tab order of elements in an HTML document. This means that they can choose the order in which elements are focused when a user presses the Tab key.
The tabindex attribute can take on an integer value. A negative value (usually -1) makes the element focusable with JavaScript (element.focus()) but leaves it out of the tab order. 0 makes it focusable and puts it in the tab order at its position in the document. A positive value puts it in front of all elements with 0, in increasing order.
The tabindex attribute can be used on any HTML element, even those that are not normally focusable, such as paragraphs and headings. This can be useful for creating custom tab orders for forms or other interactive elements.
However, it is important to use the tabindex attribute carefully. If used incorrectly, it can make a web page difficult or impossible to navigate for users who are using a keyboard.
Here are some tips for using the tabindex attribute:
- Use the
tabindexattribute to control the tab order of interactive elements, such as form fields, buttons, and links. - Only make non-interactive elements focusable with
tabindex="0"when they act as controls, and give them a suitableroleand keyboard handling. A native<button>is usually better. - Avoid positive values. They change the order from what users see on the page and are hard to maintain; arrange the elements in the source in the right order instead.
- Use
tabindex="-1"for elements that you move focus to with JavaScript, such as a dialog heading or an error summary.
Here is an example of how positive values change the tab order of a form (shown for illustration; it is better to keep the source order):
<form>
<input type="text" tabindex="1" placeholder="Name">
<input type="email" tabindex="2" placeholder="Email">
<input type="submit" tabindex="3" value="Submit">
</form>
In this example, the name field will be focused first when the user presses the Tab key. The email field will be focused next, and then the submit button.
By using the tabindex attribute, developers can create custom tab orders for their web pages that make them easier to navigate for users who are using a keyboard.
Syntax
<element tabindex="number">
Values
- negative numberThe element can be focused with JavaScript or by clicking, but not with the Tab key.
- 0The element is focusable and is reached with Tab in source order.
- positive numberThe element is reached with Tab before elements with 0, in increasing order of the value. Not recommended.
Example
Browser Support
The following information will show you the current browser support for the HTML tabindex global attribute. Hover over a browser icon to see the version that first introduced support for this HTML global attribute.
Desktop





Tablets & Mobile





