HTML tabindex Attribute

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The tabindex global attribute controls whether an element can receive focus and whether it is reached by sequential keyboard navigation (usually the Tab key). An integer value decides the behavior.

Prefer real interactive elements — <button>, <a href>, <input> — which are already in the Tab order. Related: accesskey, autofocus, disabled.

Baseline · Widely available.

Not deprecated and not experimental. Stable global attribute across modern browsers since about July 2015.

Use only 0 and -1.

Per MDN: avoid positive tabindex values (and CSS that reorders focusable items). They make keyboard and assistive-tech navigation harder. Keep focus order matching the document’s logical reading order.

HTML Syntax

syntax.html
<element tabindex=" integer">

Common safe values: 0 and -1. Equivalent JS: el.tabIndex = 0 (note the capital I in the DOM property).

Attribute Values

Integer values and what they mean:

ValueDescriptionTry it
0In Tab order, in document source order (recommended)Try it
-1 (or any negative)Focusable by script/click; skipped by Tab (recommended)Try it
Positive (1, 2…)Custom Tab order — avoid (MDN warning)Try it
Omitted on nativesButtons, links, inputs already participate in Tab orderTry it

Live Preview

Click inside the preview, then press Tab / Shift+Tab. Watch which boxes receive focus.

demo

Focus rings appear when an item is focused. The skip target uses tabindex="-1".

Focus demo

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Include a Custom Region in Tab Order

Make a non-control element reachable with Tab using 0.

HTML
<p>Press Tab after focusing this page area.</p>

<label>Name
  <input type="text" name="name">
</label>

<div tabindex="0">
  Custom panel — tabbable because tabindex="0".
</div>

<label>Email
  <input type="email" name="email">
</label>
Try It Yourself

How It Works

  1. tabindex="0" adds the panel to sequential Tab navigation.
  2. Order follows the source among other 0 / natural controls.
  3. Inputs need no tabindex — they are focusable by default.
  4. If it acts like a button, prefer a real <button> instead of a plain div.

Example 2 — Programmatic Focus with -1

Skip Tab, but allow focus() (e.g. an error or dialog target).

HTML
<p id="err" tabindex="-1">Please fix the email field.</p>

<label for="email">Email</label>
<input id="email" type="email" name="email">

<button type="button" id="show-err">Simulate error focus</button>

<script>
  document.getElementById("show-err").addEventListener("click", function () {
    document.getElementById("err").focus();
  });
</script>
Try It Yourself

How It Works

  1. tabindex="-1" keeps the message out of the normal Tab sequence.
  2. Script can still call focus() when you need attention.
  3. MDN use cases: modals, off-screen panels, form error announcements.
  4. Negative values are equal for Tab skipping — -1 is the usual choice.

Example 3 — Prefer Native Controls (No Positive tabindex)

Write markup in reading order; skip inventing tabindex="1", 2, …

HTML
<!-- Good: natural order matches the layout -->
<button type="button">Save</button>
<button type="button">Cancel</button>
<a href="/help">Help</a>

<!-- Avoid: custom positive order -->
<!-- <button tabindex="2">…</button> -->
<!-- <button tabindex="1">…</button> -->
Try It Yourself

How It Works

  1. Native controls are already keyboard-focusable.
  2. Source order = Tab order when you avoid positive values.
  3. Positive tabindex jumps ahead of 0 and natives — easy to get wrong.
  4. MDN: recommend only 0 and -1 when you must use the attribute.

Edge Cases & Pitfalls

Most accessibility bugs come from positive tabindex or fake controls on plain divs.

warning

Avoid positive values

Per MDN: values greater than 0 create a brittle custom order. Max historical value is 32767 — still don’t use it.

a11y

Not a substitute for <button>

Focusable divs lack built-in roles and Enter/Space behavior. Prefer semantic interactive elements.

css

Visual order ≠ Tab order

Flex/grid reordering can confuse keyboard users if source order differs from what they see.

natives

Don’t re-add 0 on buttons/links

They’re already tabbable. Use -1 only when you intentionally remove one from the sequence.

disabled

disabled removes focus

A disabled control is skipped regardless of tabindex. Fix enablement, not Tab numbers.

Browser Support

tabindex is an HTML global attribute for focus and Tab order in the browser. It is not a Node.js, Deno, or Bun API.

✓ Widely available

tabindex

Supported in all modern browsers. Stick to 0 and -1 for accessible keyboard UX.

97% Global support (approx.)
Google Chrome All modern
Full support
Mozilla Firefox All modern
Full support
Apple Safari All modern
Full support
Microsoft Edge All modern
Full support
Opera All modern
Full support
Samsung Internet Modern
Full support
Internet Explorer All
Supported
tabindex Widely supported

Bottom line: Safe and universal. Accessibility quality depends on using 0 / -1 and semantic controls — not on browser gaps.

Key Takeaways

  • Role: focusability and Tab sequence control.
  • Safe values: 0 (in order) and -1 (script focus only).
  • Avoid positive tabindex — keep logical document order.
  • Prefer button / a / input over focusable divs.

One line: use tabindex sparingly — usually 0 or -1, never a handmade positive ladder.

Frequently Asked Questions

It controls whether an element can receive focus and whether it participates in sequential keyboard navigation (usually the Tab key), and can affect relative order among positive values.
MDN recommends using only 0 and -1. Avoid positive values (1, 2, 3…) because they create a confusing custom Tab order that is hard for keyboard and assistive-tech users.
The element is focusable and included in Tab order after any positive tabindex elements, in document source order among other tabindex="0" and naturally focusable controls.
The element can be focused with script (or often a mouse click) but is skipped in sequential Tab navigation. Useful for modals or error messages you focus programmatically.
Usually no. Links with href, buttons, inputs, and similar controls are already in the Tab order. Add tabindex only when you need to change that (for example -1 to remove one from the order).
tabindex alone is not enough for accessibility. Prefer real interactive elements like button or a. Non-interactive tags lack built-in roles and keyboard behavior that assistive tech expects.

Next: target

Choose where a link or form response opens.

target tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful