Tabindex: A Quick Look

DZone 's Guide to

Tabindex: A Quick Look

In this short article, we take a look at how to include tabindex in your front-end code. By mastering this, you will write more efficient and user-friendly forms.

· Web Dev Zone ·
Free Resource

When dealing with element focusing, tabindex plays a big role. This attribute indicates if the element can be focusable and reachable via keyboard navigation. When pressing the Tab key, the browser shifts focus from one element to another. By using tabindex, we can change the tab order flow.

When creating an element, styling should be included.


Tabindex accepts integer values. They can be:

  • Negative (usually tabindex="-1") - the element is not reachable through keyboard navigation.
  • tabindex="0" - the element is reachable by the keyboard navigation but the order is defined by the document's source order.
  • Positive - the element is reachable by the keyboard navigation, and the order is defined by the value. For example, tabindex="2" is focusable before tabindex="3", but after tabindex="1".


Tabindex can be used on the following elements:

  • input
  • anchor (a)
  • textarea
  • select
  • button

After creating any of these elements, give the text a proper line-height.



  <label>This element will be focused second</label>
  <input name=”field1” type=”email” tabindex=”2” />

   <label>This element will be focused first</label>
  <textarea rows=”4”  cols=”5” tabindex=”1”></textarea>

   <label>The second focused last</label>
  <input name=”field3” type=”text” tabindex=”3”/>

Here we can see the order of the tab selection, starting from the lowest to the highest number. If an element has tabindex="0", it will be excluded from the tab order. If two elements have the same tabindex value, they will be selected in the order which they appear in the element.

If you found this article interesting and useful, check out other subjects such as relative font size, CSS columns and a little something about SASS and LESS.


This short article summarizes the usage of the tabindex. By mastering this, you will write more efficient and user-friendly forms.

Thank you for reading and happy coding!

web dev ,html ,tabindex ,front-end development

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}