Add a "Skip to Main Content" Link
Keyboard users should not have to tab through the same navigation on every page before reaching the article. A “Skip to main content” link gives them a direct route past those repeated controls.
The link should be one of the first focusable elements in the document. It can stay visually hidden until it receives keyboard focus, so it does not need to compete with the normal page design.
A small skip-link pattern
Add the link near the start of the page and point it at the main content:
<!-- index.html -->
<a class="skip-link" href="#main">Skip to main content</a>
…
<main id="main" tabindex="-1">
Main content
</main>
Then move the link offscreen until somebody tabs to it:
/* style.css */
.skip-link {
position: absolute;
top: -50px;
left: 0;
background: #eee;
z-index: 100;
}
.skip-link:focus {
top: 0;
}
The link is still available to the keyboard even when it is positioned above the viewport. On focus, top: 0 brings it back into view.
tabindex="-1" on the target was needed for consistent focus behaviour in IE and Chrome when this article was written. It allows the main element to receive programmatic focus without adding it to the normal tab order.
The W3C has more detail in its technique for adding a link at the top of each page. The implementation is small, and for navigation-heavy sites it removes a lot of repetitive keyboard work.
Enjoyed reading this?
If you found this article helpful, consider supporting my writing. Every little bit helps keep this blog going.
Related articles
- When to Use Hugo Shortcodes or Render Hooks
Use render hooks to change normal Markdown output and shortcodes for custom content with meaning Markdown cannot express.
- Finding Hidden Content With hidden="until-found"
Let Find in Page and fragment navigation reveal collapsed content with hidden=until-found, while keeping a usable fallback.
- The HTML Details That Make Forms More Accessible
Build clearer forms with visible labels, autocomplete, connected help and errors, fieldsets, and visible focus.