Explore Bato Web Agency Webflow Certified Partner Profile Explore Bato Web Agency Webflow Certified Partner Profile

What is the difference between tabindex=”0″ and tabindex=”-1″?

Illustration without a description Illustration without a description

tabindex="0" places an element in the page’s sequential keyboard focus order, while tabindex="-1" keeps it out of that sequence but still allows focus through JavaScript or an in-page target. Both values make many elements programmatically focusable, but only zero creates a regular Tab stop.

 

Use zero for a custom interactive element that must participate in natural keyboard navigation and has no suitable native HTML equivalent. Its position follows the DOM alongside links, buttons and form controls. Adding zero does not supply a role, accessible name, activation keys or state management, so those behaviors still need to be implemented and tested.

 

Use minus one for temporary or managed focus targets. Common examples include a dialog container when it opens, an error summary after failed submission, a heading at the start of newly loaded content or inactive items inside a roving-tabindex widget. Users reach these elements through an action or arrow-key pattern rather than by tabbing through every item.

 

<div role="tablist" aria-label="Account sections">
<button role="tab" tabindex="0" aria-selected="true">Profile</button>
<button role="tab" tabindex="-1" aria-selected="false">Security</button>
</div>

 

Do not add either value to ordinary text without a focus-management reason, and do not add zero to a div as a substitute for a button. Native controls already have correct focus behavior. In custom widgets, confirm that arrow-key movement and the single active Tab stop remain synchronized after every state change. Choose zero when the user should encounter the element with Tab, and minus one when the interface should move focus there deliberately.