CodePark/ questions / Accessibility & ARIA
START PRACTICINGPRACTICE
Frontend question · CSS & HTML › Accessibility & ARIA

What does tabindex="-1" do on a div?

Makes the element focusable with element.focus(), but leaves it out of the Tab order

A negative tabindex makes an element focusable from script with element.focus(), but the Tab key skips it. This is useful when your code moves focus to a dialog heading or an error summary.

"Focusable and first in the Tab order" is the tempting wrong answer. A positive value such as
tabindex="1" jumps an element ahead of everything else. That is an anti-pattern (a common bad practice), because it breaks the order users expect. tabindex="0" adds the element to the natural Tab order, not last. "Never receives focus" is wrong because script can still focus it.