Theming
You can style the menu by loading the default CSS and overriding variables, or by passing a theme config (class and/or tokens). Item variants add optional CSS classes for danger, info, success, warning, and muted.
Default styles
Load the default stylesheet so the menu has background, padding, and hover states. Without it, the menu is unstyled but still functional.
@import "@enegalan/contextmenu.js/dist/style.css";Or in JS:
import "@enegalan/contextmenu.js/dist/style.css";Override with CSS variables
Target the menu root (e.g. .cm-menu or a class you set via theme.class) and set variables. This applies to all menus using that class.
@import "@enegalan/contextmenu.js/dist/style.css";
.cm-menu {
--cm-bg: #1e1e1e;
--cm-fg: #eee;
--cm-radius: 8px;
}Theme config (class + tokens)
Pass theme when creating the menu. class adds a CSS class to the menu root so you can scope overrides. tokens set CSS variables (e.g. bg → --cm-bg, fg → --cm-fg).
createContextMenu({
menu: [...],
theme: {
class: "my-menu",
tokens: { bg: "#1e1e1e", fg: "#eee" },
},
});CSS variables reference
Set these on the menu root (e.g. .cm-menu or your theme class). All variables are listed with their default values from the default stylesheet.
Menu container
| Variable | Description | Default |
|---|---|---|
| --cm-bg | Menu background color | #fff |
| --cm-fg | Foreground (text) color | #1a1a1a |
| --cm-radius | Menu border radius | 12px |
| --cm-shadow | Box shadow of the menu | 0 4px 12px rgba(0, 0, 0, 0.15) |
| --cm-border | Menu border | 1px solid rgba(0, 0, 0, 0.08) |
| --cm-z-index | Z-index of the menu and overlay | 9999 |
| --cm-menu-padding | Inner padding of the menu (vertical horizontal) | 4px 0 |
| --cm-menu-min-width | Minimum menu width | 8rem |
| --cm-menu-max-height | Maximum height before the menu scrolls. Use none for no limit. | none |
Menu items
| Variable | Description | Default |
|---|---|---|
| --cm-item-padding-x | Horizontal padding of each item | 12px |
| --cm-item-padding-y | Vertical padding of each item | 8px |
| --cm-item-radius | Border radius of each item | 0 |
| --cm-item-hover-bg | Background of menu items on hover and focus | rgba(0, 0, 0, 0.06) |
| --cm-font-size | Base font size of the menu | 14px |
| --cm-disabled-opacity | Opacity applied to disabled items | 0.5 |
| --cm-leading-width | Width of the leading slot (icon/check area) | 20px |
Shortcuts
| Variable | Description | Default |
|---|---|---|
| --cm-shortcut-font-size | Font size of keyboard shortcut text | 0.9em |
| --cm-shortcut-opacity | Opacity of shortcut text | 0.7 |
| --cm-shortcut-icon-size | Size of shortcut icons | 1em |
Separators
| Variable | Description | Default |
|---|---|---|
| --cm-separator-bg | Background (line) color of separators | rgba(0, 0, 0, 0.08) |
| --cm-separator-margin | Margin around separator lines (vertical horizontal) | 4px 8px |
| --cm-separator-height | Height of separator lines | 1px |
Labels
| Variable | Description | Default |
|---|---|---|
| --cm-label-font-size | Font size of section labels | 0.75em |
| --cm-label-opacity | Opacity of section labels | 0.7 |
Badges
| Variable | Description | Default |
|---|---|---|
| --cm-badge-font-size | Font size of item badges | 0.75em |
| --cm-badge-opacity | Opacity of badges | 0.8 |
| --cm-badge-padding | Padding inside badges | 1.5px 8px |
| --cm-badge-border-radius | Border radius of badges | 10px |
| --cm-badge-box-shadow | Box shadow of badges | none |
| --cm-badge-background | Background color of badges | rgba(0, 0, 0, 0.1) |
| --cm-badge-border-width | Badge border width | 0 |
| --cm-badge-border-style | Badge border style | solid |
| --cm-badge-border-color | Badge border color | transparent |
Check and radio
| Variable | Description | Default |
|---|---|---|
| --cm-check-size | Size of checkbox indicators | 14px |
| --cm-radio-size | Size of radio indicators | 14px |
Submenu arrow
| Variable | Description | Default |
|---|---|---|
| --cm-submenu-arrow-size | Size of the arrow indicating a submenu (triangle) | 5px |
Spinner
| Variable | Description | Default |
|---|---|---|
| --cm-spinner-size | Size of the loading spinner | 14px |
| --cm-spinner-duration | Duration of one full rotation of the loading spinner | 0.6s |
Animations
| Variable | Description | Default |
|---|---|---|
| --cm-enter-duration | Duration of the enter animation | 120ms |
| --cm-enter-easing | Easing of the enter animation | ease-out |
| --cm-leave-duration | Duration of the leave animation | 80ms |
| --cm-leave-easing | Easing of the leave animation | ease-in |
For more details and examples, see Animations.
Item variants
These variables control the look of items that use variant (e.g. variant: "danger"). Each variant has a text color and a hover/focus background.
| Variable | Description | Default |
|---|---|---|
| --cm-danger-color | Text color for variant danger | #c53030 |
| --cm-danger-hover-bg | Hover/focus background for variant danger | rgba(197, 48, 48, 0.1) |
| --cm-info-color | Text color for variant info | #2b6cb0 |
| --cm-info-hover-bg | Hover/focus background for variant info | rgba(43, 108, 176, 0.1) |
| --cm-success-color | Text color for variant success | #276749 |
| --cm-success-hover-bg | Hover/focus background for variant success | rgba(39, 103, 73, 0.1) |
| --cm-warning-color | Text color for variant warning | #c05621 |
| --cm-warning-hover-bg | Hover/focus background for variant warning | rgba(192, 86, 33, 0.1) |
| --cm-muted-color | Text color for variant muted | #718096 |
| --cm-muted-hover-bg | Hover/focus background for variant muted | rgba(113, 128, 150, 0.1) |
Item variants
Action items can set variant to get an extra CSS class and often a different color. Classes added: .cm-item--danger, .cm-item--info, .cm-item--success, .cm-item--warning, .cm-item--muted. You can override these in your CSS.
{ label: "Delete", variant: "danger", onClick: () => remove() }Runtime theme change
Use menu.setOptions({ theme }) to switch theme after creation. Pass theme: undefined to clear.
menu.setOptions({ theme: { class: "my-dark", tokens: { bg: "#1a1a1a", fg: "#eee" } } });
menu.setOptions({ theme: undefined }); // clear themeDark theme example
Copy-paste to get a dark menu: load the default CSS, then add a class and set tokens: theme: { class: "cm-dark", tokens: { bg: "#1a1a1a", fg: "#e0e0e0" } }. In your CSS, target .cm-dark and override --cm-item-hover-bg / --cm-separator-bg if you want different hover and separator colors.