Content · Web Development · HTML

HTML Tabindex Zero, Negative One, and Positive Values

Tabindex Zero, Negative One, and Positive Values: Try moving through the elements with a keyboard. The labels and relationships matter even when no extra styling has been added. Includes a practical HTML example and an explanation.

1 views Published Oct 19, 2026 Updated Oct 19, 2026 Admin

Good accessibility usually starts with clear words and the right HTML elements, not a large amount of extra code.

What You Need to Know


tabindex=0 adds an element to normal keyboard navigation, and tabindex=-1 allows focus by script without putting it in the Tab sequence. Positive values can jump ahead of the natural order and are best avoided.

Try the Example


Take a look at the example. We’ll explain the important lines right below it.

<p>Press Tab to move through the controls below.</p>
<a href="/lessons">Browse lessons</a>
<button type="button">Start quiz</button>
<section id="message" tabindex="-1"><h2>Quiz result</h2></section>

Let’s Read the Code


  • tabindex: Tabindex affects sequential keyboard focus; positive values are usually a poor choice.
  • <button>: The button offers an action; its type or command determines what happens.
  • <section>: A section groups content with a shared topic.
  • href: Href is the URL to a related resource or destination.

Read the named elements and attributes together. They explain how the browser connects this feature to the rest of the page.

What Happens in the Browser?


Try this with Tab and Shift+Tab. If you can, inspect the accessibility tree too; appearance alone does not tell the whole story.

A quick keyboard check: Press Tab to move forward, Shift+Tab to go back, and Enter or Space to activate controls when appropriate. Watch where focus goes. If you cannot tell which control is active, the interface needs improvement.

Your Turn


Use Tab and Shift+Tab to visit the controls, then read their labels aloud. Is the purpose of each one clear?

Common Beginner Mistakes


  • Judging the page only by how it looks, without checking its meaning and keyboard behavior.
  • Check the same result using both the browser and a keyboard, not only by looking at the screen.

Key Takeaways


  • tabindex=0 adds an element to normal keyboard navigation, and tabindex=-1 allows focus by script without putting it in the Tab sequence.
  • tabindex: Tabindex affects sequential keyboard focus; positive values are usually a poor choice.
  • A meaningful HTML element is usually a stronger starting point than adding an ARIA role to a generic div. Also check what happens using only the keyboard.
Share this resourceSend this page to someone who may find it useful.