How to add skip to content link properly

Once I hosted my site, I was actively testing the accessibility of the site. I have used tools like Lighthouse to check site's accessibility

To add some more checks I have decided to integrate Axe core into Playwright test and I found that I was missing skip to content link which is a very important thing to improve the accessibility.

It is recommended to have Skip to Content link to be the first link in the DOM

So I have added the link as the first link in the header.

<a
  className="absolute -top-full left-1/2 z-50 -translate-x-1/2 rounded px-4 py-2 transition-all focus:top-4"
  href="#main"
>
  Skip to content
</a>

While adding the Skip to content We need to make sure few points

<header>...</header>
<main role="main" id="main" className="p-4 md:p-8"></main>

So when the user will press the tab key we can use :focus pseudo class to make it visible again by resetting the transform. We can also use CSS transition to animate it to add extra attention.

I hope this explanation was helpful to understand adding skip link to improve accessibility in your projects. Please let me know if you have any suggestions/improvements for this article.

Thanks for reading 😊