Navbar
The bar at the top of a page, which takes its material once content scrolls under it.
On this page
A navbar is the bar at the top of a page or an app: the brand, the main links and a few actions. At the top of the page it has no material at all, so the page starts as one surface. Once content scrolls under it, the bar becomes a pane of frosted glass with a hairline and a short shadow. A scroll-state container query knows when the sticky bar is stuck; no script watches the scroll.
Navbar
<div class="h(280) overflow-y-auto"> <header class="navbar"> <a class="navbar-brand" href="#"> <svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <circle cx="12" cy="12" r="8" /> <path d="M12 4a8 8 0 0 0 0 16" /> </svg>Atlas</a> <nav class="navbar-nav" aria-label="Main"> <a class="navbar-link" href="#" aria-current="page">Overview</a> <a class="navbar-link" href="#">Projects</a> <a class="navbar-link" href="#">Docs</a> </nav> <div class="navbar-end"> <button class="btn btn-quiet btn-square btn-sm navbar-toggle" aria-label="Open the menu"> <svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M4 8h16M4 16h16" /> </svg> </button> <button class="btn btn-sm">Sign in</button> <button class="btn btn-primary btn-sm">Get started</button> </div> </header> <div class="grid gap-sm p-md"> <div class="sheet p-lg text-sm">Scroll this box.</div> <div class="sheet p-lg text-sm">The bar has no material at the top.</div> <div class="sheet p-lg text-sm">Once content is under it, it becomes a pane.</div> <div class="sheet p-lg text-sm">A hairline and a short shadow part it from the page.</div> <div class="sheet p-lg text-sm">Scroll back and it lets go.</div> </div></div>The bar is position: sticky at the top of its scroll container, which is the page in most layouts. Where the browser has no scroll-state queries, the pane is always drawn.
The navbar is the bar itself: its material, its stuck state and the width at which its links step aside. What goes around it is not its business. For a whole site header, with a menu, a second action and a drawer, copy the header block; to place the bar in a page with a sidebar, see the app shell layout.
#Narrow bars
The bar is also a size container. Below 36rem of bar, navbar-nav steps aside and navbar-toggle appears; at 36rem and above it is the other way round. Point the toggle at a drawer or a menu that holds the same links.
Narrow
<div class="max-w(380) mx-auto"> <header class="navbar"> <a class="navbar-brand" href="#">Atlas</a> <nav class="navbar-nav" aria-label="Main"> <a class="navbar-link" href="#" aria-current="page">Overview</a> <a class="navbar-link" href="#">Projects</a> </nav> <div class="navbar-end"> <button class="btn btn-primary btn-sm">Get started</button> <button class="btn btn-quiet btn-square btn-sm navbar-toggle" popovertarget="navbar-menu" aria-label="Open the menu"> <svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M4 8h16M4 16h16" /> </svg> </button> <div class="menu menu-end" id="navbar-menu" popover> <a class="menu-item" href="#">Overview</a> <a class="menu-item" href="#">Projects</a> <a class="menu-item" href="#">Deployments</a> <a class="menu-item" href="#">Docs</a> </div> </div> </header></div>#Floating
navbar-floating lifts the bar off the edge: a margin around it, the corner of a surface and its material from the start. Use it over a page with a strong first screen.
Floating
<div class="h(260) overflow-y-auto bg-surface-tray"> <header class="navbar navbar-floating"> <a class="navbar-brand ml-xs" href="#">Atlas</a> <nav class="navbar-nav" aria-label="Main"> <a class="navbar-link" href="#" aria-current="page">Overview</a> <a class="navbar-link" href="#">Projects</a> <a class="navbar-link" href="#">Docs</a> </nav> <div class="navbar-end"> <button class="btn btn-primary btn-sm">Get started</button> </div> </header> <div class="grid gap-sm p-md"> <div class="sheet p-lg text-sm">Scroll this box.</div> <div class="sheet p-lg text-sm">The bar has no material at the top.</div> <div class="sheet p-lg text-sm">Once content is under it, it becomes a pane.</div> <div class="sheet p-lg text-sm">A hairline and a short shadow part it from the page.</div> <div class="sheet p-lg text-sm">Scroll back and it lets go.</div> </div></div>#Reading progress
Put a navbar-progress inside the bar and a hairline of ink along its foot fills as the page scrolls. It is driven by a scroll timeline on the root scroller, so it shows the progress of the page, and it is drawn only where the browser supports scroll-driven animations.
<header class="navbar"> … <div class="navbar-progress" role="presentation"></div></header>#Accessibility
- Use a
<header>for the bar and a<nav>with a label for the links. Mark the current page witharia-current="page": it is the only thing that puts a link in ink. - The toggle is an ordinary button. Opened by
popovertargetorcommand, its menu or drawer needs no script. - The pane is decoration. With
prefers-reduced-transparencyit is opaque, and in forced colors it is the canvas with a line under it. - A sticky bar covers the top of the page. Set
scroll-padding-topon the scroller to the bar's height, so a link to a heading does not land under it.
#Classes
| Class | Description |
|---|---|
navbar | The sticky bar, on a header; a size and scroll-state container named navbar. It has no material until content scrolls under it |
navbar-floating | A bar with a margin around it, a surface corner and its material from the start. With navbar |
navbar-brand | The mark and the name, as one link home; it also stands alone at the head of a shell or a sidebar |
navbar-nav | The row of main links, on a nav with a label; hidden below 36rem of bar |
navbar-link | A link or a button in the row: a word at rest, on a chip under the pointer |
navbar-end | The actions at the far end |
navbar-toggle | On the button that opens the links in a menu or a drawer; shown only while navbar-nav is hidden |
navbar-progress | A reading-progress line along the foot of the bar, which fills as the page scrolls; give it role="presentation" |
#Custom properties
| Property | Default | Description |
|---|---|---|
--navbar-height | 3.5rem | The bar's minimum height |
--navbar-padding-x | 1rem | Inline padding |
--navbar-color | var(--color-surface-base) | The color the pane is tinted with; match the page behind it |
#Related
- PageA header, the main region and a footer in a frame as tall as the viewport.
- App shellA sidebar that stays while the main region scrolls, and a drawer when it is narrow.