Skip to the Main Content

Write the code, see it run, pass the checks.

The problem

  • easy
  • Code

Add a skip link so keyboard users can jump past the navigation. The first thing on the page that takes focus is a link named "Skip to main content" with href="#main". After it comes a nav with "Home", "Blog" and "About" links, then a main element with id="main" holding a heading "Welcome" and a "Read more" link. Activating the skip link, by click or Enter, moves keyboard focus onto the main element itself: give main tabIndex={-1} so it can take focus, and focus it in the link's click handler, because browsers don't reliably move focus when following an in-page link (the checks' browser doesn't). The next Tab then lands on "Read more".

Your code must pass

  • Tab first reaches "Skip to main content", which links to #main
  • Activating the skip link focuses the main content
  • The next Tab goes to "Read more", past the navigation