Skip to content

Instantly share code, notes, and snippets.

@treetop1500
Created February 3, 2025 19:45
Show Gist options
  • Save treetop1500/f307a4cf4b34fd90e8ca4e84be4647d5 to your computer and use it in GitHub Desktop.
Save treetop1500/f307a4cf4b34fd90e8ca4e84be4647d5 to your computer and use it in GitHub Desktop.
Hidden Skip Links
!-- HTML -->
<a href="#main-content" class="skip-link">Skip to main content</a>
<nav>
<!-- Your navigation content -->
</nav>
<main id="main-content" tabindex="-1">
<!-- Your main content -->
</main>
<!-- CSS -->
<style>
.skip-link {
/* Position the link */
position: absolute;
top: -100px;
left: 0;
z-index: 100;
/* Basic styling */
background: #ffffff;
color: #000000;
padding: 10px 20px;
text-decoration: none;
/* Ensure proper width for longer text */
width: auto;
height: auto;
margin: 0;
/* Add a border when focused */
border: 2px solid transparent;
/* Transition for smooth appearance */
transition: top 0.3s ease;
}
/* Show the link when it receives focus */
.skip-link:focus {
top: 0;
border-color: #000000;
outline: none;
}
/* Ensure main content can receive focus */
main:focus {
outline: none;
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment