# tabindex: Using 0, -1 and Positive Values Correctly

Source: https://allyway.ai/glossary/tabindex

tabindex is an HTML attribute that makes an element focusable and sets its place in the keyboard tab order. 0 follows the source order, -1 allows focus only by script, and positive values jump ahead of everything else.

tabindex is an HTML attribute that decides whether an element can receive keyboard focus and where it sits in the Tab order. Used with `0` and `-1`, it is a helpful tool for custom controls and focus management. Used with positive numbers, it quietly reshuffles the whole page for keyboard users.

## What it means

Links, buttons and form fields are focusable by default, in the order they appear in the source code. The tabindex attribute changes that behavior:

| Value | Effect | Typical use |
|---|---|---|
| none | Native focus behavior | Links, buttons, inputs – nothing to add |
| `tabindex="0"` | Focusable, in source order | A custom control or a scrollable region that has to be reachable |
| `tabindex="-1"` | Focusable only by script or click, skipped by Tab | A dialog heading or error summary you move focus to |
| `tabindex="1"` or higher | Focused before all other elements, in ascending number order | Almost never – it breaks the natural order |

The rule behind it is [WCAG 2.4.3 Focus Order](https://www.w3.org/WAI/WCAG22/Understanding/focus-order.html), Level A: if a page can be navigated sequentially and the sequence affects meaning or operation, focusable components must receive focus in an order that preserves meaning and operability. W3C lists failure F44: using tabindex to create a tab order that does not preserve meaning and operability. The recommended alternative is technique C27 – make the DOM order match the visual order, so no tabindex is needed at all. Read more about the [focus order](https://allyway.ai/glossary/focus-order) itself.

> **Warning:** > **One positive value affects the whole page**
> A single `tabindex="1"` on a newsletter field in the footer makes it the first stop after the browser's address bar – before the logo, the menu and your [skip link](https://allyway.ai/glossary/skip-link). Every element with a positive tab index is visited first, then the rest of the page.

Who is affected: people who use [keyboard navigation](https://allyway.ai/glossary/keyboard-navigation), [screen reader](https://allyway.ai/glossary/screen-reader) users moving through controls, and people with switch devices. A wrong tab order makes them miss fields, lose context or fill in forms in the wrong sequence.

## Examples

A custom toggle that needs `tabindex="0"`, a dialog heading that receives focus by script, and the positive value to avoid:

```html title="Example"
<!-- Custom control: reachable in source order -->
<div role="switch" aria-checked="false" tabindex="0">Dark theme</div>

<!-- Focus target for script, not a Tab stop -->
<h2 id="dialog-title" tabindex="-1">Confirm your order</h2>
<script>document.getElementById('dialog-title').focus();</script>

<!-- Avoid: jumps ahead of everything else on the page -->
<input type="email" name="newsletter" tabindex="3">
```

When focus moves into a dialog, it should stay there until the dialog closes – see [accessible modal dialog](https://allyway.ai/glossary/accessible-modal-dialog).

**Do:** Do

Use native elements first – they are focusable without tabindex. Use `tabindex="0"` for custom controls and scrollable areas, `tabindex="-1"` for elements you focus by script. Fix layout problems in the source order. Give every focusable element a [visible focus](https://allyway.ai/glossary/focus-visible) indicator.

**Don't:** Don't

Use positive values to "correct" a layout. Put `tabindex="0"` on plain text or headings that aren't interactive – it adds useless Tab stops. Give an element that looks clickable `tabindex="-1"` and leave it out of the keyboard flow.

## How to check tabindex



## Questions

Q: What is the difference between tabindex 0 and -1?
A: `tabindex="0"` puts an element into the normal Tab sequence at its place in the source code. `tabindex="-1"` makes it focusable by script or mouse click, but the Tab key skips it – useful for headings or messages you move focus to.

Q: Why should I avoid positive tabindex values?
A: Elements with a positive tab index are focused before all others, in number order, no matter where they are on the page. This easily creates an order that does not preserve meaning – the failure W3C describes as F44 for WCAG 2.4.3.

Q: Do buttons and links need a tabindex?
A: No. Native links with an `href`, buttons and form fields are already focusable in source order. Adding `tabindex="0"` to them changes nothing; adding a positive value makes the order worse.

Q: Which laws require a correct tab order?
A: 2.4.3 is a Level A criterion, so it is part of every standard based on WCAG AA – including EN 301 549 clause 9.2.4.3, which the [European Accessibility Act](https://allyway.ai/regulations/eaa) relies on.

Q: Can allyWay fix tabindex automatically?
A: Yes. allyWay sets every tabindex above 0 to 0, so the Tab key follows the order of the page again – free of charge, without using any AI fixes, and without changes to your code or theme. Before the correction goes live, allyWay tries it on your real page and only applies it when nothing visitors see changes; you can change it back in one click. [Start for free](https://app.allyway.ai/register) and get a logical tab order on every page.
