Recent chats
ASKGEEZ Q&A GUIDETechnology & devices

When should I use tabindex values on website elements?

Quick answer

Most of the time, do not add tabindex to native controls such as links with href, buttons, and form fields; they are normally keyboard-focusable already. Use tabindex="0" when a non-interactive element genuinely needs to join normal Tab navigation, and tabindex="-1" when it should be focusable by code but skipped by Tab. Avoid positive values: they create a separate numeric order that can be confusing when the page changes. [S1]

LET’S WORK THROUGH IT

The question, the details, the next step.

Question

I’m reviewing a page and see tabindex on several elements. What is it for, and when should I leave it out?

Geez

Think of tabindex as a way to affect whether an element can receive keyboard focus and how it relates to sequential Tab navigation. The simplest choice is usually no tabindex at all. Links with href, buttons, inputs, selects, and textareas are normally focusable without it. [S1]

For example, a regular button can be written as a button, without a tabindex attribute. Adding tabindex="0" to that button generally adds nothing needed for Tab access. Prefer the element’s native behavior rather than adding tabindex as a blanket accessibility fix. This guidance is about HTML behavior; it does not determine whether the page’s interaction or visual design is accessible.

Follow-up question

What if a custom element, like a card or a control built from a div, should be reachable with Tab?

Geez

First ask whether it should actually behave as an interactive control. If it performs an action, a native button or link is generally the clearer starting point. If a non-interactive element truly needs to be included in the regular Tab sequence, tabindex="0" makes it sequentially focusable in its position in the document. [S1]

For instance, if a custom widget has a focusable container, tabindex="0" places it in the normal sequence according to document order—not at a hand-picked numeric position. That attribute alone does not supply the widget’s behavior or establish that it works correctly for keyboard users. Check the full interaction, not just whether the element receives focus.

Follow-up question

When is tabindex="-1" useful, and how is it different from zero?

Geez

Use tabindex="-1" when an element should be focusable through code but should not be added to the sequential Tab order. By contrast, tabindex="0" lets the user reach the element through normal Tab navigation, following its position in the document. [S1]

A possible use is a page section heading that receives focus after an in-page action, so a person can begin reading at the new section without making every heading a Tab stop. Treat that as a design example, not a guarantee that a particular focus-management pattern is right for every page. Verify that focus moves at the intended moment and that the person can continue navigating sensibly. MDN also cautions against using tabindex on a dialog element. [S1]

Follow-up question

Why are positive values discouraged? Can you give me a quick review rule for an existing page?

Geez

Positive values such as tabindex="1" put those elements into a numeric focus order ahead of elements with tabindex="0". That can make the keyboard path harder to follow, especially when someone edits the page and its numbered elements no longer match the intended sequence. MDN recommends using only 0 and -1, avoiding positive values, and preferring a logical document order. [S1]

For a review, try this decision rule:

  1. If it is a native link or form control, remove an unnecessary tabindex.
  2. If it should join normal Tab navigation, consider 0 and check the document order.
  3. If it should be reached by code but skipped by Tab, consider -1.
  4. If it has a positive value, reconsider the design rather than renumbering around it.
  5. Test the whole keyboard path and the interaction. The cited guidance explains tabindex behavior, but does not prescribe a framework-specific focus-management implementation. [S1]

Example review note: “The button is natively focusable, so remove its tabindex. Keep the section heading at -1 only if the page intentionally moves focus there; test that transition and continued navigation.”

A practical checklist

  • Identify whether the element is already a native link or form control.

  • Use tabindex="0" only when an element needs normal sequential Tab access.

  • Use tabindex="-1" only when programmatic focus is intended without a Tab stop.

  • Replace positive tabindex values with a logical document-order approach where possible.

  • Test the complete keyboard interaction, not just the presence of a focusable element.

A few more useful answers

Does tabindex="0" make a div into a button?

No. It makes the element sequentially focusable according to its document position, but does not by itself give it button behavior. [S1]

Should I add tabindex="0" to every link and button?

Usually not. Links with href and native buttons are normally focusable without adding tabindex. [S1]

What does a negative tabindex do?

A negative value allows programmatic focus without adding the element to sequential Tab navigation. [S1]

Sources

References used for this guide.

  1. [S1] MDN: tabindex global attribute
    developer.mozilla.org · Checked

YOUR QUESTION. YOUR DETAILS.

Let’s work through your situation.

Get a tailored answer or help with your next task. Starts at $1, with a quote before you pay.

Ask your own question
← Back to Geez at Work