No matter how long you do something, there is always more to learn. You’d think that since I’ve been doing HTML coding since around 1993, I’d pretty much know every in and out and every little tag and peculiarity regarding HTML. Not so. See, we form habits. We get into patterns. Specs change but we retain earlier hacks and assumptions. Today I learned an absurdly simple thing. Maybe I knew this and forgot. I rarely use tab orders on my forms. Most of the forms I create are very top down so the natural tab order is sufficient. In computing, counting starts at zero. But in HTML tab order, zero means exclude that form element from the tab order.
To exclude an element from the tab order, set the value of tabindex to 0. [Source, Webcheatsheet.com, How to Control Tab Order in HTML]
Because of my computer science studies, programming in PHP, JavaScript, C and so on, my inclination is to always begin with zero. Of course, my favorite web application language is ColdFusion and it always starts at one. I can only assume the Allaire brothers were originally targeting non-programmers.
HTML is about to become HTML 5. Funny enough I just traded my HTML 3.2 book at McCay’s a few weeks ago. Maybe I should have kept it and re-read it.
Update Jan 12, 2009: Ian Tempest noted in the comments that zero does not exclude an element but rather moves it to the end of the tab order. From the W3C HTML 4.01 specification:
Those elements that do not support the tabindex attribute or support it and assign it a value of “0? are navigated next. These elements are navigated in the order they appear in the character stream. [Source, W3C, 17.11.1 Tabbing navigation]
Hello Doug,
Zero tabindex behaviour is slightly different to how you describe, though this could be an issue of semantics. The ‘zero elements’ will be navigated after the positive tabindex elements. To exclude an element from the taborder (i.e. to make it ‘untabbable’) it should be assigned a negative tabindex.
http://www.w3.org/TR/html401/interact/forms.html#h-17.11.1
Not an issue of semantics at all. Normally I look to the W3C for this kind of information. This time I took the info from Webcheatsheet.com
Reading at the W3C link you made above we have:
Negative numbers are not allowed. We also have:
So it would seem that aside from “disabled” no number excludes an element from the tab order. You are correct with zero. Zero moves the element to the last of the tab order. Thanks for pointing this out!