tabindex: Using 0, -1 and Positive Values Correctly
Also called: Tab index, tabindex attribute, Tab order
Definition
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, 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 itself.
Who is affected: people who use keyboard navigation, 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:
<!-- 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.
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 indicator.
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
What is the difference between tabindex 0 and -1?
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.
Why should I avoid positive tabindex values?
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.
Do buttons and links need a tabindex?
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.
Which laws require a correct tab order?
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 relies on.
Can allyWay fix tabindex automatically?
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 and get a logical tab order on every page.
Related terms
Focus Order: Logical Tab Order Explained (WCAG 2.4.3)
Focus order is the sequence in which interactive elements receive keyboard focus when a user presses Tab. WCAG 2.4.3 requires that this sequence preserves the meaning and operability of the page.
Read definition: Focus Order: Logical Tab Order Explained (WCAG 2.4.3)Keyboard Navigation: WCAG 2.1.1 Explained
Keyboard navigation means that every function of a website can be reached and operated with a keyboard alone – usually with Tab, Shift+Tab, Enter, Space and the arrow keys. WCAG 2.1.1 requires it at Level A.
Read definition: Keyboard Navigation: WCAG 2.1.1 ExplainedFocus Visible: WCAG 2.4.7 and Visible Focus Styles
Focus visible means that a website shows a visible indicator – usually an outline – on the link, button or field that currently has keyboard focus. WCAG 2.4.7 requires it at Level AA.
Read definition: Focus Visible: WCAG 2.4.7 and Visible Focus StylesAccessible Modal Dialog: Focus, Escape and ARIA
An accessible modal dialog is a pop-up window that keyboard and screen reader users can use like everyone else: focus moves into it when it opens, the page behind it is inert, Escape closes it and focus returns to the control that opened it. Its focus handling falls under WCAG 2.4.3 Focus Order at Level A.
Read definition: Accessible Modal Dialog: Focus, Escape and ARIA