WebAIM - Web Accessibility In Mind

E-mail List Archives

Re: Having an application element gain focus when the pageloads?

for

From: Tim Harshbarger
Date: Mar 13, 2018 10:04AM


I would only use autofocus for elements that can receive keyboard focus and that I want to be part of the normal tab order.

I would only use tabindex="-1" if I wanted to be able to move focus to the element with javascript, but I didn't want it to be part of the normal tab order.

So autofocus would probably be the better choice if you were wanting to move keyboard focus to a specific button or field in a modal. You would only put tabindex="-1" on the div for the modal if you wanted keyboard focus to be moved there when the modal opens.


I am not sure if I explained that well.

Thanks,
Tim