How7o
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Reading: How to Skip a Link When Pressing Tab (tabindex=-1)
Share
How7oHow7o
Font ResizerAa
  • OS
Search
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Follow US
© 2024–2026 How7o. All rights reserved.
How7o > Free Laravel, PHP, WordPress & Server Tutorials > Web Development > How to Skip a Link When Pressing Tab (tabindex=-1)
Web Development

How to Skip a Link When Pressing Tab (tabindex=-1)

how7o
By how7o
Last updated: May 22, 2026
5 Min Read
Prevent tab key from focusing on a link with tabindex=-1
SHARE

To prevent the Tab key from focusing on a specific <a> tag, add tabindex="-1" to it. The negative value removes the element from the natural keyboard tab order — it stays clickable with the mouse, but pressing Tab skips over it.

Contents
  • The one-attribute fix
  • How tabindex values behave
  • The better fix — reorder the markup
  • Accessibility note
  • Frequently asked questions
  • Related guides
  • References

Last verified: 2026-05-17 in Chrome 124, Firefox 125, Safari 17. Originally published 2023-01-21, rewritten and updated 2026-05-17.

The one-attribute fix

<a href="#" id="forgot-password" tabindex="-1">Forgot Password</a>

With tabindex="-1", the user’s Tab key jumps straight from the username field to the password field, skipping the “Forgot Password” link.

Skip a link with Tab — tabindex=-1, DOM reorder alternative, accessibility note

How tabindex values behave

  • tabindex="0" — included in the natural tab order at its DOM position. Used to make non-interactive elements focusable (e.g. <div tabindex="0">).
  • tabindex="-1" — not in the tab order, but still programmatically focusable via .focus(). The case we want here.
  • tabindex="1" and above — forces a custom tab order regardless of DOM. Almost always a bug magnet; let DOM order dictate tab order instead.
  • No tabindex at all — interactive elements (<a href>, <button>, form fields) are tabbable by default; non-interactive ones aren’t.

The better fix — reorder the markup

<form>
  <label for="username">Username</label>
  <input type="text" id="username" name="username">

  <label for="password">Password</label>
  <input type="password" id="password" name="password">

  <a href="#" id="forgot-password">Forgot Password</a>

  <button type="submit">Log In</button>
</form>

Move “Forgot password” below the password input (visually and in the DOM). Tab order follows DOM order — username → password → forgot password → log in is the natural flow most users expect, and no tabindex tricks are needed.

Accessibility note

tabindex="-1" removes the element from keyboard tab navigation, not from accessibility. Screen-reader users in virtual-cursor mode can still reach the link with arrow-key navigation; mouse users can still click it. The element is still announced and reachable — it just doesn’t interrupt the form-filling tab path.

Frequently asked questions

Does tabindex="-1" hide the element from screen readers?

No — it only removes the element from the keyboard tab order. Screen-reader users navigating with virtual-cursor mode (arrow keys) can still encounter it. tabindex="-1" excludes from keyboard tabbing, not from accessibility — which is exactly what you want for a “Forgot password” link that should be reachable but not on the password-entry path.

Is this an accessibility regression?

It can be if you remove keyboard access to everything. For an inline link inside a form, skipping it during tab and reaching it on mouse or via Shift+Tab from later focus points is reasonable. Audit yourself by trying to complete the form with only the keyboard — if the user can still reach “Forgot password” (e.g. after reaching the submit button, Shift+Tab back), the change is fine.

Why is the link before the password field at all? Wouldn’t it be simpler to move it?

Yes, when you control the layout — move “Forgot password” below the password input or to the right of it. tabindex="-1" is the right tool when the DOM order is dictated by a template you can’t change (theme, plugin, third-party widget). When you can edit the markup, fixing the visual + DOM order is the more robust fix.

What’s the difference between tabindex="-1" and tabindex="0"?

0 includes the element in the natural tab order at its position in the source. -1 excludes it from tab order entirely but makes it programmatically focusable (you can call .focus() on it). Positive values like tabindex="5" force a custom order — almost always a mistake; let DOM order dictate tab order.

Related guides

  • How to Add a Required Attribute to Input Fields in jQuery
  • How to Disable or Enable an Input with JavaScript or jQuery
  • How to Auto-Focus a Select2 Dropdown on Page Load

References

MDN tabindex: developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex. WAI-ARIA Authoring Practices on keyboard interaction: w3.org/WAI/ARIA/apg/practices/keyboard-interface.

TAGGED:accessibilityformshtml

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
[mc4wp_form]
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article Open a file selection dialog from a button click How to Open a File Dialog When Clicking a Button
Next Article Nginx redirect www to non-www or vice versa How to Redirect www to non-www (or vice versa) in Nginx
Leave a Comment

Leave a Reply Cancel reply

You must be logged in to post a comment.

FacebookLike
XFollow
PinterestPin
InstagramFollow
Most Popular
Set vi as the default editor in Ubuntu — a terminal opening the vim editor
How to Set vi (Vim) as the Default Editor in Ubuntu
June 8, 2026
rsync says ALL DONE but files are missing — a terminal showing ALL DONE next to an empty folder
rsync Says “ALL DONE” but Files Are Missing: How to Verify
June 8, 2026
Migrate a website to a new server with rsync — files copying from an old server to a new one over SSH
How to Migrate a Website to a New Server With rsync
June 8, 2026
Bun runtime — faster JS toolkit replacing npm in Laravel projects
How to Install Bun Runtime on Ubuntu (And Use It in a Laravel Project)
May 24, 2026
Tailscale mesh — peer-to-peer connections between devices, coordination server
How to Install Tailscale on Ubuntu (Zero-Config Mesh VPN for Self-Hosters)
May 24, 2026

You Might Also Like

Laravel request inputs with prefix — filter request()->all() by Str::startsWith
Web Development

How to Retrieve Inputs with a Specific Prefix in Laravel Request

7 Min Read
Display PHP errors — ini_set + php.ini configuration
Web Development

How to Display PHP Errors

7 Min Read
Keep the first N characters of a JavaScript string with slice
Web Development

How to Keep Only the First N Characters of a String in JavaScript

4 Min Read
PHP add days to a date — strtotime and DateTimeImmutable side by side
Web Development

How to Add Days to a Date in PHP

5 Min Read
How7o

We provide tips, tricks, and advice for improving websites and doing better search.

Tools

  • Age Calculator
  • Word Counter
  • Image Upscaler
  • Password Generator
  • QR Code Generator
  • See all tools→

Pranks

  • Fake Blue Screen Prank
  • Hacker Typer
  • Fake iMessage Generator
  • Windows XP Crash Prank
  • Windows 11 Update Prank
  • See all prank screens →

Company

  • About Us
  • Blog
  • Contact
  • Privacy Policy
  • Terms of Service
  • Sitemap
© 2024–2026 How7o. All rights reserved.
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?