Prevent tabstop on A element (anchor link) in HTML
To omit an anchor from tab navigation, add tabindex="-1"
to the <a>
tag:
This ditches focus, making sure the tab key hops over this link.
With CSS, you can fashion your link to look the part, while not being tabbable:
Tabstop prevention with CSS and better accessibility
Using CSS for no-tabstop strategy
An alternative to tabindex
is to remove the href
to prevent focus:
This technique uses a span
with role="link"
, masquerading as a link for accessibility tools while maintaining semantics. The onclick
handler ensures it remains clickable.
Situations for non-focusable links
Certain circumstances warrant non-focusable links:
- Navigation aids: Mouse users won't need these in tab order.
- Duplicate links: Makes sense if multiple navigation paths lead to the same destination.
- App UI controls: These fall more into the buttons category than traditional hyperlinks.
Keeping accessibility in mind
While playing around with the tab order, always remember:
- Non-tabbable content, if not handled correctly, makes it inaccessible to screen readers.
- If a resource is linked, ensure there's an alternate way to access it for keyboard navigation.
Following W3C's guidelines about using ARIA roles and tabindex
appropriately can lead to better accessibility.
Ensuring a solid user experience
Handling focus invisibility
If you're looking for control, consider:
But this may hamper usability for keyboard users. It's vital to strike a balance between visibility and looks.
Tabindex-Scripting interplay
JavaScript allows dynamic modification of tabindex
, paving the way for advanced interaction designs:
Use scripting with caution and consider impact on differently-abled users.
Sticking to standards
When in doubt, look up the W3C rules. Regularly referring to trustworthy sources ensures that your solutions remain current and compliant.
Was this article helpful?