Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy
HTML

HTML: Build Accessible Navigation with Semantic Elements

- 25.07.26 - ErcanOPAK

🧭 Accessible Navigation = User-Friendly Site

Navigation is the heart of UX. Semantic HTML ensures all users can navigate your site effectively.

📝 Accessible Navigation Structure

<header role=banner>
    <div class=site-branding>
        <a href=/ aria-label=Home>
            <img src=logo.png alt=Company Logo />
            <span class=site-title>MySite</span>
        </a>
    </div>

    <nav role=navigation aria-label=Main Navigation>
        <button 
            class=menu-toggle 
            aria-expanded=false 
            aria-controls=primary-menu
        >Menu</button>
        
        <ul id=primary-menu class=menu>
            <li class=menu-item>
                <a href=/ aria-current=page>Home</a>
            </li>
            <li class=menu-item menu-item-has-children>
                <a href=/services aria-haspopup=true>
                    Services
                </a>
                <ul class=sub-menu role=menu>
                    <li><a href=/services/web-design>Web Design</a></li>
                    <li><a href=/services/development>Development</a></li>
                    <li><a href=/services/seo>SEO</a></li>
                </ul>
            </li>
            <li class=menu-item>
                <a href=/about>About</a>
            </li>
            <li class=menu-item>
                <a href=/contact>Contact</a>
            </li>
            <li class=menu-item>
                <button class=search-toggle aria-label=Search>
                    🔍
                </button>
            </li>
        </ul>
    </nav>

    <div class=search-form role=search>
        <form action=/search method=get>
            <label for=search-input>Search</label>
            <input 
                type=search 
                id=search-input 
                name=q 
                placeholder=Type to search...
                aria-describedby=search-hint
            />
            <button type=submit aria-label=Submit search>Search</button>
            <span id=search-hint class=hint>
                Press Enter to search
            </span>
        </form>
    </div>
</header>

<nav role=navigation aria-label=Breadcrumb>
    <ol class=breadcrumb>
        <li><a href=/>Home</a></li>
        <li><a href=/services>Services</a></li>
        <li aria-current=page>Web Design</li>
    </ol>
</nav>

<main role=main>
    <article>
        <h1>Page Title</h1>
        <section>
            <h2>Section Title</h2>
            <p>Content goes here...</p>
        </section>
    </article>
</main>

<footer role=contentinfo>
    <nav role=navigation aria-label=Footer Navigation>
        <ul>
            <li><a href=/privacy>Privacy Policy</a></li>
            <li><a href=/terms>Terms of Use</a></li>
            <li><a href=/sitemap>Sitemap</a></li>
        </ul>
    </nav>
    <p>© 2024 MySite. All rights reserved.</p>
</footer>

🎯 JavaScript for Accessibility

// Mobile Menu Accessibility
const menuToggle = document.querySelector(.menu-toggle);
const primaryMenu = document.getElementById(primary-menu);

menuToggle.addEventListener(click, function() {
    const expanded = this.getAttribute(aria-expanded) === true;
    this.setAttribute(aria-expanded, !expanded);
    primaryMenu.classList.toggle(active);
    document.body.classList.toggle(menu-open);
});

// Keyboard Navigation for Dropdowns
const menuItems = document.querySelectorAll(.menu-item-has-children);

menuItems.forEach(item => {
    const link = item.querySelector(a);
    const subMenu = item.querySelector(.sub-menu);
    
    link.addEventListener(keydown, function(e) {
        if (e.key === Enter || e.key ===  ) {
            e.preventDefault();
            subMenu.classList.toggle(active);
            this.setAttribute(aria-expanded, 
                subMenu.classList.contains(active)
            );
        }
    });
});

// Skip Link Implementation
document.querySelector(.skip-link).addEventListener(click, function(e) {
    e.preventDefault();
    const target = document.querySelector(this.getAttribute(href));
    target.setAttribute(tabindex, -1);
    target.focus();
});

// Focus Management for Modal/Overlay
const searchToggle = document.querySelector(.search-toggle);
const searchForm = document.querySelector(.search-form);

searchToggle.addEventListener(click, function() {
    searchForm.classList.toggle(active);
    const input = searchForm.querySelector(input);
    if (searchForm.classList.contains(active)) {
        setTimeout(() => input.focus(), 100);
    }
});

💡 Navigation Accessibility Tips

  • Use nav for all navigation sections
  • Use aria-label to distinguish multiple navs
  • Use aria-current=page for current page
  • Implement skip links for keyboard users
  • Use focus indicators for keyboard navigation

Accessible navigation is the gateway to your content. Make it work for everyone, and you will create a better experience for all users.

— UX Designer

Related posts:

HTML: Use Noscript Tag for JavaScript Fallback

HTML: Use Noscript Tag for JavaScript Fallback

HTML5 Input “step=any” — The Secret to Fix Broken Decimal Validation

HTML5 Input “step=any” — The Secret to Fix Broken Decimal Validation

HTML5: Fix a canvas Element That Renders Blurry on High-DPI Screens Because Its Pixel Size and CSS S...

HTML5: Fix a canvas Element That Renders Blurry on High-DPI Screens Because Its Pixel Size and CSS S...

Views: 8

Post navigation

CSS: Create Neumorphism with Box Shadows
JavaScript: Build Search Engine with Array Methods

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

November 2026
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
30  
« Oct    

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,055)
  • Get the User Name and Domain Name from an Email Address in SQL (980)
  • How to add default value for Entity Framework migrations for DateTime and Bool (976)
  • Get the First and Last Word from a String or Sentence in SQL (857)
  • How to select distinct rows in a datatable in C# (852)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (653)
  • Add Constraint to SQL Table to ensure email contains @ (607)
  • Average of all values in a column that are not zero in SQL (569)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (546)
  • Find numbers with more than two decimal places in SQL (475)

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit
  • SQL Server: Fix ROW_NUMBER Ties Reordering Between Identical Runs
  • C#: Fix an Enum HasFlag Returning True for the Zero Value
  • WordPress: Fix Featured Images Vanishing After a CDN Migration
  • Photoshop: Fix Content-Aware Fill Smearing a Repeating Pattern
  • Asp.Net Core: Fix Antiforgery Tokens Rejected Behind a Reverse Proxy

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,055)
  • Get the User Name and Domain Name from an Email Address in SQL (980)
  • How to add default value for Entity Framework migrations for DateTime and Bool (976)
  • Get the First and Last Word from a String or Sentence in SQL (857)
  • How to select distinct rows in a datatable in C# (852)

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com