---
title: "Sidebar Nav Item · UI SDK — StyleX Blocks"
description: "Sidebar navigation buttons with icon, label, and accent-tinted active state."
url: "https://stylexblocks.com/components/ui-sdk/sidebar-nav-item/"
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/"
---

# Sidebar Nav Item

Sidebar navigation buttons with icon, label, and accent-tinted active state.

- Behavior engine: UI SDK
- Also available for: [Ark UI](https://stylexblocks.com/components/ark-ui/sidebar-nav-item.md), [Base UI](https://stylexblocks.com/components/base-ui/sidebar-nav-item.md)
- Category: Display
- Variants: muted
- Sizes: sm, md, lg
- Used in blocks: [Messaging Shell](https://stylexblocks.com/block/ui-sdk/messaging-shell.md), [Settings Dialog](https://stylexblocks.com/block/ui-sdk/settings-dialog.md), [Settings Form](https://stylexblocks.com/block/ui-sdk/settings-form.md), [Settings Panels](https://stylexblocks.com/block/ui-sdk/settings-panels.md), [Shell Nav](https://stylexblocks.com/block/ui-sdk/shell-nav.md), [Side Nav Shell](https://stylexblocks.com/block/ui-sdk/shell-side-nav.md), [Top Nav Shell](https://stylexblocks.com/block/ui-sdk/shell-top-nav.md)
- HTML page: https://stylexblocks.com/components/ui-sdk/sidebar-nav-item/

## 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 sidebar-nav-item
```

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

## Usage

```tsx
import {
  SidebarNavItem,
  sidebarNavItemActive,
} from "#components/ui/ui-sdk/sidebar-nav-item.tsx";

export function Example() {
  return (
    // variant/size resolve once on Item; Button, Icon, and EndElement
    // inherit them via context
    <ul>
      <SidebarNavItem.Item variant="muted" size="md">
        {/* render swaps the button for a link while keeping the styling */}
        <SidebarNavItem.Button
          aria-current="page"
          style={sidebarNavItemActive}
        >
          <SidebarNavItem.Icon viewBox="0 0 16 16">{/* icon */}</SidebarNavItem.Icon>
          Dashboard
          <SidebarNavItem.EndElement>⌘1</SidebarNavItem.EndElement>
        </SidebarNavItem.Button>
      </SidebarNavItem.Item>
    </ul>
  );
}
```

## Source

`components/ui/ui-sdk/sidebar-nav-item.tsx`

```tsx
import * as stylex from "@stylexjs/stylex";
import { createSlotRecipeContext } from "#lib/ui-sdk/create-slot-recipe-context.tsx";
import { defineSlotRecipe } from "#lib/recipe-props.ts";
import { sidebarNavItemButtonSvgVars } from '@stylexblocks/ui/slot-recipes/sidebar-nav-item.stylex.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 { fontSizes } from '@stylexblocks/ui/tokens/font-sizes.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 { sizes } from '@stylexblocks/ui/tokens/sizes.stylex.ts'
import { spacing } from '@stylexblocks/ui/tokens/spacing.stylex.ts'


const sidebarNavItemItem = stylex.create({
  base: {
    position: 'relative',
    fontSize: fontSizes.sm,
    paddingBlock: '1px',
  },
})

const sidebarNavItemItemSizes = stylex.create({
  sm: {
    fontSize: fontSizes.sm,
    lineHeight: lineHeights.sm,
  },
  md: {
    fontSize: fontSizes.sm,
    lineHeight: lineHeights.sm,
  },
  lg: {
    fontSize: fontSizes.sm,
    lineHeight: lineHeights.sm,
  },
})

const sidebarNavItemButton = stylex.create({
  base: {
    display: 'flex',
    alignItems: 'center',
    gap: spacing._2,
    isolation: 'isolate',
    width: '100%',
    textOverflow: 'ellipsis',
    overflow: 'hidden',
    whiteSpace: 'nowrap',
    cursor: {
      default: cursor.button,
      ':is(:disabled, [disabled], [data-disabled])': 'not-allowed',
    },
    transitionProperty:
      'background-color, border-color, color, fill, stroke, opacity, box-shadow, transform',
    transitionDuration: durations.fast,
    outlineWidth: {
      default: null,
      ':focus-visible': 'var(--focus-ring-width, 0)',
    },
    outlineOffset: {
      default: null,
      ':focus-visible': '0px',
    },
    outlineStyle: {
      default: null,
      ':focus-visible': 'solid',
    },
    outlineColor: {
      default: null,
      ':focus-visible': colorPalette.focusRing,
    },
    focusRingWidth: '1px',
    opacity: {
      default: null,
      ':is(:disabled, [disabled], [data-disabled])': 0.5,
    },
    [sidebarNavItemButtonSvgVars.width]: sizes._4,
    [sidebarNavItemButtonSvgVars.height]: sizes._4,
    [sidebarNavItemButtonSvgVars.color]: 'var(--sidebar-item-icon-color)',
  },
})

const sidebarNavItemButtonSizes = stylex.create({
  sm: {
    borderRadius: semanticRadii.control,
    paddingInline: spacing._2,
    height: sizes.controlXs,
  },
  md: {
    borderRadius: semanticRadii.control,
    paddingInline: spacing._2_5,
    height: sizes.controlSm,
  },
  lg: {
    borderRadius: semanticRadii.control,
    paddingInline: spacing._3,
    height: sizes.controlMd,
  },
})

const sidebarNavItemButtonVariants = stylex.create({
  muted: {
    backgroundColor: {
      default: 'transparent',
      ':hover': `color-mix(in oklch, ${semanticColors.sidebarAccentBg} 90%, transparent)`,
      ':active': semanticColors.sidebarAccentBg,
    },
    color: {
      default: `color-mix(in oklch, ${semanticColors.sidebarAccentFg} 85%, transparent)`,
      ':hover': semanticColors.sidebarAccentFg,
      ':active': semanticColors.sidebarAccentFg,
    },
    '--sidebar-item-icon-color': {
      default: `color-mix(in oklch, ${semanticColors.sidebarAccentFg} 85%, transparent)`,
      ':hover': semanticColors.sidebarAccentFg,
      ':active': semanticColors.sidebarAccentFg,
    },
  },
})

const sidebarNavItemButtonSvg = stylex.create({
  base: {
    width: sidebarNavItemButtonSvgVars.width,
    height: sidebarNavItemButtonSvgVars.height,
    color: sidebarNavItemButtonSvgVars.color,
  },
})

const sidebarNavItemEndElement = stylex.create({
  base: {
    display: 'flex',
    gap: '1px',
    marginInlineStart: 'auto',
  },
})

const sidebarNavItemEndElementSizes = stylex.create({
  sm: {
    paddingInlineEnd: spacing._1,
  },
  md: {
    paddingInlineEnd: spacing._1,
  },
  lg: {
    paddingInlineEnd: spacing._1,
  },
})

export type SidebarNavItemVariant = keyof typeof sidebarNavItemButtonVariants

export type SidebarNavItemSize = keyof typeof sidebarNavItemItemSizes

// The button ships browser chrome the recipe doesn't reset, and the recipe
// has no accent treatment for the active item — both live with the component.
const sidebarNavItemStatic = stylex.create({
  button: { borderWidth: 0, textAlign: "start", width: "100%" },
  active: {
    backgroundColor: semanticColors.sidebarAccentBg,
    color: semanticColors.sidebarAccentFg,
    "--sidebar-item-icon-color": semanticColors.sidebarAccentFg,
  },
});

// 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 sidebarNavItemSlotRecipe = defineSlotRecipe({
  slots: {
    item: { styles: sidebarNavItemItem, sizes: sidebarNavItemItemSizes },
    button: {
      styles: sidebarNavItemButton,
      sizes: sidebarNavItemButtonSizes,
      variants: sidebarNavItemButtonVariants,
    },
    endElement: {
      styles: sidebarNavItemEndElement,
      sizes: sidebarNavItemEndElementSizes,
    },
  },
  defaultVariants: { variant: "muted", size: "md" },
});

/**
 * SidebarNavItem — recipe and component colocated in one file.
 * `<SidebarNavItem.Item variant size>` resolves the recipe once and every
 * part inherits it through context; each part composes via `render` (swap
 * the Button for a link with `render={<a href>}`). Mark the active route
 * with `aria-current="page"` and the `active` style export:
 * `style={sidebarNavItemActive}`.
 */
const { withProvider, withContext } = createSlotRecipeContext(
  sidebarNavItemSlotRecipe,
);

export const sidebarNavItemActive = sidebarNavItemStatic.active;

export const SidebarNavItem = {
  Item: withProvider("li", "item", "SidebarNavItemItem"),
  Button: withContext(
    "button",
    (v) => [
      sidebarNavItemButton.base,
      sidebarNavItemButtonSizes[v.size],
      sidebarNavItemButtonVariants[v.variant],
      sidebarNavItemStatic.button,
    ],
    "SidebarNavItemButton",
  ),
  // sized through the recipe's icon vars on the button slot
  Icon: withContext(
    "svg",
    () => [sidebarNavItemButtonSvg.base],
    "SidebarNavItemIcon",
  ),
  EndElement: withContext("span", "endElement", "SidebarNavItemEndElement"),
};
```
