NavigationNavbarSimple
Searchastronomic.dev# NavbarSimple
At the top of every page: the brand, the links right after it, and the actions at the end.
Interactive: inline script.
## Usage
```astro
import NavbarSimple from "@astronomic-dev/ui/components/NavbarSimple.astro";
```
## Examples
### Links and actions
The brand, the links right after it and the actions at the end. Below the md breakpoint the links fold into a menu button. In a frame, so the breakpoint is real.
```astro
---
import NavbarSimple from "@astronomic-dev/ui/components/NavbarSimple.astro";
import Star from "../../logos/astronomic-star.svg";
const links = [
{ label: "Work", href: "#work", current: true },
{ label: "Services", href: "#services" },
{ label: "About", href: "#about" },
{ label: "Journal", href: "#journal", badge: "New" },
];
const actions = [
{ label: "Sign in", href: "#sign-in", variant: "ghost" as const },
{ label: "Start a project", href: "#start", variant: "primary" as const },
];
---
<NavbarSimple links={links} actions={actions} 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>
</NavbarSimple>
```
### Your own actions
The actions slot replaces the action buttons, on desktop and in the menu.
```astro
---
import Button from "@astronomic-dev/ui/components/Button.astro";
import NavbarSimple from "@astronomic-dev/ui/components/NavbarSimple.astro";
import Star from "../../logos/astronomic-star.svg";
const links = [
{ label: "Work", href: "#work" },
{ label: "Journal", href: "#journal", current: true },
];
---
<NavbarSimple 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>
<Fragment slot="actions">
<Button size="sm" variant="secondary" tone="band" href="#subscribe">Subscribe</Button>
</Fragment>
</NavbarSimple>
```
### At every width
In a frame, so the md breakpoint is real. Set the width to 390 and open the menu.
```astro
---
import NavbarSimple from "@astronomic-dev/ui/components/NavbarSimple.astro";
import Star from "../../logos/astronomic-star.svg";
const links = [
{ label: "Work", href: "#work", current: true },
{ label: "Services", href: "#services" },
{ label: "About", href: "#about" },
];
const actions = [{ label: "Start a project", href: "#start" }];
---
<div class="min-h-[28rem]">
<NavbarSimple links={links} actions={actions} 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>
</NavbarSimple>
<p class="m-0 max-w-[40ch] px-6 py-12 text-muted">Below 768 pixels (1024 with collapse="lg"; a theme can move both) the links fold into the menu button.</p>
</div>
```
### Sticky
With sticky the bar stays at the top as the page scrolls. The kit gives the page scroll-padding-top, so in-page jumps (each note links to itself) and focused links land below the bar, with nothing set on the page. In a frame of fixed height: scroll inside it.
```astro
---
import NavbarSimple from "@astronomic-dev/ui/components/NavbarSimple.astro";
import Star from "../../logos/astronomic-star.svg";
const links = [
{ label: "Work", href: "#work", current: true },
{ label: "Services", href: "#services" },
{ label: "About", href: "#about" },
];
const actions = [{ label: "Start a project", href: "#start" }];
const notes = ["Brand and identity", "Websites", "Writing", "Photography", "Workshops", "Support"];
---
<div>
<NavbarSimple sticky links={links} actions={actions} 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>
</NavbarSimple>
<div class="mx-auto grid max-w-[60ch] gap-6 px-6 py-12">
<p class="m-0 text-muted">Scroll the frame: the bar stays at the top, and the page runs under it.</p>
{
notes.map((note) => (
<div data-sticky-note id={note.toLowerCase().replaceAll(" ", "-")} class="grid min-h-48 content-end rounded-card bg-surface-2 p-6">
<p class="m-0 font-semibold">
<a href={`#${note.toLowerCase().replaceAll(" ", "-")}`} class="text-inherit no-underline hover:underline">{note}</a>
</p>
</div>
))
}
<p class="m-0"><a href="#" class="text-inherit">Back to the top</a></p>
</div>
</div>
```
### Floating
With floating the bar sits in from the edges, with the card corners, edge and shadow, and no bottom rule.
```astro
---
import NavbarSimple from "@astronomic-dev/ui/components/NavbarSimple.astro";
import Star from "../../logos/astronomic-star.svg";
const links = [
{ label: "Work", href: "#work", current: true },
{ label: "Services", href: "#services" },
{ label: "About", href: "#about" },
];
const actions = [{ label: "Start a project", href: "#start" }];
---
<div class="bg-surface-2">
<NavbarSimple floating links={links} actions={actions} 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>
</NavbarSimple>
<p class="m-0 max-w-[48ch] px-6 pt-6 pb-12 text-muted">The bar sits in from the edges, with the card corners, edge and shadow, and the page shows around it.</p>
</div>
```
### Sticky and floating
Both: the bar sticks with a gap above it, and the page beside it takes clicks. In a frame of fixed height: scroll inside it.
```astro
---
import NavbarSimple from "@astronomic-dev/ui/components/NavbarSimple.astro";
import Star from "../../logos/astronomic-star.svg";
const links = [
{ label: "Work", href: "#work", current: true },
{ label: "Services", href: "#services" },
{ label: "About", href: "#about" },
];
const actions = [{ label: "Start a project", href: "#start" }];
const notes = ["Brand and identity", "Websites", "Writing", "Photography", "Workshops", "Support"];
---
<div>
<NavbarSimple sticky floating links={links} actions={actions} 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>
</NavbarSimple>
<div class="grid gap-2 py-6">
<p class="m-0 px-6 pb-4 text-muted">Scroll the frame: the bar sticks with a gap above it, and the page shows, and takes clicks, around it.</p>
{
notes.map((note) => (
<div data-sticky-note class="grid min-h-48 content-end bg-surface-2 p-6">
<p class="m-0 font-semibold">{note}</p>
</div>
))
}
<p class="m-0 px-6 py-6"><a href="#" class="text-inherit">Back to the top</a></p>
</div>
</div>
```
### Rolling links
With roll, each link label rolls up on hover and keyboard focus and the same words roll in from below, in the bar and in the menu. It stays still under reduced motion and the calm setting. In a frame, so the breakpoint is real.
```astro
---
import NavbarSimple from "@astronomic-dev/ui/components/NavbarSimple.astro";
import Star from "../../logos/astronomic-star.svg";
// roll: each link label rolls on hover and keyboard focus, in the bar and in the menu.
const links = [
{ label: "Work", href: "#work", current: true },
{ label: "Services", href: "#services" },
{ label: "About", href: "#about" },
{ label: "Journal", href: "#journal" },
];
const actions = [{ label: "Start a project", href: "#start" }];
---
<NavbarSimple roll links={links} actions={actions} 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>
</NavbarSimple>
```
### Shrink on scroll
With floating and shrink the bar sticks, and once the page scrolls it narrows to its content, centered, with no empty space between the brand, the links and the actions. Back at the top it widens again. Above the md breakpoint only, and with no animation under reduced motion. In a frame of fixed height: scroll inside it.
```astro
---
import NavbarSimple from "@astronomic-dev/ui/components/NavbarSimple.astro";
import Star from "../../logos/astronomic-star.svg";
const links = [
{ label: "Work", href: "#work", current: true },
{ label: "Services", href: "#services" },
{ label: "About", href: "#about" },
];
const actions = [{ label: "Start a project", href: "#start" }];
const notes = ["Brand and identity", "Websites", "Writing", "Photography", "Workshops", "Support"];
---
<div>
<NavbarSimple floating shrink links={links} actions={actions} 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>
</NavbarSimple>
<div class="grid gap-2 py-6">
<p class="m-0 px-6 pb-4 text-muted">Scroll the frame: the bar sticks, and narrows to its content, centered. Back at the top it widens again.</p>
{
notes.map((note) => (
<div data-sticky-note class="grid min-h-48 content-end bg-surface-2 p-6">
<p class="m-0 font-semibold">{note}</p>
</div>
))
}
<p class="m-0 px-6 py-6"><a href="#" class="text-inherit">Back to the top</a></p>
</div>
</div>
```
## Props
### NavbarSimple
| 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. Merged after the recipe's layout with cn(), so yours win at the same breakpoint: to override a recipe's layout class, use the fold point's own prefix (nav-md: or nav-lg:, as collapse), which moves with the fold. |
| `linksClass` | `string` | None | Classes for the desktop link list, for example its type size, weight, gap or color. Merged after the recipe's own with cn(), so yours win at the same breakpoint: to override a recipe's layout class, use the fold point's own prefix (nav-md: or nav-lg:, as collapse), which moves with the fold. |
| `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. |
| `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. |
| Slot | Description |
| --- | --- |
| `brand` | The logo or site name, at the start of the bar. |
| `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. |
| `utilities` | Extra controls after the actions, shown at every width, such as a theme switch. |
| `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. |
| `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.
NavbarSimple
FreeAt the top of every page: the brand, the links right after it, and the actions at the end.
- File
- NavbarSimple.astro
- Group
- Navigation
- Kind
- Interactive: inline script
- Examples
- 8
Examples
Drag the orange handle to set the width. Frames get real breakpoints.
- Static
- Interactive
- Framed
Links and actions
The brand, the links right after it and the actions at the end. Below the md breakpoint the links fold into a menu button. In a frame, so the breakpoint is real.
Your own actions
The actions slot replaces the action buttons, on desktop and in the menu.
At every width
In a frame, so the md breakpoint is real. Set the width to 390 and open the menu.
Sticky
With sticky the bar stays at the top as the page scrolls. The kit gives the page scroll-padding-top, so in-page jumps (each note links to itself) and focused links land below the bar, with nothing set on the page. In a frame of fixed height: scroll inside it.
Floating
With floating the bar sits in from the edges, with the card corners, edge and shadow, and no bottom rule.
Sticky and floating
Both: the bar sticks with a gap above it, and the page beside it takes clicks. In a frame of fixed height: scroll inside it.
Rolling links
With roll, each link label rolls up on hover and keyboard focus and the same words roll in from below, in the bar and in the menu. It stays still under reduced motion and the calm setting. In a frame, so the breakpoint is real.
Shrink on scroll
With floating and shrink the bar sticks, and once the page scrolls it narrows to its content, centered, with no empty space between the brand, the links and the actions. Back at the top it widens again. Above the md breakpoint only, and with no animation under reduced motion. In a frame of fixed height: scroll inside it.