104

I have 2 buttons next to a textbox and another textbox after the 2 buttons. The tabindex for the first textbox is 1000, the first button is 1001 and the second button is 1002. The second textbox has a tabindex of 1003.

When I press tab, the tabindex works fine in all browsers except for Safari, where it immediately moves from the first textbox to the second textbox although the tabindex has been set properly. Any ideas on how to prevent this issue?

DLS
  • 5,313
  • 8
  • 37
  • 50
  • If you remove the second textarea and switch the button tabindexes (so the order in the source is 1000, 1002, 1001), does Safari follow the tabindex order? Looks like Safari gives higher precedence to textareas/text inputs, for whatever reason... – Joel L Dec 04 '09 at 17:21
  • 3
    No, even that doesn't work. It seems as if tabindex on href's are ignored in Safari. I am trying a workaround with buttons to see if that will work. – DLS Dec 04 '09 at 17:31
  • 1
    This is not how tabindex works. The only relevant numbers for tabindex are -1, 0, and 1. The rest are an anti-pattern and may break accessibility for users. – ChaBuku Bakke Oct 01 '20 at 13:59

7 Answers7

257

By default tab-access is disabled in safari(!). To enable it, check "Preferences > Advanced > Press tab to highlight each item on a page".

graphicdivine
  • 10,937
  • 7
  • 33
  • 59
  • 34
    This answer is almost 7 years old, but it's still the correct fix. I'm surprised Apple doesn't enable this option by default. – Alex Oct 06 '16 at 14:37
  • 15
    This is unbelievable. Why would Safari DO this? – mAAdhaTTah Mar 08 '17 at 16:06
  • 5
    Shocked that this still has to manually be a activated. Thank you for the answer! – Yuschick Oct 18 '17 at 06:11
  • 1
    Is there a way to do this on iPad? I don't see this option under Settings -> Safari -> Advanced. Let me know if you know how to do this on iPad please. – Chemist Mar 21 '18 at 14:50
  • @Chemist I'm not sure how you would use a TAB key on an iPad, or why? – graphicdivine Mar 21 '18 at 16:01
  • 6
    @graphicdivine I figured it out, you have to use Options+Tab. How - with bluetooth keyboard, why - because the job requires it https://stackoverflow.com/questions/2292016/is-there-a-workaround-to-safaris-operas-bug-that-you-cant-tab-through-hyperli – Chemist Mar 21 '18 at 16:32
  • 1
    Yes it seems like tabbing works by default as long as you hold down option. – Jonny Oct 17 '19 at 08:43
  • The behavior is the same in iOS safari but I cannot find a similar option there. Does anyone know how to enable this on Safari for iOS? – Squeegy Jun 10 '21 at 16:13
  • I hate that safari has these kind of problems. I have to keep telling my users to use Google chrome or Firefox because I can't configure push notifications without paying a 100 USD per year, although I have a reset.css file, my styles don't look good on safari (just for little things like margins), tab does not work without doing some difficult thing for a normal user. – Herii Sep 16 '21 at 02:51
  • The same thing for Chrome. Go to Settings → Appearance → Pressing Tab on a web page highlights links, as well as form fields – Londeren Apr 15 '22 at 13:10
  • @Londeren the difference is this setting is checked by default on Chrome. – vitorbal Apr 28 '22 at 15:29
  • 1
    Thank you. I was getting frustrated. I could tab through everything in Chrome. In Safari, I could tab through links and input fields with or without tabindex="0" added to them. But Safari skipped over buttons without links. I tried your tip and now I can tab through everything in Safari. – Sean Kelliher Nov 26 '22 at 15:27
  • 1
    April 2023 and this is still a thing – kavdev Apr 14 '23 at 02:12
27

Solution for iOS will be holding Option Key + Tab key.

lesyk
  • 3,979
  • 3
  • 25
  • 39
22

Making Safari and a Mac accessible:

