Navigation Menu
A collection of links and menus for website navigation.
View as MarkdownAnatomy
Import the component and assemble its parts:
import { NavigationMenu } from '@base-ui-components/react/navigation-menu';
<NavigationMenu.Root>
  <NavigationMenu.List>
    <NavigationMenu.Item>
      <NavigationMenu.Trigger>
        <NavigationMenu.Icon />
      </NavigationMenu.Trigger>
      <NavigationMenu.Content>
        <NavigationMenu.Link />
      </NavigationMenu.Content>
    </NavigationMenu.Item>
  </NavigationMenu.List>
  <NavigationMenu.Portal>
    <NavigationMenu.Backdrop />
    <NavigationMenu.Positioner>
      <NavigationMenu.Popup>
        <NavigationMenu.Arrow />
        <NavigationMenu.Viewport />
      </NavigationMenu.Popup>
    </NavigationMenu.Positioner>
  </NavigationMenu.Portal>
</NavigationMenu.Root>API reference
Root
Groups all parts of the navigation menu.
Renders a <nav> element at the root, or <div> element when nested.
defaultValueany
(default: null
)
anynull- Name
- Description
- The uncontrolled value of the item that should be initially selected. - To render a controlled navigation menu, use the - valueprop instead.
- Type
- any
- Default
- null
valueany
(default: null
)
anynull- Name
- Description
- The controlled value of the navigation menu item that should be currently open. When non-nullish, the menu will be open. When nullish, the menu will be closed. - To render an uncontrolled navigation menu, use the - defaultValueprop instead.
- Type
- any
- Default
- null
onValueChangefunction
function- Name
- Description
- Callback fired when the value changes. 
- Type
- | (( value: any, eventDetails: NavigationMenu.Root.ChangeEventDetails, ) => void) | undefined
actionsRefRefObject<NavigationMenu.Root.Actions>
RefObject<NavigationMenu.Root.Actions>- Name
- Description
- A ref to imperative actions. 
- Type
- | React.RefObject<NavigationMenu.Root.Actions> | undefined
onOpenChangeCompletefunction
function- Description
- Event handler called after any animations complete when the navigation menu is closed. 
- Type
- ((open: boolean) => void) | undefined
delaynumber
(default: 50
)
number50- Name
- Description
- How long to wait before opening the navigation menu. Specified in milliseconds. 
- Type
- number | undefined
- Default
- 50
closeDelaynumber
(default: 50
)
number50- Name
- Description
- How long to wait before closing the navigation menu. Specified in milliseconds. 
- Type
- number | undefined
- Default
- 50
orientation'horizontal' | 'vertical'
(default: 'horizontal'
)
'horizontal' | 'vertical''horizontal'- Name
- Description
- The orientation of the navigation menu. 
- Type
- 'horizontal' | 'vertical' | undefined
- Default
- 'horizontal'
classNamestring | function
string | function- Name
- Description
- CSS class applied to the element, or a function that returns a class based on the component’s state. 
- Type
- | string | ((state: NavigationMenu.Root.State) => string)
renderReactElement | function
ReactElement | function- Name
- Description
- Allows you to replace the component’s HTML element with a different tag, or compose it with another component. - Accepts a - ReactElementor a function that returns the element to render.
- Type
- | ReactElement | (( props: HTMLProps, state: NavigationMenu.Root.State, ) => ReactElement)
List
Contains a list of navigation menu items.
Renders a <div> element.
classNamestring | function
string | function- Name
- Description
- CSS class applied to the element, or a function that returns a class based on the component’s state. 
- Type
- | string | ((state: NavigationMenu.List.State) => string)
renderReactElement | function
ReactElement | function- Name
- Description
- Allows you to replace the component’s HTML element with a different tag, or compose it with another component. - Accepts a - ReactElementor a function that returns the element to render.
- Type
- | ReactElement | (( props: HTMLProps, state: NavigationMenu.List.State, ) => ReactElement)
Item
An individual navigation menu item.
Renders a <div> element.
valueany
any- Name
- Description
- A unique value that identifies this navigation menu item. If no value is provided, a unique ID will be generated automatically. Use when controlling the navigation menu programmatically. 
- Type
- any
classNamestring | function
string | function- Name
- Description
- CSS class applied to the element, or a function that returns a class based on the component’s state. 
- Type
- | string | ((state: NavigationMenu.Item.State) => string)
renderReactElement | function
ReactElement | function- Name
- Description
- Allows you to replace the component’s HTML element with a different tag, or compose it with another component. - Accepts a - ReactElementor a function that returns the element to render.
- Type
- | ReactElement | (( props: HTMLProps, state: NavigationMenu.Item.State, ) => ReactElement)
Trigger
Opens the navigation menu popup when hovered or clicked, revealing the
associated content.
Renders a <button> element.
nativeButtonboolean
(default: true
)
booleantrue- Name
- Description
- Whether the component renders a native - <button>element when replacing it via the- renderprop. Set to- falseif the rendered element is not a button (e.g.- <div>).
- Type
- boolean | undefined
- Default
- true
classNamestring | function
string | function- Name
- Description
- CSS class applied to the element, or a function that returns a class based on the component’s state. 
- Type
- | string | ((state: NavigationMenu.Trigger.State) => string)
renderReactElement | function
ReactElement | function- Name
- Description
- Allows you to replace the component’s HTML element with a different tag, or compose it with another component. - Accepts a - ReactElementor a function that returns the element to render.
- Type
- | ReactElement | (( props: HTMLProps, state: NavigationMenu.Trigger.State, ) => ReactElement)
data-popup-open
Present when the corresponding navigation menu is open.
data-pressed
Present when the trigger is pressed.
Icon
An icon that indicates that the trigger button opens a menu.
classNamestring | function
string | function- Name
- Description
- CSS class applied to the element, or a function that returns a class based on the component’s state. 
- Type
- | string | ((state: NavigationMenu.Icon.State) => string)
renderReactElement | function
ReactElement | function- Name
- Description
- Allows you to replace the component’s HTML element with a different tag, or compose it with another component. - Accepts a - ReactElementor a function that returns the element to render.
- Type
- | ReactElement | (( props: HTMLProps, state: NavigationMenu.Icon.State, ) => ReactElement)
Content
A container for the content of the navigation menu item that is moved into the popup
when the item is active.
Renders a <div> element.
classNamestring | function
string | function- Name
- Description
- CSS class applied to the element, or a function that returns a class based on the component’s state. 
- Type
- | string | ((state: NavigationMenu.Content.State) => string)
renderReactElement | function
ReactElement | function- Name
- Description
- Allows you to replace the component’s HTML element with a different tag, or compose it with another component. - Accepts a - ReactElementor a function that returns the element to render.
- Type
- | ReactElement | (( props: HTMLProps, state: NavigationMenu.Content.State, ) => ReactElement)
data-open
Present when the popup is open.
data-closed
Present when the popup is closed.
data-activation-direction
Which direction another trigger was activated from.
data-starting-style
Present when the content is animating in.
data-ending-style
Present when the content is animating out.
Link
A link in the navigation menu that can be used to navigate to a different page or section.
Renders an <a> element.
activeboolean
(default: false
)
booleanfalse- Name
- Description
- Whether the link is the currently active page. 
- Type
- boolean | undefined
- Default
- false
classNamestring | function
string | function- Name
- Description
- CSS class applied to the element, or a function that returns a class based on the component’s state. 
- Type
- | string | ((state: NavigationMenu.Link.State) => string)
renderReactElement | function
ReactElement | function- Name
- Description
- Allows you to replace the component’s HTML element with a different tag, or compose it with another component. - Accepts a - ReactElementor a function that returns the element to render.
- Type
- | ReactElement | (( props: HTMLProps, state: NavigationMenu.Link.State, ) => ReactElement)
data-active
Present when the link is the currently active page.
Backdrop
A backdrop for the navigation menu popup.
Renders a <div> element.
classNamestring | function
string | function- Name
- Description
- CSS class applied to the element, or a function that returns a class based on the component’s state. 
- Type
- | string | ((state: NavigationMenu.Backdrop.State) => string)
renderReactElement | function
ReactElement | function- Name
- Description
- Allows you to replace the component’s HTML element with a different tag, or compose it with another component. - Accepts a - ReactElementor a function that returns the element to render.
- Type
- | ReactElement | (( props: HTMLProps, state: NavigationMenu.Backdrop.State, ) => ReactElement)
data-open
Present when the popup is open.
data-closed
Present when the popup is closed.
data-starting-style
Present when the popup is animating in.
data-ending-style
Present when the popup is animating out.
Portal
A portal element that moves the popup to a different part of the DOM.
By default, the portal element is appended to <body>.
containerUnion
Union- Name
- Description
- A parent element to render the portal element into. 
- Type
- | HTMLElement | React.RefObject<HTMLElement | null> | null | undefined
childrenReactNode
ReactNode- Name
- Type
- React.ReactNode
keepMountedboolean
(default: false
)
booleanfalse- Name
- Description
- Whether to keep the portal mounted in the DOM while the popup is hidden. 
- Type
- boolean | undefined
- Default
- false
Positioner
Positions the navigation menu against the currently active trigger.
Renders a <div> element.
collisionAvoidanceCollisionAvoidance
CollisionAvoidance- Description
- Determines how to handle collisions when positioning the popup. 
- Type
- | { side?: 'none' | 'flip' align?: 'shift' | 'none' | 'flip' fallbackAxisSide?: 'none' | 'start' | 'end' } | { side?: 'shift' | 'none' align?: 'shift' | 'none' fallbackAxisSide?: 'none' | 'start' | 'end' } | undefined
- Example
- <Positioner collisionAvoidance={{ side: 'shift', align: 'shift', fallbackAxisSide: 'none', }} />
alignAlign
(default: 'center'
)
Align'center'- Name
- Description
- How to align the popup relative to the specified side. 
- Type
- 'center' | 'start' | 'end' | undefined
- Default
- 'center'
alignOffsetnumber | OffsetFunction
(default: 0
)
number | OffsetFunction0- Name
- Description
- Additional offset along the alignment axis in pixels. Also accepts a function that returns the offset to read the dimensions of the anchor and positioner elements, along with its side and alignment. - The function takes a - dataobject parameter with the following properties:- data.anchor: the dimensions of the anchor element with properties- widthand- height.
- data.positioner: the dimensions of the positioner element with properties- widthand- height.
- data.side: which side of the anchor element the positioner is aligned against.
- data.align: how the positioner is aligned relative to the specified side.
 
