Accessibility
a11y/skip-link
Pages with repeated header or navigation start with a "Skip to main content" link whose target exists and takes focus.
moderatebrowserWCAG 2.4.1 · Afe-a11y-keyboard
Why
Without a way past the header, a keyboard user presses Tab through every navigation link on every page before reaching the content. Landmarks help screen reader users, but sighted keyboard users need the link.
Fix
Make the first focusable element of the layout <a href="#main" class="skip-link">Skip to main content</a>, give <main id="main" tabindex="-1">, and show the link when it has focus (visually hidden until :focus). Put it in the shared layout, not per page.
Examples
<!-- bad: the first Tab stop is the logo, then 30 menu links -->
<header><a href="/">Logo</a><nav>…</nav></header>
<!-- good -->
<a class="skip-link" href="#main">Skip to main content</a>
<header>…</header>
<main id="main" tabindex="-1">…</main>Sources
Facts
- Id
a11y/skip-link- Severity
- moderate
- Check
- browser needs a rendered page:
audit --url - Applies to
page- WCAG 2.2
- 2.4.1, level A
- Same problem in
- axe-core
bypass, axe-coreskip-link - Taught by the skill
fe-a11y-keyboardKeyboard access and focus- Since version
- 0.1.0
Read it in the terminal
npx github:dawidolko/frontend-skills explain a11y/skip-link