How to ignore HTML element from tabindex?

HtmlTabindex

Html Problem Overview


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 to the next visible link on the page as all the things being tabbed through are hidden to the user visually.

Html Solutions


Solution 1 - Html

You can use tabindex="-1".

The W3C HTML5 specification supports negative tabindex values:

> If the value is a negative integer
> The user agent must set the element's tabindex focus flag, but should not allow the element to be reached using sequential focus navigation.


Watch out though that this is a HTML5 feature and might not work with old browsers.
To be W3C HTML 4.01 standard (from 1999) compliant, tabindex would need to be positive.


Sample usage below in pure HTML.

<input />
<input tabindex="-1" placeholder="NoTabIndex" />
<input />

Solution 2 - Html

Don't forget that, even though tabindex is all lowercase in the specs and in the HTML, in Javascript/the DOM that property is called tabIndex.

Don't lose your mind trying to figure out why your programmatically altered tab indices calling element.tabindex = -1 isn't working. Use element.tabIndex = -1.

Solution 3 - Html

If these are elements naturally in the tab order like buttons and anchors, removing them from the tab order with tabindex="-1" is kind of an accessibility smell. If they're providing duplicate functionality removing them from the tab order is ok, and consider adding aria-hidden="true" to these elements so assistive technologies will ignore them.

Solution 4 - Html

If you are working in a browser that doesn't support tabindex="-1", you may be able to get away with just giving the things that need to be skipped a really high tab index. For example tabindex="500" basically moves the object's tab order to the end of the page.

I did this for a long data entry form with a button thrown in the middle of it. It's not a button people click very often so I didn't want them to accidentally tab to it and press enter. disabled wouldn't work because it's a button.

Solution 5 - Html

Just add the attribute disabled to the element (or use jQuery to do it for you). Disabled prevents the input from being focused or selected at all.

Solution 6 - Html

The way to do this is by adding tabindex="-1". By adding this to a specific element, it becomes unreachable by the keyboard navigation. There is a great article here that will help you further understand tabindex.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTom GullenView Question on Stackoverflow
Solution 1 - HtmlMartin HenningsView Answer on Stackoverflow
Solution 2 - HtmlEric L.View Answer on Stackoverflow
Solution 3 - HtmlMattView Answer on Stackoverflow
Solution 4 - HtmlJemmehView Answer on Stackoverflow
Solution 5 - HtmlyainspanView Answer on Stackoverflow
Solution 6 - HtmlNesha ZoricView Answer on Stackoverflow