Components
- Accordion
- Alert
- Alert Dialog
- Aspect Ratio
- Attachment
- Avatar
- Badge
- Breadcrumb
- Bubble
- Button
- Button Group
- Calendar
- Card
- Carousel
- Chart
- Checkbox
- Code Block
- Collapsible
- Combobox
- Command
- Context Menu
- Data Table
- Date Picker
- Dialog
- Direction
- Drawer
- Dropdown Menu
- Empty
- Field
- Hover Card
- Input
- Input Group
- Input OTP
- Item
- Kbd
- Label
- Marker
- Menubar
- Message
- Message Scroller
- Native Select
- Navigation Menu
- Pagination
- Popover
- Progress
- Questionnaire
- Radio Group
- Resizable
- Scroll Area
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Toast
- Toggle
- Toggle Group
- Tooltip
- Trace
- Typography
AI Elements
Get Started
@shadcn/react
@shadcn/helpers
Utilities
"use client"
import * as React from "react""use client"
import * as React from "react"
import Link from "next/link"
import {
CircleAlertIcon,
CircleCheckIcon,
CircleDashedIcon,
} from "lucide-react"
import {
NavigationMenu,
NavigationMenuContent,
NavigationMenuItem,
NavigationMenuLink,
NavigationMenuList,
NavigationMenuTrigger,
navigationMenuTriggerStyle,
} from "@/components/ui/navigation-menu"
const components: { title: string; href: string; description: string }[] = [
{
title: "Alert Dialog",
href: "/docs/primitives/alert-dialog",
description:
"A modal dialog that interrupts the user with important content and expects a response.",
},
{
title: "Hover Card",
href: "/docs/primitives/hover-card",
description:
"For sighted users to preview content available behind a link.",
},
{
title: "Progress",
href: "/docs/primitives/progress",
description:
"Displays an indicator showing the completion progress of a task, typically displayed as a progress bar.",
},
{
title: "Scroll-area",
href: "/docs/primitives/scroll-area",
description: "Visually or semantically separates content.",
},
{
title: "Tabs",
href: "/docs/primitives/tabs",
description:
"A set of layered sections of content—known as tab panels—that are displayed one at a time.",
},
{
title: "Tooltip",
href: "/docs/primitives/tooltip",
description:
"A popup that displays information related to an element when the element receives keyboard focus or the mouse hovers over it.",
},
]
export function NavigationMenuDemo() {
return (
<NavigationMenu>
<NavigationMenuList>
<NavigationMenuItem>
<NavigationMenuTrigger>Getting started</NavigationMenuTrigger>
<NavigationMenuContent>
<ul className="w-96">
<ListItem href="/docs" title="Introduction">
Re-usable components built with Tailwind CSS.
</ListItem>
<ListItem href="/docs/installation" title="Installation">
How to install dependencies and structure your app.
</ListItem>
<ListItem href="/docs/primitives/typography" title="Typography">
Styles for headings, paragraphs, lists...etc
</ListItem>
</ul>
</NavigationMenuContent>
</NavigationMenuItem>
<NavigationMenuItem className="hidden md:flex">
<NavigationMenuTrigger>Components</NavigationMenuTrigger>
<NavigationMenuContent>
<ul className="grid w-[400px] gap-2 md:w-[500px] md:grid-cols-2 lg:w-[600px]">
{components.map((component) => (
<ListItem
key={component.title}
title={component.title}
href={component.href}
>
{component.description}
</ListItem>
))}
</ul>
</NavigationMenuContent>
</NavigationMenuItem>
<NavigationMenuItem>
<NavigationMenuTrigger>With Icon</NavigationMenuTrigger>
<NavigationMenuContent>
<ul className="grid w-[200px]">
<li>
<NavigationMenuLink render={<Link href="#" className="flex-row items-center gap-2"><CircleAlertIcon />Backlog</Link>} />
<NavigationMenuLink render={<Link href="#" className="flex-row items-center gap-2"><CircleDashedIcon />To Do</Link>} />
<NavigationMenuLink render={<Link href="#" className="flex-row items-center gap-2"><CircleCheckIcon />Done</Link>} />
</li>
</ul>
</NavigationMenuContent>
</NavigationMenuItem>
<NavigationMenuItem>
<NavigationMenuLink className={navigationMenuTriggerStyle()} render={<Link href="/docs">Docs</Link>} />
</NavigationMenuItem>
</NavigationMenuList>
</NavigationMenu>
)
}
function ListItem({
title,
children,
href,
...props
}: React.ComponentPropsWithoutRef<"li"> & { href: string }) {
return (
<li {...props}>
<NavigationMenuLink render={<Link href={href}><div className="flex flex-col gap-1 text-sm">
<div className="leading-none font-medium">{title}</div>
<div className="line-clamp-2 text-muted-foreground">{children}</div>
</div></Link>} />
</li>
)
}
Installation#
pnpm dlx shadcn@latest add navigation-menu
Install the following dependencies:
pnpm add @base-ui/react
Copy and paste the following code into your project.
import { NavigationMenu as NavigationMenuPrimitive } from "@base-ui/react/navigation-menu"
import { cva } from "class-variance-authority"
import { cn } from "cn"
import { ChevronDownIcon } from "lucide-react"
function NavigationMenu({
align = "start",
className,
children,
...props
}: NavigationMenuPrimitive.Root.Props &
Pick<NavigationMenuPrimitive.Positioner.Props, "align">) {
return (
<NavigationMenuPrimitive.Root
data-slot="navigation-menu"
className={cn(
"group/navigation-menu relative flex max-w-max flex-1 items-center justify-center",
className
)}
{...props}
>
{children}
<NavigationMenuPositioner align={align} />
</NavigationMenuPrimitive.Root>
)
}
function NavigationMenuList({
className,
...props
}: React.ComponentPropsWithRef<typeof NavigationMenuPrimitive.List>) {
return (
<NavigationMenuPrimitive.List
data-slot="navigation-menu-list"
className={cn(
"group flex flex-1 list-none items-center justify-center gap-0",
className
)}
{...props}
/>
)
}
function NavigationMenuItem({
className,
...props
}: React.ComponentPropsWithRef<typeof NavigationMenuPrimitive.Item>) {
return (
<NavigationMenuPrimitive.Item
data-slot="navigation-menu-item"
className={cn("relative", className)}
{...props}
/>
)
}
const navigationMenuTriggerStyle = cva(
"group/navigation-menu-trigger inline-flex h-9 w-max items-center justify-center rounded-lg px-2.5 py-1.5 text-sm font-medium transition-all outline-none hover:bg-muted focus:bg-muted focus-visible:ring-3 focus-visible:ring-ring/50 focus-visible:outline-1 disabled:pointer-events-none disabled:opacity-50 data-popup-open:bg-muted/50 data-popup-open:hover:bg-muted data-open:bg-muted/50 data-open:hover:bg-muted data-open:focus:bg-muted"
)
function NavigationMenuTrigger({
className,
children,
...props
}: NavigationMenuPrimitive.Trigger.Props) {
return (
<NavigationMenuPrimitive.Trigger
data-slot="navigation-menu-trigger"
className={cn(navigationMenuTriggerStyle(), "group", className)}
{...props}
>
{children}{" "}
<ChevronDownIcon
className="relative top-px ml-1 size-3 transition duration-300 group-data-popup-open/navigation-menu-trigger:rotate-180 group-data-open/navigation-menu-trigger:rotate-180"
aria-hidden="true"
/>
</NavigationMenuPrimitive.Trigger>
)
}
function NavigationMenuContent({
className,
...props
}: NavigationMenuPrimitive.Content.Props) {
return (
<NavigationMenuPrimitive.Content
data-slot="navigation-menu-content"
className={cn(
"data-ending-style:data-activation-direction=left:translate-x-[50%] data-ending-style:data-activation-direction=right:translate-x-[-50%] data-starting-style:data-activation-direction=left:translate-x-[-50%] data-starting-style:data-activation-direction=right:translate-x-[50%] h-full w-auto p-1 transition-[opacity,transform,translate] duration-[0.35s] ease-[cubic-bezier(0.22,1,0.36,1)] group-data-[viewport=false]/navigation-menu:rounded-lg group-data-[viewport=false]/navigation-menu:bg-popover group-data-[viewport=false]/navigation-menu:text-popover-foreground group-data-[viewport=false]/navigation-menu:shadow group-data-[viewport=false]/navigation-menu:ring-1 group-data-[viewport=false]/navigation-menu:ring-foreground/10 group-data-[viewport=false]/navigation-menu:duration-300 data-ending-style:opacity-0 data-starting-style:opacity-0 data-[motion=from-end]:slide-in-from-right-52 data-[motion=from-start]:slide-in-from-left-52 data-[motion=to-end]:slide-out-to-right-52 data-[motion=to-start]:slide-out-to-left-52 data-[motion^=from-]:animate-in data-[motion^=from-]:fade-in data-[motion^=to-]:animate-out data-[motion^=to-]:fade-out **:data-[slot=navigation-menu-link]:focus:ring-0 **:data-[slot=navigation-menu-link]:focus:outline-none group-data-[viewport=false]/navigation-menu:data-open:animate-in group-data-[viewport=false]/navigation-menu:data-open:fade-in-0 group-data-[viewport=false]/navigation-menu:data-open:zoom-in-95 group-data-[viewport=false]/navigation-menu:data-closed:animate-out group-data-[viewport=false]/navigation-menu:data-closed:fade-out-0 group-data-[viewport=false]/navigation-menu:data-closed:zoom-out-95",
className
)}
{...props}
/>
)
}
function NavigationMenuPositioner({
className,
side = "bottom",
sideOffset = 8,
align = "start",
alignOffset = 0,
...props
}: NavigationMenuPrimitive.Positioner.Props) {
return (
<NavigationMenuPrimitive.Portal>
<NavigationMenuPrimitive.Positioner
side={side}
sideOffset={sideOffset}
align={align}
alignOffset={alignOffset}
className={cn(
"isolate z-50 h-(--positioner-height) w-(--positioner-width) max-w-(--available-width) transition-[top,left,right,bottom] duration-[0.35s] ease-[cubic-bezier(0.22,1,0.36,1)] data-instant:transition-none data-[side=bottom]:before:top-[-10px] data-[side=bottom]:before:right-0 data-[side=bottom]:before:left-0",
className
)}
{...props}
>
<NavigationMenuPrimitive.Popup className="data-[ending-style]:easing-[ease] xs:w-(--popup-width) relative h-(--popup-height) w-(--popup-width) origin-(--transform-origin) rounded-lg bg-popover text-popover-foreground shadow ring-1 ring-foreground/10 transition-[opacity,transform,width,height,scale,translate] duration-[0.35s] ease-[cubic-bezier(0.22,1,0.36,1)] outline-none data-ending-style:scale-90 data-ending-style:opacity-0 data-ending-style:duration-150 data-starting-style:scale-90 data-starting-style:opacity-0">
<NavigationMenuPrimitive.Viewport className="relative size-full overflow-hidden" />
</NavigationMenuPrimitive.Popup>
</NavigationMenuPrimitive.Positioner>
</NavigationMenuPrimitive.Portal>
)
}
function NavigationMenuLink({
className,
...props
}: NavigationMenuPrimitive.Link.Props) {
return (
<NavigationMenuPrimitive.Link
data-slot="navigation-menu-link"
className={cn(
"flex items-center gap-2 rounded-lg p-2 text-sm transition-all outline-none hover:bg-muted focus:bg-muted focus-visible:ring-3 focus-visible:ring-ring/50 focus-visible:outline-1 in-data-[slot=navigation-menu-content]:rounded-md data-active:bg-muted/50 data-active:hover:bg-muted data-active:focus:bg-muted [&_svg:not([class*='size-'])]:size-4",
className
)}
{...props}
/>
)
}
function NavigationMenuIndicator({
className,
...props
}: React.ComponentPropsWithRef<typeof NavigationMenuPrimitive.Icon>) {
return (
<NavigationMenuPrimitive.Icon
data-slot="navigation-menu-indicator"
className={cn(
"top-full z-1 flex h-1.5 items-end justify-center overflow-hidden data-[state=hidden]:animate-out data-[state=hidden]:fade-out data-[state=visible]:animate-in data-[state=visible]:fade-in",
className
)}
{...props}
>
<div className="relative top-[60%] h-2 w-2 rotate-45 rounded-tl-sm bg-border shadow-md" />
</NavigationMenuPrimitive.Icon>
)
}
export {
NavigationMenu,
NavigationMenuContent,
NavigationMenuIndicator,
NavigationMenuItem,
NavigationMenuLink,
NavigationMenuList,
NavigationMenuTrigger,
navigationMenuTriggerStyle,
NavigationMenuPositioner,
}
Update the import paths to match your project setup.
Usage#
import {
NavigationMenu,
NavigationMenuContent,
NavigationMenuItem,
NavigationMenuLink,
NavigationMenuList,
NavigationMenuTrigger,
} from "@/components/ui/navigation-menu"<NavigationMenu>
<NavigationMenuList>
<NavigationMenuItem>
<NavigationMenuTrigger>Item One</NavigationMenuTrigger>
<NavigationMenuContent>
<NavigationMenuLink>Link</NavigationMenuLink>
</NavigationMenuContent>
</NavigationMenuItem>
</NavigationMenuList>
</NavigationMenu>Composition#
Use the following composition to build a NavigationMenu:
NavigationMenu
├── NavigationMenuList
│ ├── NavigationMenuItem
│ │ ├── NavigationMenuTrigger
│ │ └── NavigationMenuContent
│ │ ├── NavigationMenuLink
│ │ └── NavigationMenuLink
│ └── NavigationMenuItem
│ └── NavigationMenuLink
└── NavigationMenuIndicatorLink Component#
Use the render prop to compose a custom link component such as Next.js Link.
import Link from "next/link"
import {
NavigationMenuItem,
NavigationMenuLink,
navigationMenuTriggerStyle,
} from "@/components/ui/navigation-menu"
export function NavigationMenuDemo() {
return (
<NavigationMenuItem>
<NavigationMenuLink
render={<Link href="/docs" />}
className={navigationMenuTriggerStyle()}
>
Documentation
</NavigationMenuLink>
</NavigationMenuItem>
)
}RTL#
To enable RTL support in shadcn/ui, see the RTL configuration guide.
"use client"
import * as React from "react"// You will notice this example uses dir and data-lang attributes. // This is because this site is not RTL by default. // In your application, you won't need these.// See the RTL guide for more information.
"use client"
import * as React from "react"
import Link from "next/link"
import {
CircleAlertIcon,
CircleCheckIcon,
CircleDashedIcon,
} from "lucide-react"
import {
useTranslation,
type Translations,
} from "@/components/language-selector"
import {
NavigationMenu,
NavigationMenuContent,
NavigationMenuItem,
NavigationMenuLink,
NavigationMenuList,
NavigationMenuTrigger,
navigationMenuTriggerStyle,
} from "@/components/ui/navigation-menu"
const translations: Translations = {
en: {
dir: "ltr",
values: {
gettingStarted: "Getting started",
introduction: "Introduction",
introductionDesc: "Re-usable components built with Tailwind CSS.",
installation: "Installation",
installationDesc: "How to install dependencies and structure your app.",
typography: "Typography",
typographyDesc: "Styles for headings, paragraphs, lists...etc",
components: "Components",
alertDialog: "Alert Dialog",
alertDialogDesc:
"A modal dialog that interrupts the user with important content and expects a response.",
hoverCard: "Hover Card",
hoverCardDesc:
"For sighted users to preview content available behind a link.",
progress: "Progress",
progressDesc:
"Displays an indicator showing the completion progress of a task, typically displayed as a progress bar.",
scrollArea: "Scroll-area",
scrollAreaDesc: "Visually or semantically separates content.",
tabs: "Tabs",
tabsDesc:
"A set of layered sections of content—known as tab panels—that are displayed one at a time.",
tooltip: "Tooltip",
tooltipDesc:
"A popup that displays information related to an element when the element receives keyboard focus or the mouse hovers over it.",
withIcon: "With Icon",
backlog: "Backlog",
toDo: "To Do",
done: "Done",
docs: "Docs",
},
},
ar: {
dir: "rtl",
values: {
gettingStarted: "البدء",
introduction: "مقدمة",
introductionDesc:
"مكونات قابلة لإعادة الاستخدام مبنية باستخدام Tailwind CSS.",
installation: "التثبيت",
installationDesc: "كيفية تثبيت التبعيات وتنظيم تطبيقك.",
typography: "الطباعة",
typographyDesc: "أنماط للعناوين والفقرات والقوائم...إلخ",
components: "المكونات",
alertDialog: "حوار التنبيه",
alertDialogDesc: "حوار نافذة يقطع المستخدم بمحتوى مهم ويتوقع استجابة.",
hoverCard: "بطاقة التحويم",
hoverCardDesc: "للمستخدمين المبصرين لمعاينة المحتوى المتاح خلف الرابط.",
progress: "التقدم",
progressDesc:
"يعرض مؤشرًا يوضح تقدم إتمام المهمة، عادةً يتم عرضه كشريط تقدم.",
scrollArea: "منطقة التمرير",
scrollAreaDesc: "يفصل المحتوى بصريًا أو دلاليًا.",
tabs: "التبويبات",
tabsDesc:
"مجموعة من أقسام المحتوى المتعددة الطبقات—المعروفة بألواح التبويب—التي يتم عرضها واحدة في كل مرة.",
tooltip: "تلميح",
tooltipDesc:
"نافذة منبثقة تعرض معلومات متعلقة بعنصر عندما يتلقى العنصر التركيز على لوحة المفاتيح أو عند تحويم الماوس فوقه.",
withIcon: "مع أيقونة",
backlog: "قائمة الانتظار",
toDo: "المهام",
done: "منجز",
docs: "الوثائق",
},
},
he: {
dir: "rtl",
values: {
gettingStarted: "התחלה",
introduction: "הקדמה",
introductionDesc: "רכיבים לשימוש חוזר שנבנו עם Tailwind CSS.",
installation: "התקנה",
installationDesc: "כיצד להתקין תלויות ולבנות את האפליקציה שלך.",
typography: "טיפוגרפיה",
typographyDesc: "סגנונות לכותרות, פסקאות, רשימות...וכו'",
components: "רכיבים",
alertDialog: "דיאלוג התראה",
alertDialogDesc: "דיאלוג מודאלי שמפריע למשתמש עם תוכן חשוב ומצפה לתגובה.",
hoverCard: "כרטיס ריחוף",
hoverCardDesc:
"למשתמשים רואים כדי להציג תצוגה מקדימה של תוכן זמין מאחורי קישור.",
progress: "התקדמות",
progressDesc:
"מציג אינדיקטור המציג את התקדמות ההשלמה של משימה, בדרך כלל מוצג כסרגל התקדמות.",
scrollArea: "אזור גלילה",
scrollAreaDesc: "מפריד תוכן חזותית או סמנטית.",
tabs: "כרטיסיות",
tabsDesc:
"קבוצה של חלקי תוכן מרובדים—המכונים לוחות כרטיסיות—המוצגים אחד בכל פעם.",
tooltip: "טולטיפ",
tooltipDesc:
"חלון קופץ המציג מידע הקשור לאלמנט כאשר האלמנט מקבל מיקוד מקלדת או כאשר העכבר מרחף מעליו.",
withIcon: "עם אייקון",
backlog: "רשימת המתנה",
toDo: "לעשות",
done: "הושלם",
docs: "תיעוד",
},
},
}
const components = [
{
titleKey: "alertDialog" as const,
descriptionKey: "alertDialogDesc" as const,
href: "/docs/primitives/alert-dialog",
},
{
titleKey: "hoverCard" as const,
descriptionKey: "hoverCardDesc" as const,
href: "/docs/primitives/hover-card",
},
{
titleKey: "progress" as const,
descriptionKey: "progressDesc" as const,
href: "/docs/primitives/progress",
},
{
titleKey: "scrollArea" as const,
descriptionKey: "scrollAreaDesc" as const,
href: "/docs/primitives/scroll-area",
},
{
titleKey: "tabs" as const,
descriptionKey: "tabsDesc" as const,
href: "/docs/primitives/tabs",
},
{
titleKey: "tooltip" as const,
descriptionKey: "tooltipDesc" as const,
href: "/docs/primitives/tooltip",
},
] as const
export function NavigationMenuRtl() {
const { dir, t, language } = useTranslation(translations, "ar")
return (
<NavigationMenu dir={dir} align={dir === "rtl" ? "end" : "start"}>
<NavigationMenuList>
<NavigationMenuItem>
<NavigationMenuTrigger>{t.gettingStarted}</NavigationMenuTrigger>
<NavigationMenuContent
dir={dir}
data-lang={dir === "rtl" ? language : undefined}
>
<ul className="w-96">
<ListItem href="/docs" title={t.introduction}>
{t.introductionDesc}
</ListItem>
<ListItem href="/docs/installation" title={t.installation}>
{t.installationDesc}
</ListItem>
<ListItem href="/docs/primitives/typography" title={t.typography}>
{t.typographyDesc}
</ListItem>
</ul>
</NavigationMenuContent>
</NavigationMenuItem>
<NavigationMenuItem className="hidden md:flex">
<NavigationMenuTrigger>{t.components}</NavigationMenuTrigger>
<NavigationMenuContent
dir={dir}
data-lang={dir === "rtl" ? language : undefined}
>
<ul className="grid w-[400px] gap-2 md:w-[500px] md:grid-cols-2 lg:w-[600px]">
{components.map((component) => (
<ListItem
key={component.titleKey}
title={t[component.titleKey]}
href={component.href}
>
{t[component.descriptionKey]}
</ListItem>
))}
</ul>
</NavigationMenuContent>
</NavigationMenuItem>
<NavigationMenuItem>
<NavigationMenuTrigger>{t.withIcon}</NavigationMenuTrigger>
<NavigationMenuContent
dir={dir}
data-lang={dir === "rtl" ? language : undefined}
>
<ul className="grid w-[200px]">
<li>
<NavigationMenuLink render={<Link href="#" className="flex-row items-center gap-2"><CircleAlertIcon />{t.backlog}</Link>} />
<NavigationMenuLink render={<Link href="#" className="flex-row items-center gap-2"><CircleDashedIcon />{t.toDo}</Link>} />
<NavigationMenuLink render={<Link href="#" className="flex-row items-center gap-2"><CircleCheckIcon />{t.done}</Link>} />
</li>
</ul>
</NavigationMenuContent>
</NavigationMenuItem>
<NavigationMenuItem>
<NavigationMenuLink className={navigationMenuTriggerStyle()} data-lang={dir === "rtl" ? language : undefined} render={<Link href="/docs">{t.docs}</Link>} />
</NavigationMenuItem>
</NavigationMenuList>
</NavigationMenu>
)
}
function ListItem({
title,
children,
href,
...props
}: React.ComponentPropsWithoutRef<"li"> & { href: string }) {
return (
<li {...props}>
<NavigationMenuLink render={<Link href={href}><div className="flex flex-col gap-1 text-sm">
<div className="leading-none font-medium">{title}</div>
<div className="line-clamp-2 text-muted-foreground">{children}</div>
</div></Link>} />
</li>
)
}
API Reference#
See the Base UI Navigation Menu documentation for more information.
Deploy your shadcn/ui app on Vercel
Trusted by OpenAI, Sonos, Adobe, and more.
Vercel provides tools and infrastructure to deploy apps and features at scale.
Deploy to Vercel