Command Palette
Cmd+K command palette with search and shortcuts.
<div class="w-full max-w-md rounded-2xl border border-slate-200 bg-white shadow-2xl overflow-hidden">
<div class="flex items-center gap-3 px-4 py-3 border-b border-slate-100">
<svg class="w-4 h-4 text-slate-400" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"/></svg>
<input type="text" placeholder="Type a command or search..." class="flex-1 text-sm outline-none placeholder:text-slate-400" />
<kbd class="px-1.5 py-0.5 rounded border border-slate-200 bg-slate-50 text-[10px] font-mono text-slate-500">ESC</kbd>
</div>
<div class="p-2">
<a href="#" class="flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-indigo-50 text-sm">
<span class="w-8 h-8 rounded-lg bg-indigo-100 text-indigo-600 flex items-center justify-center">📄</span>
<span class="flex-1"><span class="block font-semibold text-slate-900">New document</span><span class="block text-xs text-slate-400">Create a blank page</span></span>
<kbd class="text-[10px] font-mono text-slate-400">⌘N</kbd>
</a>
<a href="#" class="flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-indigo-50 text-sm">
<span class="w-8 h-8 rounded-lg bg-emerald-100 text-emerald-600 flex items-center justify-center">⚙️</span>
<span class="flex-1"><span class="block font-semibold text-slate-900">Settings</span><span class="block text-xs text-slate-400">Manage preferences</span></span>
<kbd class="text-[10px] font-mono text-slate-400">⌘,</kbd>
</a>
<a href="#" class="flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-indigo-50 text-sm">
<span class="w-8 h-8 rounded-lg bg-amber-100 text-amber-600 flex items-center justify-center">🌙</span>
<span class="flex-1"><span class="block font-semibold text-slate-900">Toggle theme</span><span class="block text-xs text-slate-400">Switch dark mode</span></span>
<kbd class="text-[10px] font-mono text-slate-400">⌘D</kbd>
</a>
</div>
<div class="px-4 py-2.5 border-t border-slate-100 flex gap-4 text-[11px] text-slate-400">
<span><kbd class="font-mono">↑↓</kbd> navigate</span>
<span><kbd class="font-mono">↵</kbd> select</span>
</div>
</div>Free to use in personal and commercial projects. No attribution required.
Variants
Same component, different looks. Preview each one live and copy the code you like.
Dark
The dark palette matches developer tools and dark-mode apps.
Grouped
Group results when the palette searches across different content types.
About this command palette
The command palette is the power-user interface: press Cmd+K and a search bar appears with every action in your app. Vercel, Linear, Raycast, and GitHub all use it. The cmdk library made it the industry standard, and users now expect Cmd+K everywhere.
This command palette UI gives you the classic structure: search input with icon, grouped action rows with icons and shortcut hints, and a footer with keyboard navigation help. Each row has an icon, a title, a description, and its shortcut.
For a functional palette, add JavaScript that filters rows as you type, navigates with arrow keys, and triggers on Enter. The visual structure here is the hard part; the filtering logic is straightforward. Place the trigger hint (⌘K) in your navbar so users discover it.
Applications with dozens of actions force users to hunt through menus for the one they need. The command palette inverts navigation: instead of learning where things live, users press Cmd+K and type what they want. For power users it is the fastest path through any complex app, which is why the shortcut has become a learned convention across Vercel, Linear, and Raycast.
The container is w-full max-w-md rounded-2xl border bg-white shadow-2xl overflow-hidden. The header row pairs a search icon with an input (flex-1 outline-none) and an ESC kbd hint. Result rows combine a w-8 h-8 rounded-lg icon tile, a title, a short description, and the keyboard shortcut on the right. A footer strip teaches the keys: arrows to navigate, Enter to select. Getting this markup right is most of the work; wiring up the keystrokes and filtering on top of it is the easy part.
Group results under section headers like Suggestions and Settings. Highlight the matched substring in each result so users see why it matched. Rank exact matches and recently used commands first, and cap the visible list around eight rows with scrolling. Put the ⌘K hint in your navbar, because the palette only helps users who discover it.
The focus mistake is opening the palette without focusing the input, forcing every user to click before they can type. That one extra click kills the speed the palette promises. Autofocus the input on open, select its contents on reopen, and make Escape close and return focus to where it was.
Where to use it
- ✓ SaaS app navigation
- ✓ Documentation search
- ✓ Admin panels
- ✓ Developer tools
Customization tips
Group actions with section headers (Suggestions, Settings). Highlight matching text in results. Add recent items at the top for returning users. The footer hints teach keyboard use.
Design notes
When to use
A command palette is the fastest path for power users in apps with dozens of actions, letting them jump anywhere by typing instead of hunting through menus. The Cmd+K shortcut has become a learned convention, so users of tools like VS Code or Linear will try it unprompted. Showing keyboard shortcuts beside each result teaches the faster path while the palette does the immediate job.
What to avoid
Do not add a command palette to a simple marketing site, it will sit unused and add bundle weight for nothing. Avoid listing every trivial action, a palette with two hundred unranked results is just a worse search box. And do not hide core navigation only inside the palette, casual users will never find it.
Accessibility
The search input needs an associated label, and results should be navigable with arrow keys plus Enter to run. Announce result counts politely so screen reader users know when the list updates as they type.
Frequently asked questions
What is a command palette?
A searchable popup (usually Cmd+K) listing all app actions. It lets power users navigate and act without touching the mouse. Vercel, Linear, and Raycast popularized it.
How do I add Cmd+K to my site?
Listen for keydown with metaKey/ctrlKey + k, then show the palette. Libraries like cmdk handle filtering and keyboard navigation.
What should go in a command palette?
Navigation links, common actions (new, save, settings), and theme toggles. Keep it to the 10-15 most useful actions; it is a shortcut, not a sitemap.
How do I add fuzzy search to a command palette?
Implement subsequence matching: every character of the query must appear in the label in order, but not necessarily adjacent. Score matches higher when characters are consecutive or at word starts, then sort by score. Highlight the matched characters in the results so users see why each item matched.
How do I navigate command palette results with arrow keys?
Track an activeIndex in state, move it with ArrowDown and ArrowUp wrapping around the list, run the active command on Enter, and close on Escape. Scroll the active item into view within the results list. Reset the index to 0 whenever the query changes.
Should a command palette show recent commands?
Yes. When the input is empty, show the last few used commands so repeat actions take one keystroke. Persist them in localStorage and update the list on each run. Group results under headings like Recent, Actions, and Navigation once the user starts typing.