UI Components Easy
Skip Navigation
Accessible skip-to-content link that appears on keyboard focus, letting screen reader and keyboard users bypass repeated navigation.
Open in Lab
MCP
css
Targets: JS HTML
Code
*,
*::before,
*::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
background: #0d1117;
color: #e6edf3;
min-height: 100vh;
}
/* Skip links — hidden until focused */
.skip-links {
position: fixed;
top: 0;
left: 0;
z-index: 9999;
display: flex;
gap: 4px;
padding: 8px;
}
.skip-link {
display: inline-block;
padding: 8px 18px;
background: #6366f1;
color: #fff;
font-size: 13px;
font-weight: 700;
border-radius: 0 0 8px 8px;
text-decoration: none;
transform: translateY(-100%);
transition: transform 0.15s ease;
border: 2px solid transparent;
}
.skip-link:focus {
transform: translateY(0);
outline: 3px solid #818cf8;
outline-offset: 2px;
}
/* Page layout */
.page-shell {
display: flex;
flex-direction: column;
min-height: 100vh;
}
/* Nav */
.demo-nav {
display: flex;
align-items: center;
gap: 24px;
padding: 14px 32px;
background: #161b22;
border-bottom: 1px solid #21262d;
flex-wrap: wrap;
}
.nav-logo {
font-size: 16px;
font-weight: 800;
color: #e6edf3;
text-decoration: none;
}
.nav-links {
display: flex;
gap: 4px;
}
.nav-link {
color: #8b949e;
text-decoration: none;
font-size: 14px;
font-weight: 500;
padding: 6px 12px;
border-radius: 7px;
transition: color 0.15s, background 0.15s;
}
.nav-link:hover {
color: #e6edf3;
background: rgba(255, 255, 255, 0.05);
}
.nav-link:focus {
outline: 2px solid #6366f1;
outline-offset: 2px;
}
.nav-search-form {
margin-left: auto;
}
.nav-search {
background: #21262d;
border: 1px solid #30363d;
border-radius: 8px;
color: #e6edf3;
font-size: 13px;
padding: 7px 12px;
outline: none;
width: 200px;
}
.nav-search:focus {
border-color: #6366f1;
outline: 2px solid rgba(99, 102, 241, 0.3);
}
/* Main */
.demo-main {
flex: 1;
max-width: 680px;
margin: 48px auto;
padding: 0 24px;
}
/* Target highlight when jumped to */
.demo-main:focus {
outline: 3px solid #6366f1;
outline-offset: 8px;
border-radius: 6px;
}
.demo-heading {
font-size: 28px;
font-weight: 800;
margin-bottom: 16px;
color: #e6edf3;
}
.demo-body {
font-size: 15px;
color: #8b949e;
line-height: 1.7;
margin-bottom: 20px;
}
kbd {
display: inline-block;
background: #21262d;
border: 1px solid #30363d;
border-bottom-width: 2px;
border-radius: 5px;
padding: 2px 7px;
font-size: 12px;
font-family: Menlo, monospace;
color: #e6edf3;
}
.demo-hint {
background: rgba(99, 102, 241, 0.1);
border: 1px solid rgba(99, 102, 241, 0.2);
border-radius: 10px;
padding: 14px 18px;
font-size: 14px;
color: #a5b4fc;
}
.demo-hint strong {
color: #c7d2fe;
}// Highlight destination landmark after skip link click
document.querySelectorAll(".skip-link").forEach((link) => {
link.addEventListener("click", () => {
const target = document.querySelector(link.getAttribute("href"));
if (target) {
target.style.transition = "outline-color 0.3s";
target.style.outline = "3px solid #6366f1";
target.style.outlineOffset = "8px";
target.style.borderRadius = "6px";
setTimeout(() => {
target.style.outline = "";
}, 1200);
}
});
});<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Skip Navigation</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<!-- Skip links — visible on focus only -->
<div class="skip-links">
<a class="skip-link" href="#main-content">Skip to main content</a>
<a class="skip-link" href="#nav">Skip to navigation</a>
<a class="skip-link" href="#search">Skip to search</a>
</div>
<div class="page-shell">
<nav class="demo-nav" id="nav">
<a href="#" class="nav-logo">Acme</a>
<div class="nav-links">
<a href="#" class="nav-link">Home</a>
<a href="#" class="nav-link">Products</a>
<a href="#" class="nav-link">Blog</a>
<a href="#" class="nav-link">About</a>
</div>
<form class="nav-search-form" id="search" role="search">
<input class="nav-search" type="search" placeholder="Search…" aria-label="Search" />
</form>
</nav>
<main class="demo-main" id="main-content" tabindex="-1">
<h1 class="demo-heading">Main Content</h1>
<p class="demo-body">Press <kbd>Tab</kbd> to reveal the skip navigation links at the top of the page. They jump keyboard users directly to key regions, bypassing repetitive navigation.</p>
<div class="demo-hint">
<strong>Try it:</strong> Click anywhere on this page and press Tab — the skip links appear at the top.
</div>
</main>
</div>
<script src="script.js"></script>
</body>
</html>Skip-to-content link that is visually hidden until focused via keyboard (Tab key), then animates into view. Targets the main content landmark, improving WCAG 2.1 SC 2.4.1 bypass-block compliance.