---
title: "Context Menu"
description: "A menu that opens where people right-click or press and hold. It holds the actions for the thing under the pointer, with keys, toggles, and submenus."
url: https://gelatinui.com/components/context-menu
markdown_url: https://gelatinui.com/components/context-menu.md
access: free
install: "npx shadcn@latest add @gelatin-ui/context-menu"
registry_item: https://gelatinui.com/r/context-menu.json
version: "2026-11-08"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# Context Menu

> A menu that opens where people right-click or press and hold. It holds the actions for the thing under the pointer, with keys, toggles, and submenus.

Page: https://gelatinui.com/components/context-menu

## When to use it

Best for: Actions for a row, a file, or a canvas that open at the pointer on a right click or a long press.

- Use it for quick actions on a row, a card, or a canvas.
- Use it as a second way to reach actions that the page also shows.
- Use the same item parts as the Menu: items, links, checks, radio items, and submenus.

## When not to use it

- For the only way to reach an action, use a [Menu](https://gelatinui.com/components/menu.md).
- For a long list that needs a filter field, use a [Menu](https://gelatinui.com/components/menu.md).

## Notes for agents

- Nothing shows that the menu is there. Make every action reachable another way.
- `ContextMenuTrigger` is a plain `<div>` with no look of its own.
- Give a row `data-popup-open:bg-foreground/6`, so people see which row the actions act on.
- `ContextMenuContent` renders its own portal. Use `ContextMenuPortal` alone only for your own popup.
- With `arrow`, the popup centers on the pointer, 8px away.
- Base UI has no filter parts in this item.

## Anatomy

```text
ContextMenu
├─ ContextMenuTrigger (0..n)
├─ ContextMenuPortal (0..n)
└─ ContextMenuContent (0..n)
```

## API reference

### ContextMenu

Also takes every prop of Base UI `ContextMenu.Root`: https://base-ui.com/react/components/context-menu

### ContextMenuTrigger

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  |  |

### ContextMenuPortal

Also takes every prop of Base UI `Menu.Portal`: https://base-ui.com/react/components/menu

### ContextMenuContent

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  |  |
| `arrow` | `boolean` | false | Show an arrow that points at the trigger. The gap grows from 4px to 8px. |
| `backdrop` | `boolean` | false | Put a clear layer under the popup (Base UI `Menu.Backdrop`), for example to dim it. |
| `portalProps` | `Omit` |  | Other Base UI props of the inner parts. A `className` here adds to the component classes. |
| `positionerProps` | `PopupPartProps` |  |  |
| `backdropProps` | `PopupPartProps<MenuBackdropProps>` |  |  |
| `arrowProps` | `PopupPartProps<MenuArrowProps>` |  |  |

Also takes every prop of Base UI `Menu.Popup`: https://base-ui.com/react/components/menu

## Styling

| Part | Slot | States | CSS variables | Tokens |
| --- | --- | --- | --- | --- |
| ContextMenuTrigger | `context-menu-trigger` |  |  |  |
| ContextMenuPortal | `context-menu-portal` |  |  |  |
| ContextMenuContent | `context-menu-content` |  |  |  |

## Usage

`ContextMenuTrigger` is a plain `div` with no look of its own. Nothing shows that the menu is there, so make every action reachable another way.

```tsx title="file-row-menu.tsx"
import {
  ContextMenu,
  ContextMenuContent,
  ContextMenuItem,
  ContextMenuTrigger,
} from "@/components/ui/context-menu";

export function FileRowMenu() {
  return (
    <ContextMenu>
      <ContextMenuTrigger className="rounded-lg border p-4 text-sm">Q3 report.pdf</ContextMenuTrigger>
      <ContextMenuContent>
        <ContextMenuItem>Rename</ContextMenuItem>
        <ContextMenuItem variant="destructive">Delete</ContextMenuItem>
      </ContextMenuContent>
    </ContextMenu>
  );
}
```

## Compose

Rules:

- Compose the parts (`compose-parts`): Build each item from its named parts as children, and pass your text and icons in as parts.
- Every state is designed (`every-state`): Give each view of data its loading, empty, and error states: a skeleton in the final layout, an `Empty` with an illustration and one next action, and an error that says what failed and how to retry.

## Add it

```bash
npx shadcn@latest add @gelatin-ui/context-menu
```

It adds 20 registry items: 17 files, 3482 lines, and the npm packages `@base-ui/react`, `@phosphor-icons/react`, `clsx`, `tailwind-merge`, `tailwind-variants`.

## Built on

- [Menu](https://gelatinui.com/components/menu.md)

## For AI agents

- Every item, one file: https://gelatinui.com/llms.txt
- MCP server (`search_items`, `get_item`, `get_install_plan`): https://gelatinui.com/mcp

## Related

- [Menu](https://gelatinui.com/components/menu.md): Pick Menu for actions from a button: a Context Menu must never be the only way to reach an action.
- [Popover](https://gelatinui.com/components/popover.md)
- [Tree](https://gelatinui.com/components/tree.md)

## Keyboard

| Keys | Action |
| --- | --- |
| Arrow Down, Arrow Up | Moves to the next or the previous item. |
| Home, End | Moves to the first or the last item. |
| Enter, Space | Runs the item, or changes a check or a radio choice. |
| Letter keys | Moves to the item whose text starts with the typed letters. |
| Arrow Right | Opens a submenu. In right to left, use Arrow Left. |
| Arrow Left | Closes a submenu. In right to left, use Arrow Right. |
| Escape | Closes the menu. |

## Accessibility

It is a Base UI Context Menu. The popup has the `menu` role, and the arrow keys move between items.

A right click opens it on a desktop, and a 500ms press and hold opens it on touch.

A keyboard has no sure way to open it, so give each action another path.

## Motion

| Part | Motion |
| --- | --- |
| Open | popup · 150ms · ease-panel (0.2, 0.4, 0.2, 1) · fades in and scales from 95% |
| Close | popup-exit · 120ms · ease-out (0, 0, 0.2, 1) |
