DEV Community

Cover image for How to add "SKIP TO MAIN CONTENT" to websites
Kritika Pattalam Bharathkumar
Kritika Pattalam Bharathkumar

Posted on • Originally published at blog.kritikapattalam.com

How to add "SKIP TO MAIN CONTENT" to websites

As part of this blog post let's see what is web accessibility, and how to add "skip to main content" link for web pages and why?.

Accessibility

As per w3.org

Web accessibility means that websites, tools, and technologies are designed and developed so that people with disabilities can use them. More specifically, people can: perceive, understand, navigate, and interact with the Web
contribute to the Web

For a normal user when he visits a page, he/she directly jumps to the section of the page where they want to read. But if we consider visually impaired users or someone who uses screen reader, the assistive device has to read through the entire page before they can reach a point which interests them.

Let's assume when a user lands on the page , the screen reader will read the entire navigation/header and then goes to the actual content of the page. The user reads through the first page of your website once, now he/she goes to the second page and the screen reader will again start reading the entire navigation for them before they can go to the main content. This is where "SKIP TO MAIN CONTENT" link comes in handy for them.

How to add "SKIP TO MAIN CONTENT" on the page

HTML

  • Inside the body tag add an anchor tag as the first element.
  • Add an id to the content you want the screenreader to jump/skip to. eg: 'main-content'
  • Add the same id as the href value to the anchor tag eg: 'main-content'
<body>
    <a class="skip-link" href="#main-content">SKIP TO MAIN CONTENT</a>
    <header> .....</header>
    <main id="main-content">
         Main Body Content .....
    </main>
    <footer>......</footer>
</body>
Enter fullscreen mode Exit fullscreen mode

CSS

  • Add CSS to the link to hide it from view. [P.S Do not use display:none or visibility hidden because screen readers will not read the element. Our main focus is for the screen reader to read the link]
  • When the screenreader focuses on that element, make the element visible and also the screen reader will read the content inside the anchor tag . i.e "SKIP TO MAIN CONTENT" in our example.
.skip-link {
    position: absolute;
    left: -999px;
    width: 1px;
    height: 1px;
    top: auto;
}

.skip-link:active, .skip-link:focus {
    color: #000;
    display: inline-block;
    height: auto;
    width: auto;
    position: static;
    margin: auto
}
Enter fullscreen mode Exit fullscreen mode

References

Checkout my other blog posts

Please share your feedbacks and suggestions in the comments below.

Lets connect on Twitter | LinkedIn for more web development related tips & tricks.

Top comments (6)

Collapse
 
ishanpro profile image
Ishan Tiwari

You should also add

html {
scroll-behaviour:smooth;
}
Enter fullscreen mode Exit fullscreen mode


`
in your project. It will smoothen the effect and make the process more enjoyable for the user.

Collapse
 
grahamthedev profile image
GrahamTheDev • Edited

If you are doing that make sure that it either responds to the media query prefers-reduced-motion: reduce and switches it off or have an option to switch it off on the site.

Smooth scrolling can cause people with motion sensitivity to feel sick etc. As we are talking about an accessibility feature I think this is even more important to consider!

Collapse
 
ishanpro profile image
Ishan Tiwari

I didn't know that this can make people sick.

Thread Thread
 
grahamthedev profile image
GrahamTheDev

Yeah look up “vestibular disorders”, it is quite common, especially for temporary conditions such as vertigo.

Easy enough to account for -> developer.mozilla.org/en-US/docs/W...

Just something to bear in mind while adding animations of any kind.

Thread Thread
 
kritikapattalam profile image
Kritika Pattalam Bharathkumar

True. Agree with you. Since this is related to accessibility will have to keep this in mind.

Collapse
 
kritikapattalam profile image
Kritika Pattalam Bharathkumar

Thanks. Hope you find it useful.