`tabindex` HTML global attribute
The tabindex global attribute allows developers to make HTML elements focusable, allow or prevent them from being sequentially focusable (usually with the <kbd>Tab</kbd> key, hence the name) and determine their relative ordering for sequential focus navigation.
The **`tabindex`** [global attribute](/docs/Web/HTML/Reference/Global_attributes) allows developers to make HTML elements focusable, allow or prevent them from being sequentially focusable (usually with the <kbd>Tab</kbd> key, hence the name) and determine their relative ordering for sequential focus navigation.
tabbed-standard
```html interactive-example
<p>Click anywhere in this pane, then try tabbing through the elements.</p>
<label>First in tab order:<input type="text" /></label>
<div tabindex="0">Tabbable due to tabindex.</div>
<div>Not tabbable: no tabindex.</div>
<label>Third in tab order:<input type="text" /></label>
```
```css interactive-example
p {
font-style: italic;
font-weight: bold;
}
div,
label {
display: block;
letter-spacing: 0.5px;
margin-bottom: 1rem;
}
div:focus {
font-weight: bold;
}
```
It accepts an integer as a value, with different results depending on the integer's value:
> [!NOTE]
> If an HTML element renders and has `tabindex` attribute with any valid integer value, the element can be focused with JavaScript (by calling the [`focus()`](/docs/Web/API/HTMLElement/focus) method) or visually by clicking with the mouse. The particular `tabindex` value controls whether the element is `tabbable` (i.e., reachable via sequential keyboard navigation, usually with the <kbd>Tab</kbd> key).
- A _negative value_ (the exact negative value doesn't actually matter, usually `tabindex="-1"`) means that the element is not reachable via sequential keyboard navigation.
> [!NOTE]
> `tabindex="-1"` may be useful for elements that should not be navigated to directly using the <kbd>Tab</kbd> key, but need to have keyboard focus set to them. Examples include an off-screen modal window that should be focused when it comes into view, or a form submission error message that should be immediately focused when an errant form is submitted.
- `tabindex="0"` means that the element should be focusable in sequential keyboard navigation, after any positive `tabindex` values. The focus navigation order of these elements is defined by their order in the document source.
- A _positive value_ means the element should be focusable in sequential keyboard navigation, with its order defined by the value of the number. That is, `tabindex="4"` is focused before `tabindex="5"` and `tabindex="0"`, but after `tabindex="3"`. If multiple elements share the same positive `tabindex` value, their order relative to each other follows their position in the document source. The maximum value for `tabindex` is 32767.
- If the `tabindex` attribute is included with no value set, whether the element is focusable is determined by the user agent.
> [!WARNING]
> You are recommended to only use `0` and `-1` as `tabindex` values. Avoid using `tabindex` values greater than `0` and CSS properties that can change the order of focusable HTML elements ([Ordering flex items](/docs/Web/CSS/Guides/Flexible_box_layout/Ordering_items)). Doing so makes it difficult for people who rely on using keyboard for navigation or assistive technology to navigate and operate page content. Instead, write the document with the elements in a logical sequence.
Some focusable HTML elements have a default `tabindex` value of `0` set under the hood by the [user agent](/docs/Glossary/User_agent). These elements are an a or area with `href` attribute, button, frame , iframe, input, object, select, textarea, and SVG a element, or a summary element that provides summary for a details element. Developers shouldn't add the `tabindex` attribute to these elements unless it changes the default behavior (for example, including a negative value will remove the element from the focus navigation order).
> [!WARNING]
> The tabindex attribute must not be used on the dialog element.
## Accessibility concerns
Avoid using the `tabindex` attribute in conjunction with non-[interactive content](/docs/Web/HTML/Guides/Content_categories#interactive_content) to make something intended to be interactive focusable by keyboard input. An example of this would be using a div element to describe a button, instead of the button element.
Interactive components authored using non-interactive elements are not listed in the [accessibility tree](/docs/Learn_web_development/Core/Accessibility/What_is_accessibility#accessibility_apis). This prevents assistive technology from being able to navigate to and manipulate those components. The content should be semantically described using interactive elements (a, button, details, input, select, textarea, etc.) instead. These elements have built-in roles and states that communicate status to the accessibility that would otherwise have to be managed by [ARIA](/docs/Web/Accessibility/ARIA).
- [Using the tabindex attribute | Vispero](https://vispero.com/resources/using-the-tabindex-attribute/)
## Specifications
## Browser compatibility
## See also
- All [global attributes](/docs/Web/HTML/Reference/Global_attributes)
- HTMLElement.tabIndex that reflects this attribute
- Accessibility problems with `tabindex`: see [Don't Use Tabindex Greater than 0](https://adrianroselli.com/2014/11/dont-use-tabindex-greater-than-0.html) by Adrian Roselli
- Reading order
Cite this
"`tabindex` HTML global attribute". MDN Web Docs. CC BY-SA 2.5 (MDN). https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/tabindex JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy