Puneet Sharma - Frontend Developer & UI Engineer
Puneet Sharma
Frontend Dev & UI Engineer · 16+ yrs · pixel-perfect HTML, React & WordPress

10 Free Bootstrap 5 Snippets for Search, Command Palettes & Developer Utilities: A Real Ctrl+K, Safe Regex Highlighting & a Recursive JSON Viewer

10 Bootstrap 5 snippets: a real Ctrl+K palette, safe regex highlighting, a recursive JSON viewer. Editable, exports to React, Vue, Angular, Tailwind.
10 Free Bootstrap 5 Snippets for Search, Command Palettes & Developer Utilities: A Real Ctrl+K, Safe Regex Highlighting & a Recursive JSON Viewer

This batch is about the tools power users and developers actually reach for constantly: a Ctrl+K command palette, a search box that remembers what you searched last time, results that highlight exactly what matched, and the small copy/status/code-display components that show up in every dashboard and every README. None of these are decorative — every keyboard shortcut is a real global listener, every highlight is safely escaped, and every copy button falls back correctly outside a secure context. Every one still loads the genuine bootstrap.min.css and bootstrap.bundle.min.js from a CDN and builds on Bootstrap's real component classes.

Every one is a live, interactive preview you can try right here in the article, and each exports to React, Vue, Angular or Tailwind in one click from its snippet page.

