61

Is there any way to exclude an element from the tab order of a HTML form.

So if i have the following

<input type=text name=username>
<input type=text name=password>
<input type=button name=forgotpassword>
<input type=submit name=login>

I'm aware that I can use tabindex as 1,2,3,4 but i don't want to have to number all the fields. My application is dynamically creating the fields.

sb813322
  • 129
  • 9
Jason
  • 15,064
  • 15
  • 65
  • 105

1 Answers1

153

Setting the tabindex to -1 will render an element untabbable (if that's a word) :)

<input type="text" name="username" tabindex="-1" />
Marko
  • 71,361
  • 28
  • 124
  • 158
  • Excellent, that's exactly what i wanted. – Jason Oct 09 '10 at 05:12
  • 8
    And there went your accessibility, right out the door. Is it really that hard to set `tabindex="4"` for the 'forgot password' button, and `tabindex`es 1-3 for the rest? – Lambart Jun 15 '15 at 20:35
  • 5
    @Lambart Note that MDN explicitly discourages using a tabIndex other than -1 or 0, i.e. you should restructure your DOM rather than providing explicit tabIndex order. Moreover, tabIndex -1 is considered by MDN to be **actually useful** for accessibility: https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex – vog Oct 24 '18 at 14:49