Testing on a Mac: System Preferences -> Keyboard -> ShortCuts (tab) -> Full Keyboard Access -> All Controls

For Tabbing to work on Safari: Preferences -> Advanced -> Press tab to highlight each item on a page (check this)

user3862605
  • 389
  • 4
  • 7
6

If you're writing your own webpage, I'd fix write something with a bit of jquery/javascript. This is what I've used on mine.

The drawback is that you prevent the default tab-key behavior on the page, which may be a bigger problem for accessibility in some situations. But I doubt it.

var Tab = {};
Tab.i = 1,
Tab.items = 0;

function fixTabulation () {
    /* This can be used to auto-assign tab-indexes, or
    #  commented out if it manual tab-indexes have
    #  already been assigned.
    */
    $('input, select, textarea').each(function(){
        $(this).attr('tabindex', Tab.i);
        Tab.i++;
        Tab.items++;
    });

    Tab.i = 0;

    /* We need to listen for any forward or backward Tab
    #  key event tell the page where to focus next.
    */
    $(document).on({
        'keydown' : function(e) {
            if (navigator.appVersion.match("Safari")) {
                if (e.keyCode == 9 && !e.shiftKey) { //Tab key pressed
                    e.preventDefault();
                    Tab.i != Tab.items ? Tab.i++ : Tab.i = 1;
                    $('input[tabindex="' + Tab.i + '"], select[tabindex="' + Tab.i + '"], textarea[tabindex="' + Tab.i + '"]').not('input[type="hidden"]').focus();
                }
                if (e.shiftKey && e.keyCode == 9) { //Tab key pressed
                    e.preventDefault();
                    Tab.i != 1 ? Tab.i-- : Tab.i = Tab.items;
                    $('input[tabindex="' + Tab.i + '"], select[tabindex="' + Tab.i + '"], textarea[tabindex="' + Tab.i + '"]').not('input[type="hidden"]').focus();
                }
            }
        }
    });

    /* We need to update Tab.i if someone clicks into
    #  a different part of the form.  This allows us
    #  to keep tabbing from the newly clicked input
    */
    $('input[tabindex], select[tabindex], textarea[tabindex]').not('input[type="hidden"]').focus(function(e) {
        Tab.i = $(this).attr('tabindex');
        console.log(Tab.i);
    });
}

$(document).ready(function() {
    fixTabulation();
});

This is no perfect solution, but it's quite better than telling all your users to go change their Safari settings in System Prefs, lol.

John Hadwin
  • 114
  • 1
  • 4
5

I tried the following with Safari 5.1.5. I don't know how it works with older versions:

When "highlighting each item on a page" (see answer by graphicdivine) is disabled, you can use that function by pressing Option(alt) + tab.

If you don't (and the option is disabled), Safari will by default tab through all form-fields (like input, textarea, select...). For this fields, it will also accept/regard a tabindex. It will first tab through all form elements with a tabindex (in the order of the given indices) and then through the rest of the form elements in the order of their definition in HTML.

So if you define a tabindex="1" (or 1001) and "3" (or 1003) for two input-elements Safari will first focus this fields and then the others.

Zaphoid
  • 2,360
  • 1
  • 18
  • 19
3

For those like me also looking how to enable this in browserstack: simply click the word "Safari" in the top left button of the screen, then you can select Preferences > Advanced > Press tab (as mentioned in https://stackoverflow.com/a/1914496/11339541)

Koen Cornelis
  • 151
  • 1
  • 4
0

Encountered the same issue and had to implement tab navigation programatically. Luckily found this jquery tabbable plugin https://github.com/marklagendijk/jQuery.tabbable and put it to good use, here's

require('../../node_modules/jquery.tabbable/jquery.tabbable');
$(document).ready(() => {
  $(document).keydown((event) => {
    if (event.keyCode === 9) {
      window.$.tabNext();
      event.preventDefault();
    }
  });
});
Dan Ochiana
  • 3,340
  • 1
  • 30
  • 28