Generate skip navigation links for keyboard accessibility
<!-- Skip Links - Add at the very start of <body> -->
<div class="skip-links">
<a href="#main-content" class="skip-link">Skip to main content</a>
</div>.skip-links {
position: absolute;
top: 0;
left: 0;
z-index: 9999;
}
.skip-link {
position: absolute;
left: -9999px;
top: 0;
padding: 0.75rem 1.5rem;
background: #000;
color: #fff;
text-decoration: none;
font-weight: 600;
border: 2px solid #fff;
}
.skip-link:focus {
left: 0;
background: #fff;
color: #000;
border-color: #000;
outline: 3px solid #0066cc;
outline-offset: 2px;
z-index: 10000;
}Skip links help users comply with: - WCAG 2.1 Level A - 2.4.1 Bypass Blocks - Section 508 - 1194.22(o) Skip Navigation Benefits: - Keyboard users can skip repetitive navigation - Screen reader users can jump to main content quickly - Improves efficiency for power users - Required for WCAG Level A compliance
Implementation Steps:
1. Add skip links HTML at the very beginning of <body>:
<!-- Skip Links - Add at the very start of <body> -->
<div class="skip-links">
<a href="#main-content" class="skip-link">Skip to main content</a>
2. Add the CSS to your stylesheet
3. Ensure skip link targets exist and are focusable:
<main id="main-content" tabindex="-1">
4. Test:
- Press Tab key when page loads
- Skip link should be first focusable element
- Clicking skip link should move focus to target
- Target should scroll into view
5. Optional: Add smooth scroll behavior:
html {
scroll-behavior: smooth;
}<body>
<a href="#main-content" class="skip-link">
Skip to main content
</a>
<!-- Navigation, header, etc. -->
<main id="main-content" tabindex="-1">
<!-- Main content -->
</main>
</body><div class="skip-links">
<a href="#main-content">Skip to main content</a>
<a href="#navigation">Skip to navigation</a>
<a href="#search">Skip to search</a>
<a href="#footer">Skip to footer</a>
</div>.skip-link {
position: absolute;
left: -9999px;
padding: 0.75rem 1.5rem;
background: #000;
color: #fff;
}
.skip-link:focus {
left: 0;
top: 0;
z-index: 9999;
outline: 3px solid #0066cc;
}<main id="main-content" tabindex="-1">
<h1>Page Title</h1>
<!-- Main content -->
</main>
<script>
// Remove focus outline after programmatic focus
document.getElementById('main-content')
.addEventListener('blur', function() {
this.removeAttribute('tabindex');
});
</script>Help others discover this tool!