Mobile Navigation

This example demonstrates creating responsive mobile navigation menus including hamburger menus, slide-out panels, and accordion navigation.

Overview

Mobile navigation typically features:

  • Hamburger menu trigger

  • Slide-out or overlay panel

  • Accordion-style nested items

  • Touch-friendly interactions

  • Accessibility support

Basic Mobile Menu

HTML Structure

@using Umbraco.Community.UmbNav.Core.Models
@using Umbraco.Community.UmbNav.Core.Enums

@{
    var home = Model.Root();
    var navigation = home?.Value<IEnumerable<UmbNavItem>>("mainNavigation");
}

<!-- Mobile Header -->
<header class="mobile-header">
    <a href="@home?.Url()" class="mobile-header__logo">
        <img src="/images/logo.svg" alt="Site Logo" />
    </a>

    <button class="mobile-header__toggle"
            aria-label="Open menu"
            aria-expanded="false"
            aria-controls="mobile-nav">
        <span class="hamburger">
            <span></span>
            <span></span>
            <span></span>
        </span>
    </button>
</header>

<!-- Mobile Navigation Panel -->
<nav id="mobile-nav" class="mobile-nav" aria-label="Main navigation" hidden>
    <div class="mobile-nav__header">
        <span class="mobile-nav__title">Menu</span>
        <button class="mobile-nav__close" aria-label="Close menu">
            <span>&times;</span>
        </button>
    </div>

    <ul class="mobile-nav__list">
        @if (navigation != null)
        {
            foreach (var item in navigation)
            {
                @await Html.PartialAsync("_MobileNavItem", item, new ViewDataDictionary(ViewData) { { "CurrentPage", Model } })
            }
        }
    </ul>
</nav>

<!-- Overlay -->
<div class="mobile-nav__overlay" hidden></div>

_MobileNavItem.cshtml

CSS

JavaScript

Slide-Out Panel with Push Effect

Full-Screen Overlay Menu

Bottom Sheet Navigation

For a bottom-sheet style mobile menu:

View Component Implementation

MobileNavigationViewComponent.cs

Usage

Accessibility Best Practices

  1. Use proper ARIA attributes

    • aria-expanded for toggle buttons

    • aria-controls linking to menu IDs

    • aria-label for icon-only buttons

    • hidden attribute for hidden menus

  2. Keyboard navigation

    • Escape key closes menu

    • Tab moves through links

    • Enter/Space activates buttons

  3. Focus management

    • Focus first item when menu opens

    • Return focus to trigger when closed

    • Trap focus within open menu

  4. Screen reader support

    • Clear menu/close button labels

    • Meaningful link text

    • Status announcements

Last updated

Was this helpful?