Search every page in the navigation.
Site navigation with grouped links and text-only states, for docs and marketing rails.
import {
Nav,
NavGroup,
NavGroupLabel,
NavItem,
NavLink,
NavList,
} from "@/components/ui/nav"
const groups = [
{
label: "Getting started",
items: ["Introduction", "Installation", "Theming"],
},
{
label: "Components",
items: ["Button", "Input", "Nav", "Select"],
},
]
export default function NavDemo() {
return (
<Nav aria-label="Docs" className="w-56">
{groups.map((group) => (
<NavGroup key={group.label}>
<NavGroupLabel>{group.label}</NavGroupLabel>
<NavList>
{group.items.map((item) => (
<NavItem key={item}>
<NavLink href="#" active={item === "Nav"}>
{item}
</NavLink>
</NavItem>
))}
</NavList>
</NavGroup>
))}
</Nav>
)
}npx shadcn@latest add @ziiz/navimport {
Nav,
NavGroup,
NavGroupLabel,
NavItem,
NavLink,
NavList,
} from "@/components/ui/nav"<Nav aria-label="Docs">
<NavGroup>
<NavGroupLabel>Components</NavGroupLabel>
<NavList>
<NavItem>
<NavLink href="/components/button" active>
Button
</NavLink>
</NavItem>
</NavList>
</NavGroup>
</Nav>Use the following composition to build a Nav:
Nav
โโโ NavHeader
โโโ NavContent
โ โโโ NavGroup
โ โโโ NavGroupLabel
โ โโโ NavList
โ โโโ NavItem
โ โ โโโ NavLink
โ โโโ NavCollapsible
โ โโโ NavCollapsibleTrigger
โ โโโ NavCollapsibleContent
โ โโโ NavSub
โ โโโ NavSubItem
โ โโโ NavLink
โโโ NavFooterNavHeader, NavContent and NavFooter are for a rail with something pinned above or below its links. A plain list of groups needs none of them.
Nav is a website's navigation: a list of pages whose states are text only: secondary at rest, primary on hover and when current, never a fill. Use it for docs, marketing and help-center rails.
Sidebar is an application shell: it collapses to icons, becomes a sheet on mobile, remembers its open state and carries menu actions. Use it when the rail is part of the app, not a table of contents.
Wrap a section in NavCollapsible to open its pages in place. A hairline runs down the left of the nested list.
import {
Nav,
NavCollapsible,
NavCollapsibleContent,
NavCollapsibleTrigger,
NavItem,
NavLink,
NavList,
NavSub,
NavSubItem,
} from "@/components/ui/nav"
const sections = [
{ title: "Introduction" },
{ title: "Basics", items: ["Overview", "Why X", "Getting started"] },
{
title: "Advertising",
items: ["Overview", "Best practices", "Measurement"],
},
{ title: "Resources" },
]
export default function NavCollapsibleExample() {
return (
<Nav aria-label="Sections" className="w-56">
<NavList>
{sections.map((section) =>
section.items ? (
<NavCollapsible
key={section.title}
defaultOpen={section.title === "Advertising"}
>
<NavCollapsibleTrigger>{section.title}</NavCollapsibleTrigger>
<NavCollapsibleContent>
<NavSub>
{section.items.map((item) => (
<NavSubItem key={item}>
<NavLink href="#" active={item === "Best practices"}>
{item}
</NavLink>
</NavSubItem>
))}
</NavSub>
</NavCollapsibleContent>
</NavCollapsible>
) : (
<NavItem key={section.title}>
<NavLink href="#">{section.title}</NavLink>
</NavItem>
)
)}
</NavList>
</Nav>
)
}Pin content above and below the links. NavContent takes the remaining height and scrolls on its own.
import { Button } from "@/components/ui/button"
import {
Nav,
NavContent,
NavFooter,
NavHeader,
NavItem,
NavLink,
NavList,
} from "@/components/ui/nav"
const pages = [
"Overview",
"Deployments",
"Analytics",
"Logs",
"Storage",
"Domains",
"Integrations",
"Usage",
"Settings",
]
export default function NavRail() {
return (
<div className="h-96 w-60 rounded-md border border-gray-alpha-400">
<Nav aria-label="Project" className="h-full gap-4 p-4">
<NavHeader>
<span className="px-2.5 text-heading-16 text-gray-1000">Acme</span>
</NavHeader>
<NavContent>
<NavList>
{pages.map((page) => (
<NavItem key={page}>
<NavLink href="#" active={page === "Overview"}>
{page}
</NavLink>
</NavItem>
))}
</NavList>
</NavContent>
<NavFooter>
<Button shape="rounded" variant="outline" size="sm" className="w-fit">
Sign In
</Button>
</NavFooter>
</Nav>
</div>
)
}size="lg" is the same list one type role louder: the full-screen menu that carries every page on mobile.
import {
Nav,
NavGroup,
NavGroupLabel,
NavItem,
NavLink,
NavList,
} from "@/components/ui/nav"
export default function NavSize() {
return (
<Nav size="lg" aria-label="Docs" className="w-72">
<NavGroup>
<NavGroupLabel>Foundation</NavGroupLabel>
<NavList>
{["Colors", "Typography", "Materials"].map((item) => (
<NavItem key={item}>
<NavLink href="#" active={item === "Typography"}>
{item}
</NavLink>
</NavItem>
))}
</NavList>
</NavGroup>
</Nav>
)
}marker on a NavList puts a small square before the current link. There is one square for the list: when another link becomes current, it slides there. Use it where the current row changes in place, such as a filter list.
"use client"
import * as React from "react"
import { Nav, NavItem, NavLink, NavList } from "@/components/ui/nav"
const filters = [
"All",
"Best practices",
"Inspiration",
"Product updates",
"Solutions",
"Trends & insights",
]
export default function NavMarker() {
const [current, setCurrent] = React.useState("All")
return (
<Nav aria-label="Categories" className="w-56">
<NavList marker>
{filters.map((filter) => (
<NavItem key={filter}>
<NavLink
active={filter === current}
render={<button type="button" />}
onClick={() => setCurrent(filter)}
>
{filter}
</NavLink>
</NavItem>
))}
</NavList>
</Nav>
)
}NavLink renders an <a>. Pass a router link through render, and mark the current page with active.
import Link from "next/link"
import { usePathname } from "next/navigation"
export function DocsNavLink({ href, children }) {
const pathname = usePathname()
return (
<NavLink active={pathname === href} render={<Link href={href} />}>
{children}
</NavLink>
)
}Nav an aria-label when a page has more than one navigation landmark.active sets aria-current="page", so the current page is announced, not only shown in a darker color. The marker follows aria-current and is hidden from assistive technology.NavCollapsibleTrigger is a real <button> with aria-expanded; Enter and Space toggle it.The root <nav> element.
| Prop | Type | Default | Description |
|---|---|---|---|
size | "default" | "lg" | "default" | lg sets every part one type role louder. |
The list of rows. Renders a <ul>.
| Prop | Type | Default | Description |
|---|---|---|---|
marker | boolean | false | Marks the current link with a square that slides between rows. |
A group heading. Renders a <div>; pass render to use a heading element.
| Prop | Type | Default | Description |
|---|---|---|---|
render | React.ReactElement | Replaces the rendered element. |
A navigation row. Renders an <a>.
| Prop | Type | Default | Description |
|---|---|---|---|
active | boolean | false | Marks the current page and sets aria-current. |
render | React.ReactElement | Replaces the rendered element, e.g. a router link. |
A section that opens in place. Renders an <li>, so it sits directly in a NavList. Accepts the Base UI Collapsible root props, including open, defaultOpen and onOpenChange.
The section's row and its panel. They accept the Base UI Collapsible trigger and panel props. The panel animates its height and respects reduced motion.