Is it possible to cancel an <a href="...">
from being tabstopped in any browser? I would like to do this without Javascript.
Asked
Active
Viewed 8.0k times
164

Taz
- 3,718
- 2
- 37
- 59

Robert Koritnik
- 103,639
- 52
- 277
- 404
5 Answers
287
Some browsers support the tabindex="-1"
attribute, but not all of them, since this is not a standard behaviour.

Hernán Eche
- 6,529
- 12
- 51
- 76

Roberto Aloi
- 30,570
- 21
- 75
- 112
-
22Oh great! Thanks! I've checked with FF3.5, IE8 and CH3 and it work in all three. Thanks a million! – Robert Koritnik Oct 13 '09 at 16:40
-
1No worries about this: just like zzzzBov states [here](https://stackoverflow.com/a/12128112/214517), HTML5 came to the rescue and standardized this functionality. So now the guilty browsers are those that miss this. – Niki Romagnoli Nov 17 '17 at 08:52
-
1Keep in mind that disabling the tabstop on a hyperlink goes against accessibility rules (e.g. people using screen readers, etc). If you know that this isn't a problem for your user base, then it should be fine. – Ricardo Sanchez Mar 29 '18 at 00:27
79
Modern, HTML5 compliant, browsers support the [tabindex]
attribute, where a value of -1
will prevent the element from being tabbed to.
If the value is a negative integer
The user agent must allow the element to be focused, but should not allow the element to be reached using sequential focus navigation.

zzzzBov
- 174,988
- 54
- 320
- 367
-
1Documentation excerpts always help. ;-) This tells us that those not supporting this are among the few and they'll likely support it sooner or later. – Robert Koritnik Jun 04 '14 at 18:58
17
You could apply a JQuery handler to the element you want to target multiple elements with no tab stop.
$(document).ready(function () {
$('.class').attr('tabindex', '-1');
});
Would be one way to do it....

Daniel Rikowski
- 71,375
- 57
- 251
- 329

dtharpe
- 179
- 1
- 2
6
I think you could do this by javascript, you override the window.onkeypress
or onkeydown
, trap the tab button, and set the focus at the desired order.

Christian Specht
- 35,843
- 15
- 128
- 182

Ammosi
- 61
- 1
- 1
-
3I appreciate the alternative solution even if it doesn't address the OP as well as the accepted answer. No need to be disparaging. – Anthony DiSanti Nov 01 '10 at 18:45
-
@Anthony DiSanti: That is true, but in this particular case I still dn't see why would one resort to javascript if something else works better? So if it's not an answer to this question why is it here then? Nevermind. Javascript is usually the last step one would take if certain things can't be done otherwise. And I'm sorry @Ammosi if I've insulted you. I didn't mean to be rude. Thanks for the late answer. – Robert Koritnik Feb 11 '11 at 08:35
-
7I agree with avoiding javascript if there is a standards-based HTML or CSS solution. However, in this case there is not. The original poster didn't need to support browsers prior to IE8 and FF3.5, but for my work I need to support back to IE6. The tabindex solution is therefore not applicable. Providing the only working solution in the browser with the greatest market share should not be discouraged. – Anthony DiSanti Feb 12 '11 at 19:47
3
Remove the href
attribute from your anchor tag

Hakan Fıstık
- 16,800
- 14
- 110
- 131

CodeDreamer68
- 420
- 5
- 10
-
-
If willing to use javascript despite the question to avoid that kind of solutions, to remove href attributes, use jquery document onload with something like `$('[href="whatever-the-url-is"]').removeAttr('href');` – Jonas Lundman Jun 06 '18 at 22:45
-
7