What these ten get right

  • Two escaping passes, not one. The search-highlighting snippet escapes the result text for safe HTML injection and escapes the user's query before it's ever turned into a RegExp — skip either one and a user typing a regex-special character like ( either breaks the search or opens an HTML-injection hole.
  • A filtered index that can't point past its own list. The command palette re-clamps its highlighted activeIndex after every keystroke, so filtering down to two results while the fourth item was highlighted can never silently point at nothing.
  • Real recursion, not a fixed two levels. The API response viewer's tree renderer calls itself for every nested object or array however deep, with each collapsible node getting its own unique id so collapsing one section never touches any other.
  • Copy that actually falls back. The copy-to-clipboard and code-block snippets both try the modern navigator.clipboard API first and fall back to a working document.execCommand('copy') path outside a secure context or on a denied permission — and each button tracks its own "flashing" state independently.
  • Real range math, not a hardcoded table. The HTTP status badge classifies any valid 3-digit code by numeric range, correctly coloring a code that never appears in its own reference list.

1. Bootstrap Filter Chips

Toggle filter buttons and each active one appears as a removable chip — clicking a chip's × deactivates its exact originating toggle button, not just the pill.

How it works: one active Set is the single source of truth for both the toggle buttons and the chip row, so removing a chip and clicking its toggle button off are always describing the same underlying change. Filters combine with real AND logic — Array.from(active).every(f => matches(p, f)) — so stacking "In stock" and "Under $50" narrows the list instead of just adding more results.

Best for: ecommerce filter sidebars and admin table filters where the currently applied conditions need to stay visible and individually removable. Tip: pair with an advanced search panel to summarize a multi-field search as chips.

Grab the code: Bootstrap Filter Chips

2. Bootstrap Advanced Search Panel

A collapsible filter panel — status, priority, a date range — with a live badge counting active filters on the toggle button, and a generated plain-English summary of the current search.

How it works: the panel uses Bootstrap's real collapse component, inheriting its built-in animation and ARIA wiring for free rather than a custom show/hide. The badge counts only the structured dropdown and date fields, not the free-text keyword, since that already has its own visible place in the summary sentence. "Reset" clears every field and re-syncs the badge and summary in one action.

Best for: support ticket dashboards and any list view needing more than a single search box. Tip: combine with filter chips to also show each applied criterion as its own removable pill.

Grab the code: Bootstrap Advanced Search Panel

3. Bootstrap Search With Recent Searches

A search box backed by real localStorage — up to 5 recent searches appear on an empty, focused input, deduplicated and most-recent-first, and clicking one re-runs it instantly.

How it works: re-searching an existing term case-insensitively removes the old entry before unshifting it back to the front, so repeating a search moves it to the top instead of creating a duplicate. The dropdown only ever shows on an empty, focused input — it's a shortcut for starting a new search, not a suggestion list competing with active typing — and every localStorage read/write is wrapped in try/catch so a blocked storage API degrades to "no history" instead of breaking the box.

Best for: documentation search and any returning-user search box where repeating a recent query in one click beats retyping it. Tip: the try/catch guard matters specifically for private browsing, where storage is often blocked or cleared.

Grab the code: Bootstrap Search With Recent Searches

4. Bootstrap Search Results Highlighting

A live search where the matching substring of every visible result is wrapped in a real <mark> — safely, even if you search for a character like ( that means something different in regex.

How it works: the query is escaped for safe use inside a RegExp before it's ever built into a pattern — without that, a user typing a regex-special character would either throw an error or match unpredictably. The result text is separately HTML-escaped before highlighting, so it can never be misinterpreted as markup. A capturing group in the replacement preserves the original text's exact casing, so searching "grid" still highlights "Grid" with its real capital G.

Best for: documentation search, admin log viewers, and any filtered list where seeing exactly what matched speeds up scanning. Tip: both escaping passes are load-bearing — skip the regex one and a search for * throws; skip the HTML one and result text becomes an injection risk.

Grab the code: Bootstrap Search Results Highlighting

5. Bootstrap Command Palette

A real Ctrl+K (Cmd+K on Mac) command palette built on a genuine Bootstrap modal — live filtering, full arrow-key navigation, and Enter to run the highlighted command.

How it works: a global keydown listener checks for (e.ctrlKey || e.metaKey) && e.key === 'k' and funnels into the same open() function the visible button uses, resetting the query and highlight every time. Filtering and keyboard navigation share one activeIndex, re-clamped after every keystroke against the current filtered list's length — the single most common bug in a homemade command palette is skipping that clamp and letting the highlight point past the end of a shortened list.

Best for: developer tools, internal admin panels, and any SaaS dashboard with more destinations than fit in a menu. Tip: pair with the keyboard shortcut help modal below to document every shortcut in one place.

Grab the code: Bootstrap Command Palette

6. Bootstrap Keyboard Shortcut Help Modal

Press "?" anywhere on the page to open a modal listing every shortcut by category — except while you're actually typing in a field, where the shortcut correctly stays silent.

How it works: an isTypingContext() check covers INPUT, TEXTAREA, and isContentEditable elements, and the global "?" listener bails out entirely whenever focus is inside one of them — without it, a user typing a literal question mark into any text field would unexpectedly pop the help modal open mid-sentence.

Best for: any app with more than a couple of custom keyboard shortcuts, especially one that already has a command palette worth documenting. Tip: generate the shortcut list from the same data structure that registers each shortcut's real handler, so the documented list and the actual behavior can never drift apart.

Grab the code: Bootstrap Keyboard Shortcut Help Modal

7. Bootstrap Copy-to-Clipboard Feedback

Two copy buttons — an API key and a referral link — each showing a genuine "Copied!" flash that reverts on its own, with a working fallback outside a secure context.

How it works: it tries navigator.clipboard.writeText() first and falls back to a working document.execCommand('copy') path — via a temporary off-screen textarea — whenever the modern API is unavailable or its permission is denied. Each button tracks its own "flashing" busy state on its own dataset rather than one shared flag, so copying the API key can never reset or interfere with the referral link's independent flash animation.

Best for: API keys, tokens, referral links, and any short string a user needs to grab and paste elsewhere with unambiguous confirmation. Tip: the per-button busy guard matters the moment a page has more than one copy button — a shared flag would let one button's click interfere with another's.

Grab the code: Bootstrap Copy-to-Clipboard Feedback

8. Bootstrap API Response Viewer

A recursively rendered JSON tree, syntax-colored by type, with every object and array independently collapsible — plus a Copy JSON button that always copies a freshly re-serialized, valid document.

How it works: renderNode() is genuinely recursive — it calls itself for every nested object or array, however deep, rather than special-casing two fixed levels. Each collapsible node gets a unique generated id so its toggle and its children block find each other regardless of how many other collapsible nodes exist elsewhere in the tree, meaning collapsing one section never affects any other. Copy JSON re-serializes the original data object fresh rather than scraping the rendered HTML, so the clipboard always holds valid JSON regardless of what's currently collapsed on screen.

Best for: internal admin tools and API debugging dashboards where inspecting a payload's exact shape matters. Tip: pair with the HTTP status badge below for a fuller request/response inspection panel.

Grab the code: Bootstrap API Response Viewer

9. Bootstrap Code Block With Copy + Line Numbers

A dark, editor-style code block with a synchronized line-number gutter and a Copy button that copies the raw source — never the rendered, highlighted HTML.

How it works: the gutter and the code pane are both generated from the exact same array of lines, so a line number and its code can never drift apart even as lines are added or removed. Copy joins the original plain-text array with real newlines rather than reading the DOM's innerHTML — copying rendered HTML would paste literal <span class="..."> tags into whatever the user pastes into.

Best for: documentation, README pages, and API examples showing a command or usage snippet exactly as a developer would want to copy and run it. Tip: the line-based comment/string coloring here is deliberately lightweight — swap in highlight.js from a CDN for genuinely complex multi-language syntax highlighting.

Grab the code: Bootstrap Code Block With Copy + Line Numbers

10. Bootstrap HTTP Status Badge

Type any 3-digit status code and it colors and labels itself live by family — 2xx, 3xx, 4xx, 5xx — plus a row of clickable common codes for quick reference.

How it works: a small FAMILIES array of numeric range tests decides every code's color and label — not a lookup table mapping every possible 3-digit code by hand — which is exactly what correctly colors an unusual code like 418 as a client error even though it never appears in the reference list. The input strips non-digit characters live, and an explicit neutral state handles empty or out-of-range input rather than guessing at a family for it.

Best for: API documentation, internal developer references, and coloring a live table of recent request outcomes by status family. Tip: reuse the same familyFor() range logic to color-code a webhook or API log table elsewhere in a dashboard.

Grab the code: Bootstrap HTTP Status Badge

Same as every batch before it, each of these ten lives in the category that actually fits its shape, so they surface alongside every other snippet of that kind rather than sitting in a library of their own. Find these ten and every other Bootstrap snippet in the collection in one place via the Bootstrap tag. Open any of them above and you land straight in the live editor, HTML/CSS/JS tabs and all; click Save as to copy it into My Code and start changing it.

About the author

Puneet Sharma
Puneet Sharma is a freelance web developer and the creator of FWD Tools and WebDevPuneet. Follow him on X/Twitter

Post a Comment