Skip Links in Web Accessibility
Quick summary
Skip link is a special link that is visually hidden from users and that helps screen reader users skip repetitive content on the site (such as large navigation menus or the site header, as well as various sidebars) and go directly to the main content of the page.
Importance of Skip Links in Web Accessibility
Most web users (and junior developers too) are unaware of these links – they are hidden visually, but appear, for example, when you go to a page and press Tab on your keyboard as your first action. They are also usually the very first piece of content on the page and are therefore read first by screen readers. If you are curious, try going to some sites you use often and pressing tab as soon as you get there. On many popular and visited sites, you will see a previously hidden link appear and offer to direct you to unique content.
Not everyone interacts with websites the same way. While most of us can scroll through menus using a mouse or trackpad, many others (like keyboard users or people with disabilities) have to press Tab for each navigation link before they get to the main content.
Sites typically have a large navigation or header at the top of each page, so not having a "skip link" to the content can result in blind screen reader users hearing the same content over and over as they navigate your site, or having to skip elements and guess where the unique content on the page begins. A very common case is when a navigation element contains many submenus and items, and the user may have to wait a long time for the screen reader to read them out loud.
Let's take a look at how skip links are implemented on some popular sites:
How Skip Links Improve User Experience
Skip links allow users with limited mobility or those relying on assistive technologies to skip over repetitive content like navigation menus and access the main part of the page more quickly. — WCAG 2.1 Success Criterion 2.4.11
Keyboard Users
For users navigating via keyboard (often using the Tab key), skip links provide an essential shortcut to jump past headers, menus, and other repetitive elements. This ensures that users can quickly reach the main content without unnecessary navigation, which enhances the speed and efficiency of their browsing experience.
Example: A website with multiple navigation menus can be tedious to navigate for users who can't use a mouse. With a skip link, they can focus on the main content after pressing Tab just once.
Screen Reader Users
Screen readers, like JAWS or VoiceOver, read out the content of a webpage linearly. Skip links can be a crucial tool for users of these devices, allowing them to bypass lengthy navigation and headers, which might otherwise slow down their access to relevant information.
When a skip link is implemented, screen readers will announce it early on the page, giving users the choice to immediately skip ahead or continue through the menu.
Implementing Skip Links in NextJS
The process for implementing skip links in Next.js is similar to how it is done in a standard HTML/CSS project, but with some key features of React and component architecture.
1. Adding the Skip Link in Your Layout Component
In Next.js, you typically have a global layout component (like _app.js or layout.js) that wraps all your pages. This is the perfect place to add a skip link that can be used site-wide.
Here’s a basic example of how you can implement the skip link in the layout:
// components/Layout.js
export default function Layout({ children }) {
return (
<>
<a href="#main-content" className="skip-link">
Skip to main content
</a>
<header> {/* Your header code */} </header>
<main id="main-content">{children}</main>
</>
);
}2. Styling the Skip Link
For the best user experience, skip links should be hidden by default and only appear on (:focus-visible). This way, they won't interfere with the site's design, but will be available when users need them.
Here's an example of how to style a skip link in global.css with Tailwind CSS:
/* global.css */
.skip-link {
@apply z-50 absolute left-0 -top-12 focus-visible:top-0 bg-primary text-primary-foreground underline text-lg px-6 py-2;
}Further reading
- A Deep Dive on Skipping to Content by Paul Ratcliffe
- Your skip links are broken by Hampus Sethfors
- Implement a Skip Link for Navigation-Heavy Sites by Ben Myers
- Skip Navigation Links by WebAIM
Footnotes: