---
title: "Navigation Menu · UI SDK — StyleX Blocks"
description: "Site-header navigation whose triggers open rich link panels in a shared viewport that morphs between them."
url: "https://stylexblocks.com/components/ui-sdk/navigation-menu/"
agent:
  instructions: "Use this search API to find relevant components and blocks across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://stylexblocks.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Navigation Menu

Site-header navigation whose triggers open rich link panels in a shared viewport that morphs between them.

- Behavior engine: UI SDK
- Also available for: [Ark UI](https://stylexblocks.com/components/ark-ui/navigation-menu.md), [Base UI](https://stylexblocks.com/components/base-ui/navigation-menu.md)
- Category: Display
- Sizes: sm, md
- HTML page: https://stylexblocks.com/components/ui-sdk/navigation-menu/

## Install

Configure the project once (sets the behavior engine and import aliases):

```sh
npx stylexblocks init --style ui-sdk
```

Then add the item as source you own:

```sh
npx stylexblocks add navigation-menu
```

Equivalent: `npx shadcn add @stylexblocks/navigation-menu`. Registry item JSON: https://stylexblocks.com/r/ui-sdk/navigation-menu.json

## Usage

```tsx
import { NavigationMenu } from "#components/ui/ui-sdk/navigation-menu.tsx";

export function Example() {
  return (
    // size resolves once on Root; parts inherit it via context. The open
    // Content moves into the Viewport, a native popover in the top layer
    // that the engine sizes and places under the open trigger; the
    // Indicator points at it.
    <NavigationMenu.Root size="md" aria-label="Main">
      <NavigationMenu.List>
        <NavigationMenu.Item value="product">
          <NavigationMenu.Trigger>
            Product
            <NavigationMenu.Icon />
          </NavigationMenu.Trigger>
          <NavigationMenu.Content>
            <NavigationMenu.PanelLink href="/components">
              <NavigationMenu.PanelLinkTitle>Components</NavigationMenu.PanelLinkTitle>
              <NavigationMenu.PanelLinkDescription>
                Accessible primitives styled with StyleX.
              </NavigationMenu.PanelLinkDescription>
            </NavigationMenu.PanelLink>
          </NavigationMenu.Content>
        </NavigationMenu.Item>
        <NavigationMenu.Item value="pricing">
          <NavigationMenu.Link href="/pricing">Pricing</NavigationMenu.Link>
        </NavigationMenu.Item>
      </NavigationMenu.List>
      <NavigationMenu.Indicator />
      <NavigationMenu.Viewport />
    </NavigationMenu.Root>
  );
}
```

## Source

`components/ui/ui-sdk/navigation-menu.tsx`

```tsx
import * as stylex from "@stylexjs/stylex";
import {
  NavigationMenu as UiSdkNavigationMenu,
  NavigationMenuContent,
  NavigationMenuIndicator,
  NavigationMenuItem,
  NavigationMenuLink,
  NavigationMenuList,
  NavigationMenuTrigger,
  NavigationMenuViewport,
} from "@ui-sdk/react/navigation-menu";
import { createSlotRecipeContext } from "#lib/ui-sdk/create-slot-recipe-context.tsx";
import {
  defineSlotRecipe,
  resolveSlotStyles,
  type StyleOverrideProps,
} from "#lib/recipe-props.ts";
import { colorPalette } from '@stylexblocks/ui/color-palette.stylex.ts'
import { cursor } from '@stylexblocks/ui/tokens/cursor.stylex.ts'
import { durations } from '@stylexblocks/ui/tokens/durations.stylex.ts'
import { easings } from '@stylexblocks/ui/tokens/easings.stylex.ts'
import { fontSizes } from '@stylexblocks/ui/tokens/font-sizes.stylex.ts'
import { fontWeights } from '@stylexblocks/ui/tokens/font-weights.stylex.ts'
import { lineHeights } from '@stylexblocks/ui/tokens/line-heights.stylex.ts'
import { semanticColors } from '@stylexblocks/ui/semantic-tokens/colors.stylex.ts'
import { semanticRadii } from '@stylexblocks/ui/semantic-tokens/radii.stylex.ts'
import { semanticShadows } from '@stylexblocks/ui/semantic-tokens/shadows.stylex.ts'
import { sizes } from '@stylexblocks/ui/tokens/sizes.stylex.ts'
import { spacing } from '@stylexblocks/ui/tokens/spacing.stylex.ts'
import { zIndices } from '@stylexblocks/ui/tokens/z-indices.stylex.ts'

const navigationMenuRoot = stylex.create({
  base: {
    position: 'relative',
    display: 'flex',
    alignItems: 'center',
    '--navigation-menu-z-index': zIndices.dropdown,
    '--navigation-menu-gutter': spacing._2,
  },
})

const navigationMenuList = stylex.create({
  base: {
    position: 'relative',
    display: 'flex',
    alignItems: 'center',
    gap: spacing._1,
    margin: 0,
    padding: 0,
    listStyle: 'none',
  },
})

const navigationMenuItem = stylex.create({
  base: {
    display: 'flex',
    listStyle: 'none',
  },
})

// Bar triggers and bar links share one look, matching `navbar`'s links: a
// transparent control that fills on hover and stays filled while its panel
// is open (Ark `data-state="open"`, Base UI `data-popup-open`).
const navigationMenuTrigger = stylex.create({
  base: {
    display: 'inline-flex',
    alignItems: 'center',
    gap: spacing._1,
    whiteSpace: 'nowrap',
    userSelect: 'none',
    color: semanticColors.fg,
    fontWeight: fontWeights.medium,
    textDecoration: 'none',
    borderWidth: 0,
    borderRadius: semanticRadii.control,
    backgroundColor: {
      default: 'transparent',
      ':hover': semanticColors.bgMuted,
      ':is([data-state="open"], [data-popup-open])': semanticColors.bgMuted,
    },
    cursor: {
      default: cursor.button,
      ':is(:disabled, [data-disabled])': 'not-allowed',
    },
    opacity: {
      default: null,
      ':is(:disabled, [data-disabled])': 0.5,
    },
    outline: {
      default: null,
      ':focus-visible': 'none',
    },
    boxShadow: {
      default: null,
      ':focus-visible': `0 0 0 2px ${colorPalette.focusRing}`,
    },
    transitionProperty: 'background-color, color, box-shadow',
    transitionDuration: durations.fast,
  },
})

const navigationMenuTriggerSizes = stylex.create({
  sm: {
    height: sizes._7,
    paddingInline: spacing._2,
    fontSize: fontSizes.xs,
    lineHeight: lineHeights.xs,
  },
  md: {
    height: sizes._8,
    paddingInline: spacing._3,
    fontSize: fontSizes.sm,
    lineHeight: lineHeights.sm,
  },
})

const navigationMenuIcon = stylex.create({
  base: {
    display: 'inline-flex',
    flexShrink: 0,
    color: semanticColors.fgMuted,
    transitionProperty: 'rotate',
    transitionDuration: durations.moderate,
    transitionTimingFunction: easings.standard,
    rotate: {
      default: '0deg',
      ':is([data-state="open"], [data-popup-open])': '180deg',
    },
  },
})

const navigationMenuLink = stylex.create({
  base: {
    display: 'inline-flex',
    alignItems: 'center',
    whiteSpace: 'nowrap',
    color: {
      default: semanticColors.fg,
      ':is([data-current], [data-active], [aria-current="page"])':
        colorPalette.fg,
    },
    fontWeight: fontWeights.medium,
    textDecoration: 'none',
    borderRadius: semanticRadii.control,
    backgroundColor: {
      default: 'transparent',
      ':hover': semanticColors.bgMuted,
    },
    outline: {
      default: null,
      ':focus-visible': 'none',
    },
    boxShadow: {
      default: null,
      ':focus-visible': `0 0 0 2px ${colorPalette.focusRing}`,
    },
    transitionProperty: 'background-color, color, box-shadow',
    transitionDuration: durations.fast,
  },
})

const navigationMenuLinkSizes = stylex.create({
  sm: {
    height: sizes._7,
    paddingInline: spacing._2,
    fontSize: fontSizes.xs,
    lineHeight: lineHeights.xs,
  },
  md: {
    height: sizes._8,
    paddingInline: spacing._3,
    fontSize: fontSizes.sm,
    lineHeight: lineHeights.sm,
  },
})

// The panel surface: matches `menu` / `popover` content (bgPanel, panel
// radius, overlay shadow). Width and height follow the engine-measured size
// of the active content so the panel morphs between triggers.
const navigationMenuViewport = stylex.create({
  base: {
    position: 'relative',
    overflow: 'hidden',
    color: semanticColors.fg,
    backgroundColor: semanticColors.bgPanel,
    borderRadius: semanticRadii.panel,
    boxShadow: semanticShadows.overlay,
    transformOrigin: 'var(--transform-origin, top center)',
    transitionProperty: 'width, height, translate',
    transitionDuration: durations.moderate,
    transitionTimingFunction: easings.standard,
  },
})

const navigationMenuContent = stylex.create({
  base: {
    display: 'grid',
    gridTemplateColumns:
      'repeat(var(--navigation-menu-columns, 2), minmax(0, 15rem))',
    width: 'max-content',
    maxWidth: 'calc(100vw - 2rem)',
    outline: 'none',
  },
})

const navigationMenuContentSizes = stylex.create({
  sm: {
    gap: spacing._0_5,
    padding: spacing._1,
  },
  md: {
    gap: spacing._1,
    padding: spacing._2,
  },
})

// A rich link inside a panel: title + description, highlighted like a menu
// item (bgSubtle) on hover and keyboard focus.
const navigationMenuPanelLink = stylex.create({
  base: {
    display: 'flex',
    flexDirection: 'column',
    gap: spacing._0_5,
    textDecoration: 'none',
    color: semanticColors.fg,
    borderRadius: semanticRadii.control,
    backgroundColor: {
      default: 'transparent',
      ':hover': semanticColors.bgSubtle,
      ':focus-visible': semanticColors.bgSubtle,
      ':is([data-current], [data-active], [aria-current="page"])':
        semanticColors.bgSubtle,
    },
    outline: 'none',
    cursor: cursor.menuitem,
    transitionProperty: 'background-color',
    transitionDuration: durations.fast,
  },
})

const navigationMenuPanelLinkSizes = stylex.create({
  sm: {
    paddingInline: spacing._2,
    paddingBlock: spacing._1_5,
  },
  md: {
    paddingInline: spacing._3,
    paddingBlock: spacing._2,
  },
})

const navigationMenuPanelLinkTitle = stylex.create({
  base: {
    fontWeight: fontWeights.medium,
    fontSize: fontSizes.sm,
    lineHeight: lineHeights.sm,
    color: semanticColors.fg,
  },
})

const navigationMenuPanelLinkDescription = stylex.create({
  base: {
    fontSize: fontSizes.xs,
    lineHeight: lineHeights.xs,
    color: semanticColors.fgMuted,
  },
})

// A small diamond that points from the open trigger at the panel. Only the
// top half shows above the panel edge; its top/left borders continue the
// panel's hairline.
const navigationMenuArrow = stylex.create({
  base: {
    width: '10px',
    height: '10px',
    rotate: '45deg',
    backgroundColor: semanticColors.bgPanel,
    borderTopWidth: '1px',
    borderLeftWidth: '1px',
    borderStyle: 'solid',
    borderColor: semanticColors.border,
    borderRightWidth: 0,
    borderBottomWidth: 0,
    borderTopLeftRadius: '2px',
  },
})

export type NavigationMenuSize = keyof typeof navigationMenuTriggerSizes

// defineSlotRecipe validates the shape at compile time: default values must
// exist in the axis maps, and slot keys must be `styles` or a declared axis
const navigationMenuRecipe = defineSlotRecipe({
  slots: {
    root: { styles: navigationMenuRoot },
    list: { styles: navigationMenuList },
    item: { styles: navigationMenuItem },
    trigger: { styles: navigationMenuTrigger, sizes: navigationMenuTriggerSizes },
    icon: { styles: navigationMenuIcon },
    link: { styles: navigationMenuLink, sizes: navigationMenuLinkSizes },
    viewport: { styles: navigationMenuViewport },
    content: { styles: navigationMenuContent, sizes: navigationMenuContentSizes },
    panelLink: { styles: navigationMenuPanelLink, sizes: navigationMenuPanelLinkSizes },
    panelLinkTitle: { styles: navigationMenuPanelLinkTitle },
    panelLinkDescription: { styles: navigationMenuPanelLinkDescription },
    arrow: { styles: navigationMenuArrow },
  },
  defaultVariants: { size: "md" },
});

// UI SDK layout: the Viewport is the panel surface and a native popover in
// the top layer, placed under the open trigger and sized from the engine's
// `--viewport-{width,height}`; it keeps the browser's popover margin, border
// and padding, so they're reset here. Contents sit at its corner so outgoing
// and incoming panels cross-fade while it morphs. The Indicator sits under
// the open trigger from `--active-item-*`; its arrow's lower half tucks
// behind the top-layer panel. Open triggers carry `data-open`.
const chrome = stylex.create({
  trigger: {
    backgroundColor: {
      default: null,
      ":is([data-open])": semanticColors.bgMuted,
    },
  },
  icon: {
    rotate: {
      default: null,
      ":is([data-open] *)": "180deg",
    },
  },
  viewport: {
    margin: 0,
    padding: 0,
    borderWidth: 0,
    zIndex: zIndices.dropdown,
    width: "var(--viewport-width)",
    height: "var(--viewport-height)",
    transitionProperty: "width, height, left, top, opacity, scale",
    opacity: {
      default: 1,
      ":is([data-starting-style], [data-ending-style])": 0,
    },
    scale: {
      default: 1,
      ":is([data-starting-style], [data-ending-style])": 0.95,
    },
  },
  content: {
    position: "absolute",
    top: 0,
    insetInlineStart: 0,
    transitionProperty: "opacity",
    transitionDuration: durations.moderate,
    opacity: {
      default: 1,
      ":is([data-starting-style], [data-ending-style])": 0,
    },
  },
  indicator: {
    position: "absolute",
    top: "calc(var(--active-item-top) + var(--active-item-height))",
    left: "var(--active-item-left)",
    width: "var(--active-item-width)",
    height: "var(--navigation-menu-gutter)",
    display: "flex",
    alignItems: "flex-end",
    justifyContent: "center",
    pointerEvents: "none",
    transitionProperty: "left, width, opacity",
    transitionDuration: durations.moderate,
    transitionTimingFunction: easings.standard,
    opacity: {
      default: 0,
      ":is([data-open])": 1,
    },
  },
  arrow: {
    display: "block",
    translate: "0 50%",
  },
});

function ChevronDownIcon(props: React.ComponentProps<"svg">) {
  return (
    <svg width="12" height="12" viewBox="0 0 16 16" fill="none" aria-hidden="true" {...props}>
      <path d="m4 6 4 4 4-4" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
    </svg>
  );
}

const { withProvider, withContext } = createSlotRecipeContext(navigationMenuRecipe);

// UI SDK has no trigger-icon part: a plain span that turns while the trigger
// around it carries `data-open`.
const StyledIcon = withContext(
  "span",
  (v) => [...resolveSlotStyles(navigationMenuRecipe.slots.icon, v), chrome.icon],
  "NavigationMenuIcon",
);

function Icon(props: React.ComponentProps<typeof StyledIcon>) {
  const { children, ...rest } = props;
  return (
    <StyledIcon aria-hidden {...rest}>
      {children ?? <ChevronDownIcon />}
    </StyledIcon>
  );
}
Icon.displayName = "NavigationMenuIcon";

const StyledViewport = withContext(
  NavigationMenuViewport,
  (v) => [...resolveSlotStyles(navigationMenuRecipe.slots.viewport, v), chrome.viewport],
  "NavigationMenuViewport",
);

function Viewport(props: React.ComponentProps<typeof StyledViewport>) {
  const { sideOffset = 8, collisionPadding = 8, ...rest } = props;
  return (
    <StyledViewport sideOffset={sideOffset} collisionPadding={collisionPadding} {...rest} />
  );
}
Viewport.displayName = "NavigationMenuViewport";

const Arrow = withContext(
  "span",
  (v) => [...resolveSlotStyles(navigationMenuRecipe.slots.arrow, v), chrome.arrow],
  "NavigationMenuArrow",
);

const StyledIndicator = withContext(
  NavigationMenuIndicator,
  () => [chrome.indicator],
  "NavigationMenuIndicator",
);

/** Sits under the open trigger; renders an arrow by default. */
function Indicator(props: React.ComponentProps<typeof StyledIndicator>) {
  const { children, ...rest } = props;
  return <StyledIndicator {...rest}>{children ?? <Arrow />}</StyledIndicator>;
}
Indicator.displayName = "NavigationMenuIndicator";

/**
 * NavigationMenu — UI SDK's navigation menu wearing the navigation-menu
 * slot recipe: hover/click triggers with delays, arrow-key roving, and one
 * shared Viewport (a native popover in the top layer, so no Portal or
 * Positioner) that the engine sizes from the open content and moves under
 * the open trigger. Put the Indicator after the List for the arrow under
 * the open trigger. `<NavigationMenu.Root size>` resolves the recipe once;
 * every part inherits it through context and composes via `render`. Give
 * Root an `aria-label`.
 */
export const NavigationMenu = {
  Root: withProvider(UiSdkNavigationMenu, "root", "NavigationMenuRoot"),
  List: withContext(NavigationMenuList, "list", "NavigationMenuList"),
  Item: withContext(NavigationMenuItem, "item", "NavigationMenuItem"),
  Trigger: withContext(
    NavigationMenuTrigger,
    (v) => [...resolveSlotStyles(navigationMenuRecipe.slots.trigger, v), chrome.trigger],
    "NavigationMenuTrigger",
  ),
  Icon,
  Link: withContext(NavigationMenuLink, "link", "NavigationMenuLink"),
  Indicator,
  Arrow,
  Content: withContext(
    NavigationMenuContent,
    (v) => [...resolveSlotStyles(navigationMenuRecipe.slots.content, v), chrome.content],
    "NavigationMenuContent",
  ),
  PanelLink: withContext(NavigationMenuLink, "panelLink", "NavigationMenuPanelLink"),
  PanelLinkTitle: withContext("span", "panelLinkTitle", "NavigationMenuPanelLinkTitle"),
  PanelLinkDescription: withContext(
    "span",
    "panelLinkDescription",
    "NavigationMenuPanelLinkDescription",
  ),
  Viewport,
};
```
