Navigation
Sidebars, top bars, tab bars, and section menus for React built with the Nav components, with collapsible sections, current-page indicators, badges, and thumbnails.
Examples
Overview
These examples build navigation with the Ariakit UI Nav components. Most examples show only the navigation, with placeholders where the rest of the page would be. The Accordion Sections and Top Bar examples use the Shell components to show full pages. Open them in a new tab and resize the window to see how they adapt.
The gallery includes a list of links, a list with a brand selection, a top bar, course lessons, a workspace sidebar, a sidebar with collapsible sections and thumbnails, an API reference, a music library, repository tabs, a feed with links in a segmented control, numbered steps on a guide, a page tree on a guide, and a settings sidebar with compact rows.
Components
Nav renders a navigation landmark with a list of NavLink rows. Set $layout="horizontal" for a row that scrolls when the links need more room. The row hides its scrollbar, and its links fade at each end while more links lie that way. With a fine pointer, “Scroll backward” and “Scroll forward” buttons show beside the row, outside the navigation landmark, so the reading and Tab order of the links stay the same. A wrapper holds the navigation and the buttons, paints the surface and the edge of the navigation, and takes className and style. buttons={false} removes the buttons, and previousButton and nextButton take props, such as $forceRounded for round buttons in the Tabs with Counts example. The current link keeps its own surface. Pass bar to also mark it with a thin bar, or bar={{ $offset: "halfway" }} to center it between the link and the navigation edge. Set bar on a NavLink to override the default for that link.
When the current link changes without a page load, such as with a client-side router, the bar travels from the old link to the new one. The bar that travels is inside the Nav, so a horizontal Nav that scrolls clips it, and the links keep taking clicks. When a scroll area inside the Nav, such as the open section of a filled NavDisclosureGroup, hides the old or the new bar, the bar changes at once. With reduced motion or forced colors, the bar changes at once too.
Set aria-current="page" on the current NavLink, or pass currentUrl to compare it with the href. Put an icon, badge, avatar, shortcut, or thumbnail in a NavSlot, and the text in a NavLinkLabel. In a horizontal row, the current link uses the normal weight unless it gets its plain text through text, as in <NavLink text="Overview" />, or through <NavLinkLabel text="Issues" /> beside slots. The label then reserves the width of the heavier text, so the current link turns heavier without moving the links after it. Wrap a label and a NavLinkDescription in NavLinkContent to show secondary text below or beside the label.
Set $kind="segmented" on a horizontal Nav and on its NavLink elements to show the links as a segmented control, as in the Segmented Links with an Inverted Thumb example. The current link is the selected segment, and the links stay in a navigation landmark. Set $invert on the links to invert only the current one.
A Nav is a list of links, so it takes the row props of a List. $itemPadding sets the padding of every link and group label at once, as in the Compact Rows example. $gap sets the space between two rows, and $groupGap the space between two groups.
Set ordered on the Nav to render an ordered list and number its top-level links, as in the Numbered Steps on a Guide example. The numbers are the counters of a List. They sit in a gutter before the links, so the surface of a link does not cover them. $markerSize sets their size, and the marker prop of Nav and NavLink takes NavLinkMarker props, such as a color.
Set $guide to smooth, diagonal, or rail to join the links with a guide. For nested links that always show, put a NavLink and a NavList in a NavItem. The guide bends into the nested list, and $indent sets how far the nested links move in. Set ordered on a nested NavList to number its links, or $marker="bullet" to draw a dot on the guide at each of them, as in the Nested Links on a Bending Guide example. $bulletSize sets the size of the dots. The guide prop of Nav and NavLink takes NavLinkGuide props, such as an edge color or a line style. The markers and the guide need a vertical Nav, and they don’t join the rows of a NavDisclosure.
With a guide, the bar of a link draws on the guide and follows its bends, and the marker of the link fills with the bar color. When the current link changes without a page load, the bar glides along the guide to the new current link. Set $markerHighlight="ring" to light up a ring around the marker instead, and $barWidth to set the thickness of the bar. A bar with $side="end", or with a number as its $offset, stays off the guide. For a bar that follows the scroll position of a page, use the Toc components, which make the same bar cover the rows of the sections on screen.
NavGroup and NavGroupLabel put rows under a small heading. Set $divider on a group to draw a line before it, or $uppercase on a label to show it in small uppercase letters. NavDisclosure shows nested rows in a collapsible section. NavDisclosureGroup puts sections in a shared frame with dividers. Set $fill on the group and on the Nav in a sidebar, and the open section takes the height that the closed sections leave and scrolls its own rows.
Accessibility
Give each Nav a name with aria-label or aria-labelledby, because a page can have more than one navigation landmark. A Nav inside a Nav landmark or a ShellSidebar with landmark="nav" renders a div, so the rows don’t repeat the landmark around them. Leave that Nav without a name, because a name keeps its own landmark. When the landmark around it renders outside the React tree, such as an Astro sidebar around an island, set landmark={false} on the Nav.
A NavLinkDescription becomes the accessible description of its link, so the label and the slots name the link and the description adds detail. A link that shows only an icon still needs a name.