Nav
µNav provides the responsive navigation bar via the <nav> element in µCSS. The navigation uses flexbox to distribute items, with automatic spacing and link styling. On mobile (< 640px), links collapse into a burger menu via a CSS-only checkbox hack.
Usage #
A basic responsive navigation uses <nav> with a brand <ul>, a hidden checkbox, a burger label, and a <ul class="navbar-menu"> for the links:
<nav>
<ul><li><strong>My site</strong></li></ul>
<input type="checkbox" id="my-nav" class="navbar-toggle" hidden>
<label for="my-nav" class="navbar-burger">☰</label>
<ul class="navbar-menu">
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
On desktop, the burger is hidden and links display inline (flex row). On mobile, the burger appears and links are hidden until the user clicks the burger icon. Each burger needs a unique id/for pair.
Customization variables #
| Variable | Default | Description |
|---|---|---|
--mu-nav-element-spacing-vertical |
1rem |
Vertical padding of items |
--mu-nav-element-spacing-horizontal |
0.5rem |
Horizontal padding of items |
--mu-nav-link-spacing-vertical |
0.5rem |
Vertical padding of links |
--mu-nav-link-spacing-horizontal |
0.5rem |
Horizontal padding of links |
--mu-nav-breadcrumb-divider |
">" |
Breadcrumb separator |
Active link #
Add .active to a link to bold it, indicating the current page:
<nav>
...
<ul class="navbar-menu">
<li><a href="#" class="active">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
Sticky and fixed navbars #
Use the utility classes .sticky-top, .fixed-top, or .fixed-bottom on a <nav>. When used on a nav, a z-index and box-shadow are added automatically:
<nav class="sticky-top">
<ul><li><strong>Brand</strong></li></ul>
<input type="checkbox" id="nav-s" class="navbar-toggle" hidden>
<label for="nav-s" class="navbar-burger">☰</label>
<ul class="navbar-menu">
<li><a href="#" class="active">Home</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
| Class | Behavior |
|---|---|
.sticky-top |
Stays in flow, sticks to the top on scroll (recommended for navbars) |
.fixed-top |
Always fixed to the viewport top (content flows behind, add padding-top on body) |
.fixed-bottom |
Fixed to the viewport bottom (useful for mobile action bars) |
These classes are generic utilities defined in mu.utilities.css and work on any element (e.g., sticky <thead>, sticky sidebar).
Accessibility #
- Use
<nav>as a landmark element for the main navigation. - Add
aria-labelto distinguish multiple<nav>elements on the same page (e.g.,aria-label="Main navigation"). - Links in the nav are keyboard-accessible with visible focus (outline + border-radius).
- For production use, add
aria-label="Menu"to the burger label and managearia-expandedvia JavaScript. - For breadcrumbs, use
aria-label="breadcrumb"on the<nav>(see Breadcrumb).