Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / HTML

HTML term or value: tabindex

The `tabindex` attribute controls focusability and participation in sequential keyboard navigation.

Version: WHATWG HTML Living Standard; index snapshot date recorded separately

Syntax

<div tabindex="-1">…</div>

tabindex accepts a valid integer. 0 expresses an author preference for inclusion according to structure and focus scope, while -1 prefers script or click focus without Tab participation; a user agent can ignore these preferences when platform conventions require it.

The tabIndex property exposes the value used by the DOM, and focus() can move focus to an element with a negative value. No tabindex value makes an intrinsically focusable element non-focusable; use disabled for a control or inert for a subtree when those semantics apply.

Avoid positive values such as tabindex="1", which create a separate order that is difficult to maintain. Native button and addressed a elements already have keyboard behavior; making a div focusable supplies no role or Enter/Space activation.

The example gives a container tabindex="-1": the property returns -1, and after focus() the element becomes document.activeElement even though it does not participate in the ordinary Tab sequence.

Examples

<!doctype html><meta charset="utf-8"><button id="a">A</button><div id="x" tabindex="-1">Target</div><output id="result"></output><script>x.focus();result.textContent=`tabIndex=${x.tabIndex}; focused=${document.activeElement===x}`;</script>

Result

tabIndex=-1; focused=true

The executed example verifies the boundary between programmatic focus and sequential navigation for a negative value.

Sources