Command Palettes
A navigation dialog: search a list of pages and open one with the keyboard.
Basic
A dialog with a search box and a list of pages, opened with the button or Ctrl/Cmd+K (only the layout palette, whose id is command-palette, answers the shortcut). The pages come from items, each with a text, an optional hint, an href, and an optional target, followed by the links of the page marked with data-palette-text. Typing filters by the text and the hint; the arrow keys move, Enter or a click opens the page, and an item with target="_blank" opens in a new tab. Esc or a click outside closes the dialog and the focus goes back to the button. Try typing “products”.
<div
x-data='commandPalette({"id":"command-palette-basic","items":[{"text":"Dashboard","hint":"Showcase","href":"/index.html"},{"text":"All Products","hint":"Showcase › Products","href":"/products/all-products.html"},{"text":"Create New Product","hint":"Showcase › Products","href":"/products/form-product.html"},{"text":"Full Sidebar","href":"/layouts/full-sidebar.html"},{"text":"Button","hint":"Components","href":"/components/button.html"},{"text":"Input","hint":"Components › Form controls","href":"/components/form-controls/input.html"},{"text":"Toast","hint":"Services","href":"/services/toast.html"},{"text":"Alpine.js","hint":"Resources","href":"https://alpinejs.dev","target":"_blank"}]})'
x-on:keydown.window="shortcut($event)"
id="command-palette-basic"
class="group/palette"
>
<button
id="command-palette-basic-button"
class="inline-flex items-center gap-3 px-3 py-2 text-sm text-dominant-700 dark:text-dominant-200 bg-white dark:bg-dominant-950 rounded-lg inset-ring inset-ring-dominant-500 dark:inset-ring-dominant-400 cursor-pointer hover:bg-dominant-50 dark:hover:bg-dominant-800 focus-visible:ring-2 focus-visible:ring-primary-700 dark:focus-visible:ring-primary-400 focus-visible:outline-none"
type="button"
aria-controls="command-palette-basic-panel"
aria-expanded="false"
aria-haspopup="dialog"
>
<i aria-hidden="true" class="fa-solid fa-magnifying-glass"> </i>
<span class="flex-1 text-left">Search pages</span>
<kbd
class="px-1.5 py-0.5 font-mono text-xs text-dominant-700 dark:text-dominant-200 bg-dominant-50 dark:bg-dominant-800 rounded border border-dominant-300 dark:border-dominant-600"
>
Ctrl K
</kbd>
</button>
<div
class="fixed inset-0 z-50 overflow-y-auto bg-dominant-950/60 opacity-0 invisible transition-all duration-200 overscroll-contain motion-reduce:transition-none group-has-[button[aria-expanded=true]]/palette:visible group-has-[button[aria-expanded=true]]/palette:opacity-100"
>
<div class="flex items-start justify-center p-4 pt-16 min-h-full sm:p-6 sm:pt-24">
<div
id="command-palette-basic-panel"
aria-label="Command palette"
class="relative overflow-hidden w-full max-w-xl bg-white dark:bg-dominant-900 rounded-xl shadow-xl scale-95 transition-all duration-200 dark:ring-1 dark:ring-dominant-700 motion-reduce:transition-none group-has-[button[aria-expanded=true]]/palette:scale-100"
>
<div
class="flex items-center gap-3 px-4 border-b border-dominant-200 dark:border-dominant-700"
>
<i
aria-hidden="true"
class="text-dominant-600 dark:text-dominant-300 fa-solid fa-magnifying-glass"
>
</i>
<input
id="command-palette-basic-search"
type="text"
role="combobox"
aria-expanded="true"
aria-controls="command-palette-basic-list"
aria-autocomplete="list"
aria-label="Search pages"
autocomplete="off"
placeholder="Search pages"
x-model="query"
x-bind:aria-activedescendant="results.length ? prefix + '-option-' + active : null"
x-on:input="active = 0"
x-on:keydown.arrow-down.prevent="move(1)"
x-on:keydown.arrow-up.prevent="move(-1)"
x-on:keydown.home.prevent="active = 0"
x-on:keydown.end.prevent="active = results.length - 1"
x-on:keydown.enter.prevent="run(results[active])"
class="flex-1 py-4 min-w-0 text-sm text-dominant-900 dark:text-white bg-transparent placeholder:text-dominant-600 dark:placeholder:text-dominant-400 focus:outline-none"
/>
<kbd
aria-hidden="true"
class="px-1.5 py-0.5 font-mono text-xs text-dominant-700 dark:text-dominant-200 bg-dominant-50 dark:bg-dominant-800 rounded border border-dominant-300 dark:border-dominant-600"
>
Esc
</kbd>
</div>
<div
id="command-palette-basic-list"
role="listbox"
aria-label="Results"
class="overflow-y-auto p-2 max-h-80"
>
<template x-for="(item, index) in results" x-bind:key="index + ' ' + item.href">
<div
role="option"
x-bind:id="prefix + '-option-' + index"
x-bind:aria-selected="index === active"
x-on:mousemove="active = index"
x-on:click="run(item)"
class="flex items-center gap-3 px-3 py-2 text-sm text-dominant-800 dark:text-dominant-100 rounded-lg cursor-pointer aria-selected:bg-primary-50 dark:aria-selected:bg-primary-900/50 aria-selected:text-primary-900 dark:aria-selected:text-white"
>
<span x-text="item.text" class="flex-1 min-w-0 truncate"> </span>
<span
x-show="item.hint"
x-text="item.hint"
class="min-w-0 max-w-1/2 truncate text-xs text-dominant-700 dark:text-dominant-300"
>
</span>
<i
x-show="item.target === '_blank'"
aria-hidden="true"
class="text-xs text-dominant-600 dark:text-dominant-300 fa-solid fa-arrow-up-right-from-square"
>
</i>
<span x-show="item.target === '_blank'" class="sr-only"> (opens in a new tab) </span>
</div>
</template>
<div
x-show="!results.length"
role="status"
style="display: none"
class="flex flex-col items-center px-6 py-10 text-center"
>
<span
aria-hidden="true"
class="flex items-center justify-center size-12 text-dominant-700 dark:text-dominant-200 bg-dominant-100 dark:bg-dominant-800 rounded-full"
>
<i class="text-xl fa-solid fa-magnifying-glass"> </i>
</span>
<p class="mt-4 text-base font-semibold text-dominant-900 dark:text-white">
No results for “
<span x-text="query"> </span>
”
</p>
<p class="mt-1 text-sm text-dominant-700 dark:text-dominant-200">
Check the spelling or try another word.
</p>
</div>
</div>
<div
aria-hidden="true"
class="flex items-center gap-4 px-4 py-2.5 text-xs text-dominant-700 dark:text-dominant-200 border-t border-dominant-200 dark:border-dominant-700"
>
<span>
<kbd
class="px-1.5 py-0.5 font-mono text-xs text-dominant-700 dark:text-dominant-200 bg-dominant-50 dark:bg-dominant-800 rounded border border-dominant-300 dark:border-dominant-600"
>
↑
</kbd>
<kbd
class="px-1.5 py-0.5 font-mono text-xs text-dominant-700 dark:text-dominant-200 bg-dominant-50 dark:bg-dominant-800 rounded border border-dominant-300 dark:border-dominant-600"
>
↓
</kbd>
to move
</span>
<span>
<kbd
class="px-1.5 py-0.5 font-mono text-xs text-dominant-700 dark:text-dominant-200 bg-dominant-50 dark:bg-dominant-800 rounded border border-dominant-300 dark:border-dominant-600"
>
Enter
</kbd>
to open
</span>
</div>
</div>
</div>
</div>
</div>
Empty
When nothing matches, the list says so in a role="status" block (the Empty State pattern, small) and keeps the box so the person can correct the search. This preview is a static picture (inert); the live palette above shows the same state when you type something that matches nothing.
No results for “zzz”
Check the spelling or try another word.
<div
inert
aria-label="No results"
class="overflow-hidden max-w-xl bg-white dark:bg-dominant-900 rounded-xl border border-dominant-200 dark:border-dominant-700 shadow-sm"
>
<div
class="flex items-center gap-3 px-4 py-3.5 text-sm border-b border-dominant-200 dark:border-dominant-700"
>
<i
aria-hidden="true"
class="text-dominant-600 dark:text-dominant-300 fa-solid fa-magnifying-glass"
>
</i>
<span class="text-dominant-900 dark:text-white"> zzz </span>
</div>
<div class="flex flex-col items-center px-6 py-10 text-center">
<span
aria-hidden="true"
class="flex items-center justify-center size-12 text-dominant-700 dark:text-dominant-200 bg-dominant-100 dark:bg-dominant-800 rounded-full"
>
<i class="text-xl fa-solid fa-magnifying-glass"> </i>
</span>
<p class="mt-4 text-base font-semibold text-dominant-900 dark:text-white">
No results for “zzz”
</p>
<p class="mt-1 text-sm text-dominant-700 dark:text-dominant-200">
Check the spelling or try another word.
</p>
</div>
</div>
Options reference
The dialog opens and closes with the global dialog behaviour; command-palette.js only filters, highlights, and opens the page.
| Part | Value | Description |
|---|---|---|
label
|
string | The trigger text. Default “Search pages”. |
items
|
{ text, hint, href, target }[]
|
The pages. hint and target are optional. After them, the palette lists the links with data-palette-text (and an optional data-palette-hint), read each time it opens; a link whose href is already an item is left out. The layouts rely on the sidebar links.
|
button-class
|
classes | Extra classes of the trigger. Every attribute that is not a prop goes to the root. |
| Trigger |
button with aria-haspopup="dialog", aria-controls, aria-expanded
|
Its id is <id>-button, and button-class adds classes to it. The global dialog behaviour opens and closes the panel, traps Tab, closes on Esc or a click outside, and returns the focus.
|
| Dialog |
<id>-panel, aria-label
|
The panel. It gets role="dialog" and aria-modal while it is open.
|
| Search |
<id>-search, role="combobox"
|
aria-controls the list, aria-expanded="true", aria-autocomplete="list" and aria-activedescendant with the id of the highlighted option.
|
| List |
<id>-list, role="listbox"
|
Each page is role="option" with the id <id>-option-<index> and aria-selected.
|
| Keys | Ctrl/Cmd+K, ↑ ↓, Home, End, Enter, Esc | Open (layout palette only), move, jump to the first or last, open the page, close. |
| Empty |
role="status"
|
Shown when no page matches; keeps the search box. |