Skip to content
Tutorials Center
My learning

Topics

Lesson 17 of 38 ยท Keyboard and Focus

Skip Links and Bypassing Blocks

Learn how to build a skip link that works, why WCAG 2.4.1 requires a way to bypass repeated content, and how landmarks, headings and focus targets complete the picture.

Most pages repeat the same header and navigation, sometimes dozens of links, before the real content. A mouse user simply looks past them. A keyboard user would have to press Tab through every one, on every page. WCAG 2.4.1 (Bypass Blocks, Level A) requires a mechanism to skip repeated blocks of content. The classic answer is a skip link: the very first focusable element on the page, which jumps to the main content.

You also have other mechanisms: landmarks and headings count as valid ways to bypass blocks for screen reader users, since they can jump straight to <main>. But keyboard-only sighted users do not use landmark shortcuts, so a skip link is still the most useful one. This lesson builds it properly.

HTML
<body>
  <a class="skip-link" href="#main">Skip to main content</a>
  <header>...navigation...</header>
  <main id="main" tabindex="-1">
    <h1>Page title</h1>
  </main>
</body>

The link is a normal anchor to the id of the main area. Three details make it reliable:

  1. It is the first focusable element in the DOM.
  2. It is visible when focused. It may be hidden until then, but must never stay hidden for a sighted keyboard user.
  3. The target has tabindex="-1" so that focus actually moves there in all browsers. Without it, some browsers scroll to the target but leave focus at the link, and the next Tab continues from the top.

Hide it visually until focus, the right way

Do not use display: none or visibility: hidden, since those remove it from the tab order and the link would never be reachable. Move it off-screen, or collapse it, and bring it into view on focus.

A working skip link

Activate the link and the status line shows that focus is now on main itself. The next Tab moves to the first control inside it, not back into the menu.

Why tabindex="-1" on the target

Fragment navigation to a non-focusable element is inconsistent. Chrome and Edge are good about moving the sequential focus starting point, but Safari and older browsers may not. Making the target programmatically focusable avoids any doubt. Hide the resulting outline on that element only (main:focus { outline: none; }), since it is not an interactive control. It is still fine for :focus-visible to apply to real controls.

More skip targets

Large pages benefit from several skip links: "Skip to search", "Skip to footer", or in a web app "Skip to results". Keep them few. One main-content link is the minimum, and a short group of two or three is acceptable. Group them in one container that appears on focus.

Other ways to bypass blocks

Mechanism Helps
Skip link Keyboard and switch users
Landmarks (main, nav) Screen reader users
Headings Screen reader users, scanners
Collapsible navigation Everyone on small screens
Page structure with accesskeys Rarely recommended, they clash with other shortcuts

Mobile navigation hidden behind a "Menu" button naturally reduces the number of links before the content, but you should still provide a skip link for the desktop layout.

Check for a skip link

Common mistakes

  • Hiding the link with display: none. Keyboard users can then not reach it.
  • Never showing it. Moving it off-screen without a :focus rule makes a hidden tab stop.
  • A broken target. The href points to an id that does not exist.
  • Skip link not first. A cookie banner before it pushes it down. Put the skip link first, or place the banner after it.
  • Moving focus but not the scroll position. Test with sticky headers, and add scroll-padding-top.
  • Single-page apps. On route changes, also move focus to the new page heading or main region (see managing focus).

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which WCAG criterion requires a way to skip repeated blocks?

    2.4.1 Bypass Blocks (Level A) asks for a mechanism such as a skip link, landmarks or headings.
  2. 2. Where should the skip link be in the DOM?

    It must be reached with the first Tab press to be useful.
  3. 3. Why add tabindex="-1" to the skip target?

    A non-interactive target is not focusable by default, so browsers may leave focus behind at the link.
  4. 4. Why not hide the skip link with display: none?

    Elements with display none cannot take focus, so the link could never appear when tabbing.

Summary

  • Pages with repeated content need a bypass mechanism, and a skip link is the best for keyboard users.
  • Make it the first focusable element, visible on focus and pointing to a target with tabindex="-1".
  • Landmarks and headings also help, particularly for screen reader users.
  • Test with Tab and Enter, including sticky headers and single-page apps.

Next: Managing Focus in Dialogs and Widgets