Today I Learned

hashrocket A Hashrocket project

HTML Tab Index Gotcha

The tabindex attribute on HTML elements behaves differently than one might first expect.

The default tabindex for an element is 0, all elements with this index will be tabbed to in the order they appear in the document.

Giving an element a positive tabindex will prioritize it over all elements with a 0 index, in the order they appear.

Consider the following code

    { [0,1,2].map((n) => (
  • {n}
  • ) }

The order that the buttons will be focused when tabbing is 1, then 2, and finally 0.