Web development

Add a skip link to repeated navigation

Put a skip link near the start of the document so keyboard users can move past repeated navigation to the main content. Keep the link visible when it receives focus.

Worked example

HTML example · save as example.html and open in a browser

<style>
.skip{position:absolute;top:-5rem;left:1rem;background:white;padding:.75rem;z-index:10}
.skip:focus{top:1rem}
</style>
<a class="skip" href="#main">Skip to content</a>
<nav><a href="/">Home</a> <a href="/articles/">Articles</a></nav>
<main id="main" tabindex="-1"><h1>Article title</h1><p>Start reading here.</p></main>

How it works

The fragment points to a unique main-content target. Tabindex minus one permits programmatic focus without adding the main element to the normal tab sequence. The focused link is positioned above other page content so it can be seen and activated.

Limits and mistakes

Do not use display none for the default hidden state because that removes the link from keyboard navigation. The target ID must exist on every page that uses the shared link. Test actual focus behavior in supported browsers.

Check the result

Reload the page, press Tab once, and activate Skip to content. The viewport and subsequent keyboard navigation should move into the main content rather than restarting at the navigation links.

Sources

Reference documentation for the behavior used in this guide: