Fix Invisible Focus and Skip Link Keyboard Navigation
In this article
A skip link that only works when you can see where focus has landed is not a working skip link. To fix invisible focus and a broken skip link, add a visible :focus-visible style to every interactive element, make sure the skip link is the first focusable item in the DOM, remove outline: none rules, and confirm the link targets a real element with tabindex="-1" so focus actually moves. The steps below apply to ordinary HTML/CSS sites and to component frameworks that render standard DOM elements; menu labels and browser settings can differ slightly by version, device or region.
What You'll Need
- Access to the site's HTML templates and CSS (or the component files that render the header and layout).
- A modern browser with keyboard access (Tab, Shift+Tab, Enter).
- Optional but useful: the browser's built-in accessibility inspector or a screen reader such as NVDA, JAWS or VoiceOver.
- A way to test on both desktop and mobile widths, since focus styles can be hidden by responsive CSS.
Step-by-Step
- Find the skip link in the markup. It is usually the first
<a>inside<body>or inside the main layout wrapper, with text like "Skip to main content" and anhrefpointing at an ID such as#main. If it sits after the navigation, move it to the very start of the body so it is the first thing Tab reaches. - Check that the target exists and is focusable. The
href="#main"must match an element withid="main". Addtabindex="-1"to that target so the browser can move focus to it, not just scroll to it. Withouttabindex="-1", many browsers scroll but leave focus on the link, so the next Tab press goes back into the menu. - Remove every rule that hides focus. Search the CSS for
outline: none,outline: 0,:focus { outline: none }and anybox-shadow: noneon:focus. Delete or override them. Hiding the outline is the most common cause of invisible focus. - Add a strong, visible focus style. Use
:focus-visibleso the ring appears for keyboard users and not for mouse clicks. A practical rule is a 3px solid outline in a colour with at least 3:1 contrast against the background, plus a 2px offset:outline: 3px solid #1a73e8; outline-offset: 2px;. Apply it toa, button, input, select, textarea, summary, [tabindex]and any custom control that receives focus. - Style the skip link itself. The link is often visually hidden until focused. Keep it off-screen with a transform or clip, then on
:focusbring it into view at the top-left with a solid background, padding and a visible outline. Do not usedisplay: noneorvisibility: hidden, because those remove it from the tab order entirely. - Test the tab order. Reload the page and press Tab once. The skip link should appear. Press Enter. Focus should land on the main content, and the next Tab should move to the first link or control inside main, not back to the header menu. Press Shift+Tab to confirm you can move backwards.
- Check for focus traps and hidden focusable items. Off-canvas menus, modal dialogs and collapsed accordions can keep links in the tab order while they are invisible. Add
inertor remove them from the DOM when closed, and make sure any open dialog traps focus intentionally and returns focus to the trigger when closed. - Verify colour contrast of the focus ring. A thin grey ring on a white card is technically visible but easy to miss. Aim for a ring that stands out on every background it appears over, including images and dark headers. If one colour fails, use a two-tone ring (a light outline plus a dark box-shadow) so it works on both.
- Re-test with a screen reader. Turn on the screen reader and press Tab. You should hear the skip link announced first, then the main landmark after activation. If the screen reader stays silent, the target may be missing a role or accessible name; a
<main>element with anidis the simplest fix.
Common Mistakes
- Using
outline: noneglobally. This removes the only visual cue for keyboard users. Replace it with a custom ring rather than deleting it. - Pointing the skip link at a wrapper with no
tabindex. The page scrolls but focus stays on the link, so the skip does not actually skip anything. - Hiding the link with
display: none. It disappears from the tab order, so no keyboard user can ever reach it. - Placing the skip link after the navigation. It must be the first focusable element to be useful.
- Relying on
:focusalone in frameworks. Some component libraries reset focus styles; add your own:focus-visiblerule at the end of the stylesheet so it wins. - Forgetting mobile and zoomed layouts. A focus ring that is clipped by
overflow: hiddenon a container is invisible even though the CSS is correct.
Tips
- Test with the keyboard only for a full pass: Tab through the header, main content and footer without touching the mouse.
- Keep the focus ring consistent across links, buttons and form fields so users learn one visual language.
- Use
:focus-visiblefor keyboard-only rings and keep a subtler:focusstyle for mouse users if design requires it. - Check the skip link at 200% zoom; it should still be fully visible and not overlap the logo.
- If the site uses a sticky header, add
scroll-margin-topto the main target so the heading is not hidden under the header after the skip.
Troubleshooting
If the skip link appears but Enter does nothing, confirm the href ID exists exactly once and that no JavaScript is calling preventDefault() on the link. If focus moves but the ring is still invisible, inspect the element in the browser's developer tools and check which rule is overriding your outline; a later outline: none or a box-shadow: none on :focus will win. If the ring is clipped, look for overflow: hidden on a parent and either remove it or add padding. If the tab order jumps strangely, remove positive tabindex values (values above 0) and let the DOM order control focus. If a screen reader does not announce the main content, make sure the target is a landmark element such as <main> and that it has an accessible name if needed. If the problem only appears on mobile, remember that external keyboards and switch access follow the same tab order, so test with a Bluetooth keyboard before assuming it is fine.
Frequently Asked Questions
Why does my skip link not show when I press Tab?
It is probably hidden with display: none or visibility: hidden, which removes it from the tab order. Use an off-screen technique that keeps it focusable, then reveal it on :focus.
Do I need tabindex="-1" on the main content?
Yes, in most cases. It lets the browser move focus to the target so the next Tab press continues inside the main content instead of returning to the menu.
Should I use :focus or :focus-visible?
Use :focus-visible for the visible ring so keyboard users see it and mouse users do not get a ring on every click. Keep a basic :focus style as a fallback for older browsers.
Why is the focus ring invisible on some elements only?
A component style or a parent with overflow: hidden is likely clipping or overriding it. Check the computed styles in developer tools and add a specific rule for that component.
Does a skip link need to be the first element in the body?
It should be the first focusable element. Placing it at the top of the body is the simplest way to guarantee that.
Can I fix this without changing the design?
Yes. A focus ring only appears during keyboard use, so it does not affect the default look. The skip link can stay visually hidden until focused.