- Type
- | number | ((data: { side: Side align: Align anchor: { width: number; height: number } positioner: { width: number; height: number } }) => number) | undefined
- Default
- 0
- Example
- <Positioner alignOffset={({ side, align, anchor, positioner }) => { return side === 'top' || side === 'bottom' ? anchor.width : anchor.height; }} />
sideSide
(default: 'bottom'
)
Side'bottom'- Name
- Description
- Which side of the anchor element to align the popup against. May automatically change to avoid collisions. 
- Type
- | 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start' | undefined
- Default
- 'bottom'
sideOffsetnumber | OffsetFunction
(default: 0
)
number | OffsetFunction0- Name
- Description
- Distance between the anchor and the popup in pixels. Also accepts a function that returns the distance to read the dimensions of the anchor and positioner elements, along with its side and alignment. - The function takes a - dataobject parameter with the following properties:- data.anchor: the dimensions of the anchor element with properties- widthand- height.
- data.positioner: the dimensions of the positioner element with properties- widthand- height.
- data.side: which side of the anchor element the positioner is aligned against.
- data.align: how the positioner is aligned relative to the specified side.
 
- Type
- | number | ((data: { side: Side align: Align anchor: { width: number; height: number } positioner: { width: number; height: number } }) => number) | undefined
- Default
- 0
- Example
- <Positioner sideOffset={({ side, align, anchor, positioner }) => { return side === 'top' || side === 'bottom' ? anchor.height : anchor.width; }} />
arrowPaddingnumber
(default: 5
)
number5- Name
- Description
- Minimum distance to maintain between the arrow and the edges of the popup. - Use it to prevent the arrow element from hanging out of the rounded corners of a popup. 
- Type
- number | undefined
- Default
- 5
anchorUnion
Union- Name
- Description
- An element to position the popup against. By default, the popup will be positioned against the trigger. 
- Type
- | Element | React.RefObject<Element | null> | VirtualElement | (() => Element | VirtualElement | null) | null | undefined
collisionBoundaryBoundary
(default: 'clipping-ancestors'
)
Boundary'clipping-ancestors'- Description
- An element or a rectangle that delimits the area that the popup is confined to. 
- Type
- | Element | 'clipping-ancestors' | Element[] | Rect | undefined
- Default
- 'clipping-ancestors'
collisionPaddingPadding
(default: 5
)
Padding5- Name
- Description
- Additional space to maintain from the edge of the collision boundary. 
- Type
- | { top?: number right?: number bottom?: number left?: number } | number | undefined
- Default
- 5
stickyboolean
(default: false
)
booleanfalse- Name
- Description
- Whether to maintain the popup in the viewport after the anchor element was scrolled out of view. 
- Type
- boolean | undefined
- Default
- false
positionMethod'fixed' | 'absolute'
(default: 'absolute'
)
'fixed' | 'absolute''absolute'- Name
- Description
- Determines which CSS - positionproperty to use.
- Type
- 'fixed' | 'absolute' | undefined
- Default
- 'absolute'
trackAnchorboolean
(default: true
)
booleantrue- Name
- Description
- Whether the popup tracks any layout shift of its positioning anchor. 
- Type
- boolean | undefined
- Default
- true
classNamestring | function
string | function- Name
- Description
- CSS class applied to the element, or a function that returns a class based on the component’s state. 
- Type
- | string | ((state: NavigationMenu.Positioner.State) => string)
renderReactElement | function
ReactElement | function- Name
- Description
- Allows you to replace the component’s HTML element with a different tag, or compose it with another component. - Accepts a - ReactElementor a function that returns the element to render.
- Type
- | ReactElement | (( props: HTMLProps, state: NavigationMenu.Positioner.State, ) => ReactElement)
data-open
Present when the popup is open.
data-closed
Present when the popup is closed.
data-anchor-hidden
Present when the anchor is hidden.
data-align
Indicates how the popup is aligned relative to the specified side.
data-instant
Present if animations should be instant.
data-side
Indicates which side the popup is positioned relative to the trigger.
--anchor-height
The anchor's height.
--anchor-width
The anchor's width.
--available-height
The available height between the trigger and the edge of the viewport.
--available-width
The available width between the trigger and the edge of the viewport.
--positioner-height
The fixed height of the positioner element.
--positioner-width
The fixed width of the positioner element.
--transform-origin
The coordinates that this element is anchored to. Used for animations and transitions.
Popup
A container for the navigation menu contents.
Renders a <nav> element.
classNamestring | function
string | function- Name
- Description
- CSS class applied to the element, or a function that returns a class based on the component’s state. 
- Type
- | string | ((state: NavigationMenu.Popup.State) => string)
renderReactElement | function
ReactElement | function- Name
- Description
- Allows you to replace the component’s HTML element with a different tag, or compose it with another component. - Accepts a - ReactElementor a function that returns the element to render.
- Type
- | ReactElement | (( props: HTMLProps, state: NavigationMenu.Popup.State, ) => ReactElement)
data-open
Present when the popup is open.
data-closed
Present when the popup is closed.
data-align
Indicates how the popup is aligned relative to the specified side.
data-side
Indicates which side the popup is positioned relative to the trigger.
data-starting-style
Present when the popup is animating in.
data-ending-style
Present when the popup is animating out.
--popup-height
The fixed height of the popup element.
--popup-width
The fixed width of the popup element.
Viewport
The clipping viewport of the navigation menu's current content.
Renders a <div> element.
classNamestring | function
string | function- Name
- Description
- CSS class applied to the element, or a function that returns a class based on the component’s state. 
- Type
- | string | ((state: NavigationMenu.Viewport.State) => string)
renderReactElement | function
ReactElement | function- Name
- Description
- Allows you to replace the component’s HTML element with a different tag, or compose it with another component. - Accepts a - ReactElementor a function that returns the element to render.
- Type
- | ReactElement | (( props: HTMLProps, state: NavigationMenu.Viewport.State, ) => ReactElement)
Arrow
Displays an element pointing toward the navigation menu's current anchor.
Renders a <div> element.
classNamestring | function
string | function- Name
- Description
- CSS class applied to the element, or a function that returns a class based on the component’s state. 
- Type
- | string | ((state: NavigationMenu.Arrow.State) => string)
renderReactElement | function
ReactElement | function- Name
- Description
- Allows you to replace the component’s HTML element with a different tag, or compose it with another component. - Accepts a - ReactElementor a function that returns the element to render.
- Type
- | ReactElement | (( props: HTMLProps, state: NavigationMenu.Arrow.State, ) => ReactElement)
data-open
Present when the popup is open.
data-closed
Present when the popup is closed.
data-uncentered
Present when the popup arrow is uncentered.
data-align
Indicates how the popup is aligned relative to specified side.
data-side
Indicates which side the popup is positioned relative to the trigger.
Examples
Nested submenus
A NavigationMenu.Root component can be nested within a higher-level NavigationMenu.Content part to create a multi-level navigation menu.
Custom links
The NavigationMenu.Link part can be customized to render the link from your framework using the render prop to enable client-side routing.
import NextLink from 'next/link';
import { NavigationMenu } from '@base-ui-components/react/navigation-menu';
function Link(props: NavigationMenu.Link.Props) {
  return (
    <NavigationMenu.Link
      render={<NextLink href={props.href} />}
      {...props}
    />
  );
}Large menus
When you have large menu content that doesn’t fit in the viewport in some cases, you usually have two choices:
- Compress the navigation menu content
You can change the layout of the navigation menu to render less content or be more compact by reducing the space it takes up. If your content is flexible, you can use the max-height property on Popup to limit the height of the navigation menu to let it compress itself while preventing overflow.
.Content,
.Popup {
  max-height: var(--available-height);
}- Make the navigation menu scrollable
.Content,
.Popup {
  max-height: var(--available-height);
}
.Content {
  overflow-y: auto;
}Native scrollbars will be visible while transitioning content, so we recommend using our Scroll Area component instead of native scrollbars to keep them hidden, which will also allow the Arrow to be centered correctly.