Skip navigation links

Description:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Accessible Skip Navigation Link Example</title>
    <style>
        /* Skip link styling - hidden by default, visible on focus */
        .skip-link {
            position: absolute;
            top: -40px;
            left: 10px;
            background-color: #005fcc;
            color: #ffffff;
            padding: 10px;
            z-index: 1000;
            text-decoration: none;
            font-size: 1em;
            border-radius: 5px;
        }
        .skip-link:focus {
            top: 10px;
            outline: 2px solid #ffbf00; /* High contrast outline */
        }
        /* Basic styles for layout */
        header, nav, main, footer {
            padding: 20px;
            margin: 20px 0;
        }
        /* Example content for product listings */
        .product-listing {
            padding: 10px;
            border: 1px solid #ddd;
        }
    </style>
</head>
<body>
    <!-- Skip Link for Quick Access to Product Listings -->
    <a href="#product-listings" class="skip-link">Skip to Product Listings</a>
    <!-- Page Header -->
    <header>
        <h1>Online Store</h1>
        <p>Welcome to our online store. Browse our categories and find the best products for you.</p>
    </header>
    <!-- Navigation Menu -->
    <nav aria-label="Main Navigation">
        <ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">Categories</a></li>
            <li><a href="#">Deals</a></li>
            <li><a href="#">Contact</a></li>
        </ul>
    </nav>
    <!-- Main Content Area -->
    <main>
        <section aria-labelledby="product-listings">
            <h2 id="product-listings">Product Listings</h2>
            <div class="product-listing">Product 1 - $10</div>
            <div class="product-listing">Product 2 - $20</div>
            <div class="product-listing">Product 3 - $30</div>
        </section>
    </main>
    <!-- Footer -->
    <footer>
        <p>© 2023 Online Store. All rights reserved.</p>
    </footer>
</body>
</html>

Explanation #

  1. Skip Link Styling:
    • The skip link is positioned off-screen by default but moves into view when focused (top: 10px).
    • A high-contrast background (#005fcc for blue) and text color (#ffffff for white) make the link clearly visible when focused.
    • A contrasting outline (#ffbf00 for yellow) is added on focus to further enhance visibility, ensuring that keyboard users can locate the link.
  2. Skip Link Functionality:
    • The skip link (<a href="#product-listings" class="skip-link">Skip to Product Listings</a>) points directly to the product listings section using the href="#product-listings" attribute.
    • When activated, the link jumps to the <h2 id="product-listings">Product Listings</h2> header, making the product listings immediately accessible.
  3. Accessible Structure with ARIA:
    • An aria-label is used on the navigation <nav> to help screen readers identify the navigation section as the main menu.
    • The <section> containing the product listings uses aria-labelledby="product-listings" to associate it with the header. This adds clarity for screen reader users by linking the heading to the main content of the section.
  • Keyboard Accessibility: Users who navigate by keyboard can skip over repetitive content (like the header and navigation) and jump directly to the product listings.
  • Screen Reader Compatibility: Screen reader users receive an option to skip straight to the main content, reducing unnecessary announcements of navigation links.
  • Enhanced Usability: All users, including those with visual impairments, can access the primary content more efficiently.

What are your feelings

Updated on March 6, 2025