Why Tab Order Becomes a Problem

Keyboard navigation on the web follows a simple contract: press TAB to move focus between focusable elements, press ENTER to activate. The failure mode is scale. Sites that put a long menu of links at the top of every page can force dozens of key presses before the first bit of real content is reachable — on the 20min homepage, getting to the top story takes close to 40.

Fixing this requires accounting for two distinct groups: people who combine the keyboard with a screen reader such as NVDA or JAWS on Windows, or VoiceOver on macOS, and all other keyboard users. The solution that follows uses two complementary techniques, landmarks and skip links, while staying out of the way of mouse users. The example site used throughout is called Style Magic, with versions for each technique in a CodePen collection and standalone pages for easier keyboard testing.

Landmarks Come Free With HTML5

Screen readers can list a page's landmarks — significant regions the user can jump to directly — and let the user move to one from that list. In NVDA with a full keyboard, INS+F7 opens the "Elements List" and ALT+d shows the landmarks; VoiceOver has a comparable Web Item Rotor.

Most sites already have landmarks without knowing it, because they map directly to the HTML5 semantic elements. Converting wrapper <div>s to the right elements costs nothing on the CSS side when the classes are preserved, and requires only a handful of edits in the example:

  • The top-level <div> becomes <header>.
  • The branding block becomes <section>.
  • Both menu containers become <nav> elements, each labeled with aria-label: "Main menu" for the top one, "Utility menu" for the one at the bottom.
  • The content wrapper becomes <main>.
  • The bottom <div> becomes <footer>.

With those changes, the Elements List reports banner, Main menu; navigation, main and content info. A user can select main from the dialog, or in NVDA just press D while browsing to step between landmark roles; JAWS users can press Q to land on main. Semantic elements also help search engines understand and index the content.

Confirming With a Screen Reader

Testing keyboard behavior on CodePen is awkward, so the standalone pages are the practical way to verify. Windows users can install the free NVDA for an authentic run-through, and WebAIM publishes usage overviews for both NVDA and VoiceOver.

Landmarks alone are not enough. Google research from 2011 on CTRL+f found that 90% of people had either never heard of it or never used it; screen reader users rely on landmarks in much the same uneven way. A skip link covers both groups plus keyboard users without a screen reader. A good one meets four requirements:

  • It is perceivable to all keyboard users, screen reader or not, when needed.
  • It explains what it does.
  • It works across as broad a range of current browsers as possible.
  • It does not interfere with mouse users.

Make Focus Obvious First

Keyboard focus is the equivalent of the cursor position in a word processor: TAB moves it between links and form controls. Browsers render a default focus indicator, but it benefits from reinforcement. The :focus pseudo-class carries the styling, and mirroring the same rules for :hover keeps the treatment consistent.

a:focus { /* generic rule for entire page */
  border-bottom-color: #1295e6;
}
.menu-right a:focus,
.branding a:focus {
  /* inverted colors for links in the header and footer */
  background-color: white;
  color: #1295e6;
}

The Trigger and the Target

The skip link has two halves. The trigger goes at the very start of the page, just inside the <header>:

<header class="content-width flex-container">
  <a href="#skip-link-target" class="text-assistive display-at-top-on-focus">Skip to main content.</a>
  <!-- etc. -->
</header>

The target goes immediately before the main content:

<a href="#skip-link-target" class="text-assistive display-at-top-on-focus" id="skip-link-target">Start of main content.</a>

<main class="content-width">
  <!-- etc. -->
</main>

The trigger's href="#skip-link-target" matches the target's id="skip-link-target", moving focus from one to the other when followed. An intermediate <a> anchor is preferable to putting the id on <main> directly: it sidesteps focus-transfer bugs in some browsers and leaves room to show the user that the jump worked. Descriptive link text on both elements explains what is happening.

Hiding It Without Breaking It

Left as-is, the link is visible to everyone. CSS should hide it until it receives focus — and the method matters:

  • Do use clip-path, or move it off screen with transform: translate or position: absolute.
  • Don't use display: none, visibility: hidden, the hidden attribute, or zero width/height — each makes the link unusable for one or both classes of keyboard user.
  • Don't use clip, which is deprecated.

clip-path with its -webkit- prefix covers 96.84% of users at time of writing, which is acceptable for most sites; WebAIM documents alternatives for cases that require more coverage.

.text-assistive {
  -webkit-clip-path: polygon(0 0, 0 0, 0 0, 0 0);
  clip-path: polygon(0 0, 0 0, 0 0, 0 0);
  box-sizing: border-box;
  position: absolute;
  margin: 0;
  padding: 0;
}

Reveal the links on focus, styled to match the branding:

.text-assistive.display-at-top-on-focus {
  top: 0;
  left: 0;
  width: 100%;  
}
.text-assistive.display-at-top-on-focus:focus {
  -webkit-clip-path: none;
  clip-path: none;
  z-index: 999;
  height: 80px;
  line-height: 80px;
  background: white;
  font-size: 1.2rem;
  text-decoration: none;
  color: #1295e6;
  text-align: center;
}
#skip-link-target:focus {
  background: #084367;
  color: white;
}

This puts a clearly visible trigger and target at the top of the page, where users expect to find keyboard focus just after load, and changes color on activation as feedback.

Skip links are not limited to the main menu. Any page with a long run of links can use them within the content itself, hiding and showing triggers and targets with transform: translateY(); the source includes standalone examples for that pattern and for supporting older browsers.