Command menu

A Cmd+K palette for moving around an app and running actions. Commands can open pages of their own, the ones you ran last come first, a search ranks every command across every page, and a side pane previews the highlighted one.

Command menuClick the field, or press Cmd+K or Ctrl+K anywhere on this page.

Examples

Views

The menu has three views, and a few states within them.

HomeRecent commands first, then your groups in order.
Search resultsOne ranked list across every page, each row naming where it lives.
Page openA back button, a breadcrumb and the page's own hint.
No matchesA search with no results says so.
Without hintsFor apps where people already know the keys.

With a preview

When anything on screen has a preview, the dialog widens and a pane follows the highlight. Commands without one show No preview. When the dialog itself is narrower than 36rem, the pane hides, so it also stays hidden in a small container on a wide screen.

Preview paneFiles show a thumbnail and an excerpt, people their role.

Inset

variant="inset" sets the list in a card inside a muted shell. The search box and the keyboard hints sit on the shell, with no rules between them, so the results read as a layer of their own.

InsetThe same menu, with its list in a card.

Rows

Each row can carry an icon, a shortcut and a chevron for a page. Recent commands and search results also name where they live, and a disabled row fades.

Row statesHighlighted with context, a shortcut, a page, and disabled.

In a header

The usual home: a search field in the app's header, where people look for search.

AcmeProjectsDocs
Click the field in the header.

Your own trigger

Any button can open it in place of the search field.

A ghost button labeled Commands.

Opened from anywhere

With no trigger, the app decides when it opens, from a button, a menu item or the shortcut.

Last command: none

Open it, run a command, and the page shows which.

Inside a card

modal={false} opens the menu without trapping focus, locking the page's scroll or moving focus into it, and opening a page leaves focus where it is. Use it for a menu shown inside a card or a cover rather than over the page.

Non-modalOpen it: focus stays on the field until you click into the menu.

Anatomy

The dialog is three regions stacked over a backdrop: the search field, the list of commands with an optional preview pane beside it, and the keyboard hints.

  1. Search field
  2. Group label
  3. Item
  4. Keyboard hints
  5. Backdrop
  6. Preview pane
The dialogMid-search, so every region is on screen.

Each row carries a label and, when it has them, an icon, where it lives, a shortcut and a chevron for a page.

  1. Group label
  2. Highlighted row
  3. Icon
  4. Disabled row
  5. Context
  6. Shortcut
  7. Page
A rowOne of each kind: highlighted, with a shortcut, opening a page, and disabled.

Guidelines

  • 01Use it for moving around an app and running actions people would otherwise hunt for in menus.
  • 02Start labels with a verb for actions (New file, Change theme) and use the plain name for places and things (Inbox, Roadmap 2027).
  • 03Make an item a page when it needs a choice before it can run: a theme, a person, a status. Keep pages one or two levels deep.
  • 04Add keywords for the words people might type instead: appearance for Change theme, create for New file.
  • 05Give previews to things people pick between by content, such as files and people. Leave them off plain actions.
  • 06Don't make it the only way to reach something. It speeds up people who know it's there.

Best practices

DoGroup the choices for one action on a page of their own.
Don'tDon't list every variant on the first page. It buries the other commands.
DoStart actions with a verb and name places plainly, so the list scans.
Don'tDon't write sentences or mix styles. People read the list as they type.
DoGive previews to things people choose between by content: files, people, records.
Don'tDon't preview plain actions. The pane widens the dialog and mostly says No preview.

Accessibility

Everything works from the keyboard, and the keys are the ones people know from other palettes.

KeyDoes
⌘K or CtrlKDoesOpens and closes the menu from anywhere on the page
↑↓DoesMoves the highlight
↵DoesRuns the highlighted command, or opens its page
⌫DoesOn an empty search, steps back out of a page
EscDoesClears the search, then leaves the page, then closes
  • 01It's a modal dialog named by label. Focus moves to the search box when it opens, stays inside while it's open, and returns to the trigger when it closes.
  • 02With modal set to false it doesn't trap or move focus, so keep it for a menu that's part of the page, such as a demo in a card, where people choose to reach into it.
  • 03The search box is a combobox that points at the highlighted command with aria-activedescendant, so screen readers read each one as the arrows move.
  • 04On a page, the search box is named after it, such as Command menu, Change theme, and the back button says where it goes. Items that open a page say so.
  • 05Escape steps back one level at a time: it clears the search, then leaves the page, then closes the menu without running anything.
  • 06A search announces how many results it found, and the preview pane is a polite live region.
  • 07The keyboard hints are hidden from screen readers, which announce the combobox's keys themselves.
  • 08Every piece of text the menu writes can be translated with labels, alongside placeholder, emptyText and label.

References