Questions tagged [tabindex]

The [tabindex] is used to define a sequence that users follow when they use the Tab key to navigate through a page. By default, the natural tabbing order will match the source order in the markup.

The tabindex content attribute allows authors to control whether an element is supposed to be focusable, whether it is supposed to be reachable using sequential focus navigation, and what is to be the relative order of the element for the purposes of sequential focus navigation. The name "tab index" comes from the common use of the "tab" key to navigate through the focusable elements. The term "tabbing" refers to moving forward through the focusable elements that can be reached using sequential focus navigation.
W3C Recommendation: HTML5
Section 7.4.1 Sequential focus navigation and the tabindex attribute

The tabindex starts at 0 or any positive whole number and increments upward. It's common to see the value 0 avoided because in older versions of Mozilla and IE, the tabindex would start at 1, move on to 2, and only after 2 would it go to 0 and then 3. The maximum integer value for tabindex is 32767. If elements have the same tabindex then the tabindex will match the source order in the markup.

A negative value (usually tabindex="-1") will remove the element from the tab index and it will never be focusable via keyboard navigation. Focus can be given to the element programmatically using element.focus() or with mouse click for focusable elements.

If you specify the tabindex attribute with no value or an empty value it will be ignored.

If the disabled attribute is set on an element which has a tabindex, the element will be ignored.


If a tabindex is set anywhere within the page regardless of where it is in relation to the rest of the code (it could be in the footer, content area, where-ever) if there is a defined tabindex then the tab order will start at the element which is explicitly assigned the lowest tabindex value above 0. It will then cycle through the elements defined and only after the explicit tabindex elements have been tabbed through, will it return to the beginning of the document and follow the natural tab order.


In the HTML4 spec only the following elements support the tabindex attribute: , , , , , , and . But the HTML5 spec, with accessibility in mind, allows all elements to be assigned tabindex.

--

For example

<ul tabindex="-1">
  <li tabindex="0"></li>
  <li tabindex="1"></li>
  <li tabindex="2"></li>
</ul>

is the same as

<ul tabindex="-1">
  <li tabindex="1"></li>
  <li tabindex="1"></li>
  <li tabindex="1"></li>
</ul>

because regardless of the fact that they are all assigned tabindex="1", they will still follow the same order, the first one is first, and the last one is last. This is also the same..

<div>
  <a></a>
  <a></a>
  <a></a>
</div>

because you do not need to explicitly define the tabIndex if it's default behavior. A div by default will not be focusable, the anchor tags will.

512 questions
437
votes
6 answers

How to ignore HTML element from tabindex?

Is there any way in HTML to tell the browser not to allow tab indexing on particular elements? On my page though there is a sideshow which is rendered with jQuery, when you tab through that, you get a lot of tab presses before the tab control moves…
Tom Gullen
  • 61,249
  • 84
  • 283
  • 456
239
votes
10 answers

What is the HTML tabindex attribute?

What is the tabindex attribute used for in HTML?
sleep
  • 2,421
  • 2
  • 15
  • 5
203
votes
6 answers

How to allow keyboard focus of links in Firefox?

Go to this ultra-simple fiddle in a Webkit browser and click on on of the inputs: http://jsfiddle.net/eK4TT/ my first link my second link my…
Ben
  • 11,082
  • 8
  • 33
  • 47
84
votes
9 answers

Remove or disable focus border of browser via javascript

Does anybody know how to disable or manipulate the (in most browsers) dashed border of a dom-element if it has the focus in a tabindex order? I want to build my own style for a focused element, but it would be great to use the existing feature,…
helle
  • 11,183
  • 9
  • 56
  • 83
61
votes
1 answer

Explicitly exclude an html element from the tab order

Is there any way to exclude an element from the tab order of a HTML form. So if i have the following I'm aware…
Jason
  • 15,064
  • 15
  • 65
  • 105
54
votes
4 answers

Where do tabindex="0" HTML elements end up in the tabbing order?

In what order are elements with a tabindex value of 0 focused when the web page is tabbed?
HELP
  • 14,237
  • 22
  • 66
  • 100
52
votes
4 answers

Can I ignore some website element when navigating using the tab key?

As question really. I have an input box on my page that I would like to ignore when navigating using the keyboard tab key. I'm using this input box as a simple bot honeytrap and positioning it off the page, so at the moment when using the tab key,…
thor
  • 1,318
  • 2
  • 15
  • 24
41
votes
4 answers

Tab Index on div

Please see the form HTML code below
Mithun Sreedharan
  • 49,883
  • 70
  • 181
  • 236
39
votes
6 answers

tabindex -1 not working for child elements

I have a div tag with some content getting loaded inside it. The content inside can have buttons, anchor elements, etc. which are focusable. I do not have control over the content but I can modify the 'div' tag attributes. My problem is the focus…
Adarsh Konchady
  • 2,577
  • 5
  • 30
  • 50
37
votes
5 answers

Adding tabindex dynamically

I'd like to add tabindex to all form elements. The form is dynamic and I can't add it to the HTML. I would like to run it as a function. If there are several radio buttons with the same name, each must have it's own tabindex value. Most of the form…
santa
  • 12,234
  • 49
  • 155
  • 255
31
votes
6 answers

How do I disable a tab index on a control on a form?

I have a form with 2 buttons and 2 labels. I want to set button 1 = tabIndex = 0, button 2 = tabIndex = 1 and I do not want to set a tabIndex to the 2 labels, meaning that if the user presses tab, it'll go from button 1 to button 2. How would I go…
JJ.
  • 9,580
  • 37
  • 116
  • 189
30
votes
2 answers

document.activeElement returns body in onblur handler

Here is my HTML and JS: function invokeFunc() { // ajax request alert(document.activeElement); // this returns body element in firefox, safari and chrome. }
Jigar Parekh
  • 6,163
  • 7
  • 44
  • 64
25
votes
5 answers

Restrict tabindex focusing to a section of the page

Situation: I have a webpage which opens modal windows (light boxes) which contain forms where the user can input data. Users generally navigate using the keyboard, tabbing from one field to the next. Problem: When a modal window opens, only the…
SlappyTheFish
  • 2,344
  • 3
  • 34
  • 41
25
votes
5 answers

How to repeat the tabindex from 1 after it has gone to the last element with a tabindex?

So, for example, here's a script:
Lucas
  • 16,930
  • 31
  • 110
  • 182
22
votes
1 answer

How to prevent SVG elements from gaining focus with tabs in IE11?

There is an inline SVG element among my HTML form elements. When I navigate through my elements with the Tab key, the SVG element gets focused, in IE11 only, even if the SVG element has the tabindex="-1" attribute set to every element inside…
1
2 3
34 35