Top nav
A translucent bar across the top of a site without a sidebar: brand, up to five links, actions. Below 760 px the links fold into a panel under the bar.
Usage
Use it when
- A marketing, landing or content site with five or fewer top-level pages and no need for a sidebar.
- A public part of a product (pricing, docs home, sign in) that sits in front of an app shell.
Use something else when
- An app with many destinations, groups or nested lessons: use App shell.
- A phone app with three to five destinations people switch between all day: use Phone bars. The tab bar sits under the thumb; a folded top menu does not.
- Sibling sections of one record or page: use Tabs.
- File, Edit, View style command menus in an editor: use Menubar.
Where it goes. The first element in <body>, sticky to the top of the viewport, full width. 60 px tall on wide screens, 56 px below 760 px, padded for the notch. Content scrolls under its material.
Examples
Prepare for the civil service exam
Scroll this box: the bar stays on top and the content passes under its material.
<header class="topnav" data-lds-topnav>
<a class="topnav__brand" href="/">Exam prep</a>
<nav class="topnav__links" id="site-links" aria-label="Main">
<a class="topnav__link" href="/courses" aria-current="page">Courses</a>
<a class="topnav__link" href="/tryouts">Tryouts</a>
<a class="topnav__link" href="/pricing">Pricing</a>
</nav>
<div class="topnav__actions">
<a class="btn btn--plain btn--md" href="/sign-in">Sign in</a>
<a class="btn btn--primary btn--md" href="/start">Start free</a>
<button class="icon-btn topnav__toggle" data-lds-topnav-toggle aria-controls="site-links" aria-expanded="false" aria-label="Menu"><span class="burger" aria-hidden="true"><i></i><i></i><i></i></span></button>
</div>
</header><div style="height: 260px; overflow: hidden; position: relative;">
<header class="topnav" data-lds-topnav>
<a class="topnav__brand" href="#tn2-body">Teacher guide</a>
<nav class="topnav__links" id="tn2-links" aria-label="Guide">
<a class="topnav__link" href="#tn2-body">Start here</a>
<a class="topnav__link" href="#tn2-body" aria-current="page">Grading</a>
<a class="topnav__link" href="#tn2-body">Reports</a>
</nav>
<div class="topnav__actions">
<button class="icon-btn topnav__toggle" data-lds-topnav-toggle aria-controls="tn2-links" aria-expanded="false" aria-label="Menu"><span class="burger" aria-hidden="true"><i></i><i></i><i></i></span></button>
</div>
</header>
<div class="stack" id="tn2-body" style="padding: 32px 20px;"><p class="section__sub">Grading: how scores are weighted and when students see them.</p></div>
</div>Anatomy
| Part | What it is |
|---|---|
.topnav[data-lds-topnav] | Required. The <header> bar; sticky, translucent material, hairline under it. |
.topnav__brand | Required. Product name or logo, a link home. |
.topnav__links | Required. A <nav aria-label> with the links; on phones it becomes the fold-out panel. |
.topnav__link | Required. One destination; aria-current="page" underlines it with a 2 px bar at the bottom of the nav bar. |
.topnav__actions | Pushed to the right: a sign in link, one primary button, an icon button. |
.topnav__toggle[data-lds-topnav-toggle] | The menu icon-btn with a .burger, shown only below 760 px. |
States
| State | How |
|---|---|
aria-current="page" | Strong text and a 2 px bar on the bottom edge of the nav bar; on phones a tinted row. |
hover | Strong text on a quiet tint, only where hover exists. |
.topnav.is-open | Below 760 px: the links panel is shown and the burger becomes a close icon. |
Motion and microinteractions
- Phone panel: enters with opacity over
--d-fastand slides 8 px down on--spring-smooth; leaves over--d-exit(180 ms) on--ease-exit, then hides. - The burger folds into a close icon on
--spring-snappy. - The bar does not hide or shrink on scroll; a jumping header costs more than the 60 px it saves.
- Reduced motion: transitions drop to 120 ms linear; reduced transparency swaps the blur for a solid material.
Accessibility
- The bar is a
<header>; the links sit in a<nav aria-label>; the current link hasaria-current="page". - The toggle has
aria-label="Menu",aria-controlsthe links id andaria-expandedkept in sync by the script. - Escape closes the panel and returns focus to the toggle; a pointer down outside closes it; following a link closes it.
- Links are 44 px tall in the phone panel.
Do and don't
Do
- Keep to five links or fewer, named with nouns people search for.
- Put one primary button at most in the actions.
- Pair with a nav progress bar if pages take long to arrive.
Don't
- Add dropdown mega menus; if the site needs them, it needs an app shell.
- Use a top nav and a sidebar together.
- Hide the brand on phones; the toggle goes at the end of the actions instead.
Behavior and code
Plain HTML. data-lds-topnav on .topnav wires the [data-lds-topnav-toggle] button: toggles .is-open and aria-expanded, closes on Escape (focus back to the toggle), on a pointer down outside and when a .topnav__link is followed.