Skip to content

Command Palette Search

Dark Tailwind CSS command palette opened with Ctrl+K: live filtering with match highlights, grouped results and full keyboard navigation.

Also known as: command palette, ctrl k search, command menu, quick search modal, spotlight search

Tailwind CSS Search Bars Responsive Dark #command-palette #dark #keyboard #modal #search

Command Palette Search live demo

Open in new tab

Tailwind CSS code (HTML, CSS, JS)

A dark command palette built with Tailwind CSS and vanilla JavaScript, opened with Ctrl + K (⌘ + K on macOS) or a search button. Users type to filter grouped commands, move through results with the arrow keys and press Enter to run one, the same pattern used in code editors, admin dashboards and SaaS apps.

How it works

The root is .tcp-palette. It holds the page content with a search button and suggestion chips marked data-tcp-open, a role="status" message (data-tcp-status) and the .tcp-overlay, which starts hidden. The overlay contains a blurred .tcp-backdrop and the #tcp-dialog panel (.tcp-panel). Inside the panel are the search input (data-tcp-input, role="combobox"), the #tcp-list listbox and a data-tcp-empty message.

Results are grouped: each data-tcp-group item contains a heading and a role="group" list of role="option" items marked data-tcp-option. Each option has a visible label (data-tcp-label) plus hidden search words in data-tcp-keywords, so typing "invoices" finds "Go to Billing".

On every input event the script splits the query into words and keeps only the options that contain all of them. Matching characters are wrapped in <mark class="tcp-mark">, empty groups are hidden and the empty state appears when nothing matches. The first visible result becomes active: it gets aria-selected="true" (styled with the aria-selected: variants) and its id is written to aria-activedescendant, so focus never leaves the input. Arrow Up and Down wrap through results, Ctrl + Home and Ctrl + End jump to the ends, mouse movement updates the active row and a click or Enter runs it. Running a command closes the palette, restores focus, shows a status message and dispatches a tcp:run event.

Customization

  • data-tcp-hotkey="k" on .tcp-palette: change the shortcut letter, or remove the attribute to disable the global shortcut.
  • Add a command by copying an li with role="option" and data-tcp-option; give it a unique id, a data-tcp-label text and search words in data-tcp-keywords.
  • Listen for tcp:run on .tcp-palette and use event.detail.id or event.detail.command to navigate or call your own functions.
  • aria-selected:bg-violet-500/15 on the options and .tcp-mark in style.css: change the active row and match colors.
  • data-tcp-query on any data-tcp-open button: opens the palette pre-filled with that search, like the "billing" and "theme" chips.
  • max-h-80 on #tcp-list: show more or fewer rows before the list scrolls.
  • pt-[10vh] sm:pt-[14vh] on .tcp-overlay: move the panel up or down on the screen.

Use cases

  • Admin dashboards: press Ctrl+K to jump to pages and actions without using the sidebar
  • SaaS apps: grouped commands filter as you type, with matches highlighted in the results
  • Code editor style tools: arrow keys move through results and Enter runs the command
  • Documentation sites: a search button opens the dark palette on any device

Accessibility

The input follows the combobox pattern: role="combobox", aria-controls="tcp-list", aria-autocomplete="list", aria-expanded and aria-activedescendant. The panel is a role="dialog" with aria-modal="true", Escape closes it, Tab keeps focus on the search field and focus returns to the trigger on close. A hidden live region announces how many commands match, decorative icons and key hints are aria-hidden, and entrance animations are disabled under prefers-reduced-motion: reduce.

Usage notes

Only one palette per page should carry data-tcp-hotkey; otherwise every instance would open on the same shortcut. Ctrl + K overrides the browser's search-bar shortcut while the page has focus.

Command Palette Search at a glance

Framework
Tailwind CSS
Code
HTML, CSS, JavaScript
JavaScript
Vanilla JavaScript, no jQuery
Dependencies
Tailwind CSS
Layout
Responsive, works on mobile, dark design
Category
Search Bars
License
Free for personal and commercial use

Questions about this template

Can I use the Command Palette Search code for free?

Yes. You can copy or download the code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my website?

Load Tailwind CSS from a CDN (the links are under Requirements). Paste the HTML where the component should appear, add the CSS to your stylesheet and load the JavaScript before the closing </body> tag. Download HTML gives you a complete page with everything already linked.

Does it need jQuery or a JavaScript framework?

No. The script is plain vanilla JavaScript, so it works without jQuery, React or Vue. You can still use the markup inside those frameworks.

Does it work on mobile?

Yes. The layout adapts to small screens. Use the Mobile and Tablet buttons above the live demo to check it at phone and tablet width.

Requirements

Add these to your page (already included in the download):

  • <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>

The Tailwind browser build is for prototyping. In production, compile Tailwind with its CLI or your bundler.

Command Palette Search – free Tailwind CSS search bar template
Command Palette Search · free Tailwind CSS search bar template

More Search Bars

Expanding Search Bar – free Pure CSS search bar template

Expanding Search Bar

Search icon button that expands into a pill-shaped input, shown in a dark navbar and a large hero search, with Escape to close and a demo submit.

Search with Autocomplete – free Bootstrap 5 search bar template

Search with Autocomplete

Bootstrap 5 help center search bar with an accessible autocomplete list built from local data, highlighted matches, keyboard navigation and popular search chips.