//navigation
Navigation Menu
A site header menu whose panels open on hover or click and slide between each other, for product, docs and resource links. Copy-paste ready.
// title: Marketing mega menu with icon cards and a featured link
import {
BarChart3Icon,
BookOpenIcon,
type LucideIcon,
MailIcon,
NewspaperIcon,
ShieldCheckIcon,
WorkflowIcon,
ZapIcon,
} from "lucide-react";
import {
NavigationMenu,
NavigationMenuContent,
NavigationMenuItem,
NavigationMenuLink,
NavigationMenuList,
NavigationMenuTrigger,
} from "@/components/ui/navigation-menu";
type Entry = {
title: string;
description: string;
icon: LucideIcon;
href: string;
};
const PRODUCTS: Entry[] = [
{
description: "Dashboards and funnels in real time.",
href: "#analytics",
icon: BarChart3Icon,
title: "Analytics",
},
{
description: "Trigger flows from any event.",
href: "#automations",
icon: WorkflowIcon,
title: "Automations",
},
{
description: "Campaigns that send themselves.",
href: "#email",
icon: MailIcon,
title: "Email",
},
{
description: "SSO, audit logs and roles.",
href: "#security",
icon: ShieldCheckIcon,
title: "Security",
},
];
const RESOURCES: Entry[] = [
{
description: "Guides and API reference.",
href: "#docs",
icon: BookOpenIcon,
title: "Documentation",
},
{
description: "Product news and stories.",
href: "#blog",
icon: NewspaperIcon,
title: "Blog",
},
{
description: "What shipped this week.",
href: "#changelog",
icon: ZapIcon,
title: "Changelog",
},
];
function EntryLink({ entry }: { entry: Entry }) {
return (
<NavigationMenuLink className="flex-row gap-3" href={entry.href}>
<span className="flex size-8 shrink-0 items-center justify-center rounded-md border bg-background">
<entry.icon aria-hidden="true" className="size-4 opacity-80" />
</span>
<span className="flex flex-col gap-0.5">
<span className="font-medium">{entry.title}</span>
<span className="text-muted-foreground text-xs">
{entry.description}
</span>
</span>
</NavigationMenuLink>
);
}
export default function Particle() {
return (
<NavigationMenu>
<NavigationMenuList>
<NavigationMenuItem>
<NavigationMenuTrigger>Products</NavigationMenuTrigger>
<NavigationMenuContent>
<ul className="grid gap-1 sm:w-[30rem] sm:grid-cols-2">
{PRODUCTS.map((entry) => (
<li key={entry.title}>
<EntryLink entry={entry} />
</li>
))}
</ul>
</NavigationMenuContent>
</NavigationMenuItem>
<NavigationMenuItem>
<NavigationMenuTrigger>Resources</NavigationMenuTrigger>
<NavigationMenuContent>
<div className="grid gap-2 sm:w-[32rem] sm:grid-cols-[1fr_12rem]">
<ul className="grid gap-1">
{RESOURCES.map((entry) => (
<li key={entry.title}>
<EntryLink entry={entry} />
</li>
))}
</ul>
<NavigationMenuLink
className="justify-end gap-1 bg-muted/60 p-4"
href="#state-of-ui"
>
<span className="text-muted-foreground text-xs">Report</span>
<span className="font-medium">State of UI 2026</span>
<span className="text-muted-foreground text-xs">
What 4,000 teams told us about their design systems.
</span>
</NavigationMenuLink>
</div>
</NavigationMenuContent>
</NavigationMenuItem>
<NavigationMenuItem>
<NavigationMenuLink href="#pricing" variant="trigger">
Pricing
</NavigationMenuLink>
</NavigationMenuItem>
</NavigationMenuList>
</NavigationMenu>
);
}
Installation
pnpm dlx shadcn@latest add @cnippet/navigation-menu
Usage
import {
NavigationMenu,
NavigationMenuContent,
NavigationMenuItem,
NavigationMenuLink,
NavigationMenuList,
NavigationMenuTrigger,
} from "@/components/ui/navigation-menu"<NavigationMenu>
<NavigationMenuList>
<NavigationMenuItem>
<NavigationMenuTrigger>Products</NavigationMenuTrigger>
<NavigationMenuContent>
<NavigationMenuLink href="/analytics">
<span className="font-medium">Analytics</span>
<span className="text-muted-foreground text-xs">Dashboards in real time.</span>
</NavigationMenuLink>
</NavigationMenuContent>
</NavigationMenuItem>
<NavigationMenuItem>
<NavigationMenuLink href="/pricing" variant="trigger">
Pricing
</NavigationMenuLink>
</NavigationMenuItem>
</NavigationMenuList>
</NavigationMenu>Anatomy
<NavigationMenu> {/* root; also renders the shared popup */}
<NavigationMenuList>
<NavigationMenuItem>
<NavigationMenuTrigger /> {/* opens this item's content; chevron included */}
<NavigationMenuContent> {/* rendered inside the popup when open */}
<NavigationMenuLink />
</NavigationMenuContent>
</NavigationMenuItem>
<NavigationMenuItem>
<NavigationMenuLink variant="trigger" /> {/* a top-level link with no panel */}
</NavigationMenuItem>
</NavigationMenuList>
</NavigationMenu>Good to know
- All items share one popup. Moving between triggers resizes it and slides the content left or right, depending on which way you moved.
- Triggers open on hover and on click. Arrow keys move between triggers, and Tab moves into the open panel.
- Give each content panel a width from
sm:up (the examples usesm:w-[30rem]). On small screens it fills the viewport minus 2rem. NavigationMenuLinkdefaults to a block link for use inside a panel. Usevariant="trigger"for a top-level link that matches the triggers. Passactiveto mark the current page.- On phones, swap the menu for a Sheet or Drawer with the same links.
API Reference
NavigationMenu
Takes all Base UI NavigationMenu.Root props (value, defaultValue, onValueChange, delay, closeDelay, orientation), plus:
| Prop | Type | Default | Description |
|---|---|---|---|
sideOffset | number | 8 | Gap between the triggers and the popup |
align | "start" | "center" | "end" | "start" | How the popup lines up with the active trigger |
NavigationMenuLink
| Prop | Type | Default | Description |
|---|---|---|---|
variant | "content" | "trigger" | "content" | Block link inside a panel, or a top-level link |
active | boolean | — | Marks the current page (aria-current="page") |
Other parts take their Base UI props. See the Base UI docs.
Examples
Docs menu
Sections of a docs site, with a two-column panel for the longer list.
// title: Docs menu with sections and a plain link
import {
NavigationMenu,
NavigationMenuContent,
NavigationMenuItem,
NavigationMenuLink,
NavigationMenuList,
NavigationMenuTrigger,
} from "@/components/ui/navigation-menu";
const SECTIONS = {
Components: [
["Button", "Actions, links and icon buttons."],
["Dialog", "Modal windows for focused tasks."],
["Stepper", "Progress through multi-step flows."],
["Tag Input", "Free-form tags with validation."],
["Sidebar", "Collapsible app navigation."],
["File Upload", "Drag-and-drop with previews."],
],
"Getting started": [
["Introduction", "What Cnippet is and how it works."],
["Installation", "Add it to a Next.js or Vite app."],
["Theming", "Tokens, dark mode and custom colors."],
],
} as const;
export default function Particle() {
return (
<NavigationMenu>
<NavigationMenuList>
{Object.entries(SECTIONS).map(([section, pages]) => (
<NavigationMenuItem key={section}>
<NavigationMenuTrigger>{section}</NavigationMenuTrigger>
<NavigationMenuContent>
<ul
className={
pages.length > 3
? "grid gap-1 sm:w-[28rem] sm:grid-cols-2"
: "grid gap-1 sm:w-72"
}
>
{pages.map(([title, description]) => (
<li key={title}>
<NavigationMenuLink
href={`#${title.toLowerCase().replace(/\s+/g, "-")}`}
>
<span className="font-medium">{title}</span>
<span className="text-muted-foreground text-xs">
{description}
</span>
</NavigationMenuLink>
</li>
))}
</ul>
</NavigationMenuContent>
</NavigationMenuItem>
))}
<NavigationMenuItem>
<NavigationMenuLink href="#github" variant="trigger">
GitHub
</NavigationMenuLink>
</NavigationMenuItem>
</NavigationMenuList>
</NavigationMenu>
);
}