Skip to content

Linter Rule: Avoid positive tabindex values

Rule: html-no-positive-tab-index

Description

Prevent using positive values for the tabindex attribute. Only tabindex="0" (to make elements focusable) and tabindex="-1" (to remove from tab order) should be used.

Rationale

Positive tabindex values create a custom tab order that can be confusing and unpredictable for keyboard users. They override the natural document flow and can cause elements to be focused in an unexpected sequence. This breaks the logical reading order and creates usability issues, especially for screen reader users who rely on a predictable navigation pattern.

The recommended approach is to structure your HTML in the correct tab order and use tabindex="0" only when you need to make non-interactive elements focusable, or tabindex="-1" to remove elements from the tab sequence while keeping them programmatically focusable.

Examples

✅ Good

erb
<!-- Natural tab order (no tabindex needed) -->
<button>First</button>
<button>Second</button>
<button>Third</button>

<!-- Make non-interactive element focusable -->
<div tabindex="0" role="button">Custom button</div>

<!-- Remove from tab order but keep programmatically focusable -->
<button tabindex="-1">Skip this in tab order</button>

<!-- Zero tabindex to ensure focusability -->
<span tabindex="0" role="button">Focusable span</span>

🚫 Bad

erb
<button tabindex="3">Third in tab order</button>
Do not use positive `tabindex` values as they are error prone and can severely disrupt navigation experience for keyboard users. Use `tabindex="0"` to make an element focusable or `tabindex="-1"` to remove it from the tab sequence. (html-no-positive-tab-index)
<button tabindex="1">First in tab order</button>
Do not use positive `tabindex` values as they are error prone and can severely disrupt navigation experience for keyboard users. Use `tabindex="0"` to make an element focusable or `tabindex="-1"` to remove it from the tab sequence. (html-no-positive-tab-index)
<button tabindex="2">Second in tab order</button>
Do not use positive `tabindex` values as they are error prone and can severely disrupt navigation experience for keyboard users. Use `tabindex="0"` to make an element focusable or `tabindex="-1"` to remove it from the tab sequence. (html-no-positive-tab-index)
<input tabindex="5" type="text">
Do not use positive `tabindex` values as they are error prone and can severely disrupt navigation experience for keyboard users. Use `tabindex="0"` to make an element focusable or `tabindex="-1"` to remove it from the tab sequence. (html-no-positive-tab-index)
<button tabindex="10">Submit</button>
Do not use positive `tabindex` values as they are error prone and can severely disrupt navigation experience for keyboard users. Use `tabindex="0"` to make an element focusable or `tabindex="-1"` to remove it from the tab sequence. (html-no-positive-tab-index)

References

Released under the MIT License.