NavigationNavbar
Searchastronomic.dev# Navbar
To build your own navbar layout: the brand, the links, the actions and utilities, with the fold into a menu, sticky and floating. For a ready layout, use NavbarSimple, NavbarCentered, NavbarStacked or NavbarBrandCenter.
Interactive: inline script.
## Usage
```astro
import Navbar from "@astronomic-dev/ui/components/Navbar.astro";
```
## Examples
### The four areas
The shell with each area filled: the brand slot, the links prop, the actions slot and the utilities slot. A site picks a recipe, such as NavbarSimple, which sets the layout. Below the md breakpoint the links fold into a menu button. In a frame, so the breakpoint is real.
```astro
---
import Button from "@astronomic-dev/ui/components/Button.astro";
import Star from "../../logos/astronomic-star.svg";
import Navbar from "@astronomic-dev/ui/components/Navbar.astro";
const links = [
{ label: "Work", href: "#work", current: true },
{ label: "Services", href: "#services" },
{ label: "About", href: "#about" },
{ label: "Journal", href: "#journal", badge: "New" },
];
---
<Navbar links={links} label="Astronomic">
<a slot="brand" href="#" class="inline-flex items-center gap-2 text-inherit no-underline">
<Star class="size-5 shrink-0" aria-hidden="true" />
Astronomic
</a>
<Button slot="actions" size="sm" tone="band" href="#start">Start a project</Button>
<a slot="utilities" href="#search" aria-label="Search" class="inline-flex size-9 items-center justify-center rounded-control text-inherit">
<svg viewBox="0 0 16 16" class="size-4" aria-hidden="true">
<circle cx="7" cy="7" r="4.75" fill="none" stroke="currentColor" stroke-width="1.5" />
<path d="M10.5 10.5L14 14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" />
</svg>
</a>
</Navbar>
```
### With a phone
The phone prop: the label over the number in the end group before the actions on wide screens, a 44px round call button with your icon below the fold point (it stays beside a CallBar there), and a "Call {number}" row in the menu. In a frame, so the fold point is real.
```astro
---
import Navbar from "@astronomic-dev/ui/components/Navbar.astro";
import Phone from "@lucide/astro/icons/phone";
import { plumbing } from "../_data/groundcrew.ts";
const links = [
{ label: "Services", href: "#services", current: true },
{ label: "Reviews", href: "#reviews" },
{ label: "Areas", href: "#areas" },
{ label: "FAQ", href: "#faq" },
];
---
<!-- Brassfield Plumbing & Drain: the number in the bar on wide screens, a round call button and a menu row on phones. -->
<Navbar links={links} actions={[{ label: "Get a quote", href: "#quote" }]} label="Brassfield" phone={{ number: plumbing.phone, label: "Call us", icon: Phone }}>
<a slot="brand" href="#" class="text-inherit no-underline">Brassfield</a>
</Navbar>
```
### The number after the links fold
phone.iconOnlyBelow="nav-phone": the links fold into the menu at lg, but the number stays in the bar down to the phone's own fold point (theme.css --breakpoint-nav-phone, md by default; set it in your theme), then shows as the 44px round call button. In a frame, so both fold points are real.
```astro
---
import Navbar from "@astronomic-dev/ui/components/Navbar.astro";
import Phone from "@lucide/astro/icons/phone";
import { plumbing } from "../_data/groundcrew.ts";
const links = [
{ label: "Services", href: "#services", current: true },
{ label: "Reviews", href: "#reviews" },
{ label: "Areas", href: "#areas" },
{ label: "FAQ", href: "#faq" },
];
---
<!-- Brassfield Plumbing & Drain: the links fold at lg, the number stays in the bar down to the phone's own fold point. -->
<Navbar links={links} actions={[{ label: "Get a quote", href: "#quote" }]} label="Brassfield" collapse="lg" phone={{ number: plumbing.phone, label: "Call us", icon: Phone, iconOnlyBelow: "nav-phone" }}>
<a slot="brand" href="#" class="text-inherit no-underline">Brassfield</a>
</Navbar>
```
### With an emergency line
The emergency slot, first in the end group at every width: here an urgent PhoneLink for the after-hours line, icon only on a phone, before the main number.
```astro
---
import Navbar from "@astronomic-dev/ui/components/Navbar.astro";
import PhoneLink from "@astronomic-dev/ui/components/PhoneLink.astro";
import Phone from "@lucide/astro/icons/phone";
import Siren from "@lucide/astro/icons/siren";
import { plumbing } from "../_data/groundcrew.ts";
const links = [
{ label: "Services", href: "#services", current: true },
{ label: "Reviews", href: "#reviews" },
{ label: "Areas", href: "#areas" },
{ label: "FAQ", href: "#faq" },
];
const line = plumbing.emergency?.phone ?? plumbing.phone;
---
<!-- The after-hours line first in the end group, at every width: an urgent PhoneLink that is icon only on a phone. -->
<Navbar links={links} actions={[{ label: "Get a quote", href: "#quote" }]} label="Brassfield" collapse="lg" phone={{ number: plumbing.phone, label: "Call us", icon: Phone }}>
<a slot="brand" href="#" class="text-inherit no-underline">Brassfield</a>
<PhoneLink slot="emergency" number={line} text="24/7 emergency" icon={Siren} urgent tone="band" iconOnlyBelow="md" />
</Navbar>
```
## Props
### Navbar
| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `links` | `NavLink[]` | None | Required. The page links. NavLink is { label, href, current?, target?, index?, badge? }: current marks the page, target "_blank" adds rel="noopener noreferrer", index is a section number, such as "1.0", shown before the label, badge is a short tag, such as "Beta", shown after it. |
| `actions` | `NavAction[]` | `[]` | Call-to-action links, on desktop (unless the `actions` slot is used) and in the menu. NavAction is { label, href, variant?, size? }; by default the last is primary, the rest ghost, and the desktop size is sm. |
| `label` | `string` | `"Main"` | Accessible name of the navigation landmark and the mobile menu. |
| `menuTitle` | `string` | `"Menu"` | Visible title of the mobile menu panel. |
| `menuText` | `string` | None | Visible words on the mobile menu's open button, such as "Menu" (MobileMenu's openText): a bordered pill in the bar's colors in place of the icon-only button. The words name the button. Off by default. |
| `menuPanel` | `"drawer" \| "card"` | `"drawer"` | The mobile menu panel's shape (MobileMenu's panel): `drawer`, a tall floating panel with the panel corners at the end of the screen; `card`, a floating card just under the bar, on its side edges, with the card corners. |
| `class` | `string` | None | More classes, merged with cn(), so yours win on conflicts. |
| `contentClass` | `string` | None | Classes for the inner row, for example a max width that matches the page container. Recipes set its layout here too. |
| `linksClass` | `string` | None | Classes for the desktop link list, for example its type size or gap. |
| `linkStyle` | `"plain" \| "rule"` | `"plain"` | Desktop link look: a color change, or a straight bottom rule on hover and on the current page (square corners, and a square focus ring). |
| `collapse` | `"md" \| "lg"` | `"md"` | Below which fold point the links fold into the menu button: md is 768 pixels, lg is 1024. Use lg when the links, actions and utilities need more room. A theme moves either one with --breakpoint-nav-md or --breakpoint-nav-lg in its own @theme (after the kit's theme.css), for example --breakpoint-nav-lg: 1100px; the bar, the recipes' layouts, the menu's loading and the sticky inset all follow. |
| `areaOrder` | `"brand-links-end" \| "links-brand-end" \| "brand-end-links"` | `"brand-links-end"` | For recipes. The order of the brand, the links and the end group in the markup, so the Tab order follows the layout: links-brand-end for the brand in the middle, brand-end-links for the links on a row under the rest. Below the fold point the links are hidden, so the order is the brand, the end group, the menu button either way. |
| `sticky` | `boolean` | `false` | Keeps the bar at the top of the window as the page scrolls, above the page content and below the open menu. It keeps the bar's background and blur. The page gets scroll-padding-top (--ui-nav-offset, default 6rem, or 7rem when floating), so in-page jumps and focused elements land below the bar. No script. |
| `floating` | `boolean` | `false` | Sets the bar in from the page edges, with the card corner radius, edge and shadow, and no bottom rule. The page shows around it. Where a preset has no shadow, the edge alone marks it. With sticky, it sticks with that gap above it. |
| `shrink` | `boolean` | `false` | With floating: once the page scrolls a little, the bar narrows to the width its content needs (the brand, the links and the actions, with no empty space between them), centered, and widens again at the top. It implies sticky. Only above the fold point (collapse); below it the bar keeps its width. The header's height never changes, so the page does not move. A small script animates the width (no animation under reduced motion); without it the bar is sticky at its normal width. Ignored without floating. |
| `roll` | `boolean` | `false` | Each link label, in the bar and in the menu, rolls up on hover and keyboard focus and the same words roll in from below (the text-roll utility). Only the label rolls: the index and the badge stay put. Read once. Still under reduced motion and the theme's calm setting (data-motion="calm"), and a hover counts only on a device that hovers. |
| `phone` | `NavPhone` | None | A number to call. NavPhone is { number, label?, icon, callText?, iconOnlyBelow? }: a PhoneLink in the end group before the actions, at every width (the label over the number above the fold point, a 44px round link with your icon below it, named the same), and a "Call {number}" row at the end of the menu (callText sets its words, {number} filled in by the number as written; the words name the row link, so keep the number in them). iconOnlyBelow sets where the bar phone folds: unset, with the links (collapse); "nav-phone", at theme.css --breakpoint-nav-phone (md by default; your theme sets it), so the number stays after the links fold. The icon is required. Off by default. |
| `brandClass` | `string` | None | For recipes. Classes for the brand wrapper. |
| `endClass` | `string` | None | For recipes. Classes for the end group, which holds the actions and the utilities and shows at every width. |
| Slot | Description |
| --- | --- |
| `brand` | The logo or site name: at the start of the bar, or after the links with areaOrder="links-brand-end" (at the start again below the fold point). |
| `actions` | Your own actions, in place of the actions buttons on desktop. The mobile menu shows it too when actions is empty. Buttons you put here should pass tone="band", so they take the band colors under a band preset. |
| `emergency` | First in the end group, at every width: an emergency line, such as a PhoneLink with urgent. Pass tone="band" and iconOnlyBelow to match the bar. |
| `utilities` | Extra controls after the actions, shown at every width, such as a theme switch. |
| `menu` | More for the mobile menu panel, after the actions, with or without them: a control that sits in the bar on wider screens but has no room there on a narrow phone, such as a theme switch with visible text below 360px. Show each copy at its own widths with your classes. It may hold a part with a script. Without JavaScript the panel cannot open, so it is not shown: keep anything that must work with no script in the bar. |
Any other attribute goes on the <header>.
## Accessibility
| Key | Action |
| --- | --- |
| Tab | Moves through the brand, the links and the actions |
| Enter | Follows the focused link |
- A <header> holds a <nav> named by label (default "Main").
- The link with current set gets aria-current="page".
- Below the md breakpoint the links and actions move into MobileMenu, a native dialog with a small script. Without JavaScript the menu button is hidden and the links show as a row of their own under the brand.
- Put a link with text or alt text in the brand slot, so the brand has a name.
- With sticky, in-page jumps and focused elements land below the bar: the kit sets scroll-padding-top on a page with a sticky bar, 6rem, or 7rem when it floats. A site with a taller bar sets --ui-nav-offset to its height.
- With phone, the number is one link named "Call (614) 555-0147", or by its label and the number ("Call us: (614) 555-0147"), at every width; below the fold point it is a 44px round link with the icon only, and the menu ends with a "Call {number}" row named by its words.
- With shrink, the bar only changes width: the Tab order, the focus ring and the open menu (which covers the bar) stay the same, and under reduced motion or the calm setting it switches with no animation.
Navbar
FreeTo build your own navbar layout: the brand, the links, the actions and utilities, with the fold into a menu, sticky and floating. For a ready layout, use NavbarSimple, NavbarCentered, NavbarStacked or NavbarBrandCenter.
- File
- Navbar.astro
- Group
- Navigation
- Kind
- Interactive: inline script
- Examples
- 4
Examples
Drag the orange handle to set the width. Frames get real breakpoints.
- Static
- Interactive
- Framed
The four areas
The shell with each area filled: the brand slot, the links prop, the actions slot and the utilities slot. A site picks a recipe, such as NavbarSimple, which sets the layout. Below the md breakpoint the links fold into a menu button. In a frame, so the breakpoint is real.
With a phone
The phone prop: the label over the number in the end group before the actions on wide screens, a 44px round call button with your icon below the fold point (it stays beside a CallBar there), and a "Call {number}" row in the menu. In a frame, so the fold point is real.
The number after the links fold
phone.iconOnlyBelow="nav-phone": the links fold into the menu at lg, but the number stays in the bar down to the phone's own fold point (theme.css --breakpoint-nav-phone, md by default; set it in your theme), then shows as the 44px round call button. In a frame, so both fold points are real.
With an emergency line
The emergency slot, first in the end group at every width: here an urgent PhoneLink for the after-hours line, icon only on a phone, before the main number.