Navigation Menu
A collection of links and menus for website navigation.
Anatomy
<NavigationMenu.Root>
<NavigationMenu.List>
<NavigationMenu.Item>
<NavigationMenu.Trigger />
<NavigationMenu.ItemIndicator />
<NavigationMenu.Content>
<NavigationMenu.Link />
</NavigationMenu.Content>
</NavigationMenu.Item>
<NavigationMenu.Indicator>
<NavigationMenu.Arrow />
</NavigationMenu.Indicator>
</NavigationMenu.List>
<NavigationMenu.ViewportPositioner>
<NavigationMenu.Viewport />
</NavigationMenu.ViewportPositioner>
</NavigationMenu.Root>
Examples
Viewport
Use NavigationMenu.Viewport for one shared panel. Add NavigationMenu.Indicator so the arrow tracks the open trigger.
Current link
Set current on the link for the current page. It renders aria-current="page" and a data-current attribute for
styling.
Vertical
Set orientation="vertical" for sidebar navigation. Panels open to the side. ArrowUp and ArrowDown move between
triggers, and ArrowRight enters the open panel.
Indicator
Render NavigationMenu.Indicator inside the list to highlight the active trigger, tab-style. It slides between triggers
with a CSS transition on --trigger-x and --trigger-width. For a static per-item marker, use
NavigationMenu.ItemIndicator.
Controlled
Use value and onValueChange to control the active item.
Root Provider
Use RootProvider with the useNavigationMenu hook to access the state and methods from outside the component.
RootProviderreplacesRoot. Don't use both.
Context
Read state with NavigationMenu.Context or the useNavigationMenuContext hook.
Guides
Custom links
Use asChild to render NavigationMenu.Link as your router's link component.
import { Link as RouterLink } from 'react-router-dom'
import { NavigationMenu } from '@ark-ui/<framework>/navigation-menu'
export const MenuLink = (props: NavigationMenu.LinkProps) => {
return (
<NavigationMenu.Link {...props} asChild>
<RouterLink to={props.href ?? '#'}>{props.children}</RouterLink>
</NavigationMenu.Link>
)
}
Viewport size
NavigationMenu.Root and NavigationMenu.Viewport expose these CSS variables:
/* size and position of the active trigger */
--trigger-width: <pixel-value>;
--trigger-height: <pixel-value>;
--trigger-x: <pixel-value>;
--trigger-y: <pixel-value>;
/* size and position of the active content */
--viewport-width: <pixel-value>;
--viewport-height: <pixel-value>;
--viewport-x: <pixel-value>;
--viewport-y: <pixel-value>;
Animate the shared panel between items with --viewport-width and --viewport-height:
[data-navigation-menu-viewport] {
width: var(--viewport-width);
height: var(--viewport-height);
transition:
width 250ms ease,
height 250ms ease;
}
Large menus
For content taller than the viewport, cap the panel and scroll the content:
[data-navigation-menu-viewport] {
max-height: min(var(--viewport-height), 70vh);
}
[data-navigation-menu-content] {
max-height: 70vh;
overflow-y: auto;
}
API Reference
Props
Root
Defines the <nav> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
closeDelay | 300 | numberThe delay before the menu closes |
defaultValue | stringThe default value of the navigation menu. Use when you don't want to control the value of the menu. | |
disableClickTrigger | booleanWhether to disable the click trigger | |
disableHoverTrigger | booleanWhether to disable the hover trigger | |
disablePointerLeaveClose | booleanWhether to disable the pointer leave close | |
hideMode | 'display-none' | HideModeHow to hide content when mounted but not present. - `'display-none'`: HTML `hidden` attribute. Effects stay alive. - `'activity'`: React 19 `<Activity mode="hidden">`. Effects pause. Requires React 19+. |
id | stringThe unique identifier of the machine. | |
ids | ElementIdsThe ids of the elements in the machine. | |
lazyMount | false | booleanWhether to enable lazy mounting |
onValueChange | (details: ValueChangeDetails) => voidFunction called when the value of the menu changes | |
openDelay | 200 | numberThe delay before the menu opens |
orientation | 'horizontal' | 'horizontal' | 'vertical'The orientation of the element. |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. | |
translations | IntlTranslationsSpecifies the localized strings that identifies the accessibility elements and their states | |
unmountOnExit | false | booleanWhether to unmount on exit. |
value | stringThe controlled value of the navigation menu |
| Attribute | Description |
|---|---|
[data-navigation-menu-root] | <uid> |
[data-orientation] | The orientation of the navigation-menu |
| CSS Variable | Description |
|---|---|
--trigger-width | The width of the Root |
--trigger-height | The height of the Root |
--trigger-x | The trigger x value for the Root |
--trigger-y | The trigger y value for the Root |
--viewport-width | The width of the Root |
--viewport-height | The height of the Root |
--viewport-x | The viewport x value for the Root |
--viewport-y | The viewport y value for the Root |
Arrow
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-navigation-menu-arrow] | <uid> |
[data-orientation] | The orientation of the arrow |
Content
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<NavigationMenuContentState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. | |
value | stringThe value of the item this content belongs to |
| Attribute | Description |
|---|---|
[data-navigation-menu-content] | <uid> |
[data-state] | "open" | "closed" |
[data-orientation] | The orientation of the content |
[data-activation-direction] | |
[data-motion] | |
[data-value] | The value of the item |
[data-nested] | Present when the content is nested within another {{widget}} |
[data-has-nested] | Present when the content has nested {{widget}}s |
| CSS Variable | Description |
|---|---|
--layer-index | The index of the dismissable in the layer stack |
--nested-layer-count | The number of nested navigation-menus |
Indicator
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-navigation-menu-indicator] | <uid> |
[data-state] | "open" | "closed" |
[data-orientation] | The orientation of the indicator |
ItemIndicator
Defines the <span> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-navigation-menu-item-indicator] | <uid> |
[data-state] | "open" | "closed" |
[data-orientation] | The orientation of the item |
[data-value] | The value of the item |
Item
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
value | stringThe value of the item | |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
disabled | booleanWhether the item is disabled | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<NavigationMenuItemState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-navigation-menu-item] | <uid> |
[data-value] | The value of the item |
[data-state] | "open" | "closed" |
[data-orientation] | The orientation of the item |
[data-disabled] | Present when disabled |
Link
Defines the <a> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
closeOnClick | true | booleanWhether to close the navigation menu when the link is clicked. |
current | booleanWhether the link is the current link | |
onSelect | (event: CustomEvent<any>) => voidFunction called when the link is selected | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. | |
value | stringThe value of the item this link belongs to |
| Attribute | Description |
|---|---|
[data-navigation-menu-link] | <uid> |
[data-value] | The value of the item |
[data-current] | Present when current |
List
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-navigation-menu-list] | <uid> |
[data-orientation] | The orientation of the list |
RootProvider
Defines the <nav> element.
| Attribute | Default | Type |
|---|---|---|
value | UseNavigationMenuReturn | |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
hideMode | 'display-none' | HideModeHow to hide content when mounted but not present. - `'display-none'`: HTML `hidden` attribute. Effects stay alive. - `'activity'`: React 19 `<Activity mode="hidden">`. Effects pause. Requires React 19+. |
lazyMount | false | booleanWhether to enable lazy mounting |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. | |
unmountOnExit | false | booleanWhether to unmount on exit. |
Trigger
Defines the <button> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
disabled | booleanWhether the item is disabled | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<NavigationMenuTriggerState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-navigation-menu-trigger] | <uid> |
[data-uid] | |
[data-trigger-proxy-id] | |
[data-value] | The value of the item |
[data-state] | "open" | "closed" |
[data-disabled] | Present when disabled |
ViewportPositioner
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
align | 'center' | 'start' | 'end'Placement of the viewport for css variables `(--viewport-x, --viewport-y)`. | |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-navigation-menu-viewport-positioner] | <uid> |
[data-orientation] | The orientation of the viewportpositioner |
[data-align] |
Viewport
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-navigation-menu-viewport] | <uid> |
[data-state] | "open" | "closed" |
[data-orientation] | The orientation of the viewport |
[data-activation-direction] | |
[data-align] | |
[data-nested] | Present when the viewport is nested within another {{widget}} |
[data-has-nested] | Present when the viewport has nested {{widget}}s |
| CSS Variable | Description |
|---|---|
--viewport-width | The width of the Viewport |
--viewport-height | The height of the Viewport |
--viewport-x | The viewport x value for the Viewport |
--viewport-y | The viewport y value for the Viewport |
Context
API
| Property | Type |
|---|---|
value | string | nullThe current value of the menu |
setValue | (value: string, reason?: ValueChangeReason) => voidSets the value of the menu |
open | booleanWhether the menu is open |
isViewportRendered | booleanWhether the viewport is rendered |
activationDirection | Exclude<ActivationDirection, "none"> | nullWhere the open item's trigger sits relative to the previous one: `left`, `right`, `up` or `down`. `null` when opened from closed. |
getViewportNode | () => HTMLElement | nullGets the viewport node element |
orientation | OrientationThe orientation of the menu |
reposition | VoidFunctionFunction to reposition the viewport |
getRootState | () => RootStateReturns the state of the root. The list, indicator, arrow and viewport positioner share it. |
getTriggerState | (props: ItemProps) => TriggerStateReturns the state of a specific trigger |
getContentState | (props: ContentProps) => ContentStateReturns the state of a specific content |
getViewportState | () => ViewportStateReturns the state of the viewport |
getItemState | (props: ItemProps) => ItemStateReturns the state of a specific item |
Accessibility
Complies with the Navigation Menubar WAI-ARIA design pattern.
Keyboard Support
| Key | Description |
|---|---|
ArrowDown | When focus is on trigger (vertical orientation), moves focus to the next trigger. |
ArrowUp | When focus is on trigger (vertical orientation), moves focus to the previous trigger. |
ArrowRight | When focus is on trigger (horizontal orientation), moves focus to the next trigger. When focus is on content, moves focus to the next link. |
ArrowLeft | When focus is on trigger (horizontal orientation), moves focus to the previous trigger. When focus is on content, moves focus to the previous link. |
Home | When focus is on trigger, moves focus to the first trigger. When focus is on content, moves focus to the first link. |
End | When focus is on trigger, moves focus to the last trigger. When focus is on content, moves focus to the last link. |