DEV Community

Cover image for A11Y 101: Adding skip links
Chris Bongers
Chris Bongers

Posted on • Originally published at daily-dev-tips.com

10 1

A11Y 101: Adding skip links

While evaluating my website, I realized while using a screen reader. A user has to tab quite a lot to get to the main content part.

This is quite annoying as this can take you forever, and you might even lose users over this behavior.

What are skip links?

Luckily for us, there is a solution to fix this, called skip links.

These are technically hidden links that sit above navigation areas, so people can quickly skip that section.

To illustrate it could look like this:

<a href="#main-content" class="skip-link">Skip navigation</a>
<nav>
  <a href="#">About</a>
  <a href="#">Contact</a>
  <a href="#">Login</a>
</nav>
<main id="main-content">I'm the main content</main>
<footer>
  <a href="#">Privacy</a>
</footer>
Enter fullscreen mode Exit fullscreen mode

This, in general, already works. We can quickly tab and skip the whole navigation section!

Making skip links better

It's ugly to have this link sit there, so we can make it visually hidden as we just learned.

In our case, we want to be able to show it on focus, so let's move it outside of the view initially.

.skip-link {
  background: #da0060;
  color: #fff;
  left: 50%;
  padding: 8px;
  position: absolute;
  transform: translate(-50%, -200%);
  transition: transform 0.3s;
}
Enter fullscreen mode Exit fullscreen mode

With this code, we set the skip links element above the top of our page, so it's not visible to users.

We can add a focus selector to animate it into the screen when a user focuses on it using tab navigation.

.skip-link:focus {
  transform: translate(-50%, 0);
}
Enter fullscreen mode Exit fullscreen mode

And when they now tab into this element, it will appear.

I made this super simple demo for you to play with.
Try using your tab navigation and interact with the skip element, then tab again.

You are immediately in the footer, right?
Now try not to click on the skip link, but keep tabbing.
You are now able to visit the menu!

Thank you for reading, and let's connect!

Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter

Tiugo image

Modular, Fast, and Built for Developers

CKEditor 5 gives you full control over your editing experience. A modular architecture means you get high performance, fewer re-renders and a setup that scales with your needs.

Start now

Top comments (0)

Image of Stellar post

Check out Episode 1: How a Hackathon Project Became a Web3 Startup 🚀

Ever wondered what it takes to build a web3 startup from scratch? In the Stellar Dev Diaries series, we follow the journey of a team of developers building on the Stellar Network as they go from hackathon win to getting funded and launching on mainnet.

Read more

👋 Kindness is contagious

Dive into this thoughtful article, cherished within the supportive DEV Community. Coders of every background are encouraged to share and grow our collective expertise.

A genuine "thank you" can brighten someone’s day—drop your appreciation in the comments below!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found value here? A quick thank you to the author makes a big difference.

Okay