Skip to content

FAQ with Live Search Filter

Tailwind CSS FAQ section with a live search box that filters questions as you type, highlights matches, adds topic chips and shows an empty state.

Also known as: searchable faq, faq search bar, filterable faq accordion, faq with search

FAQ with Live Search Filter live demo

Open in new tab

Tailwind CSS code (HTML, CSS, JS)

An FAQ section with a live search filter, built with Tailwind CSS and vanilla JavaScript. As visitors type, the question list narrows instantly, matching words are highlighted in questions and answers, and topic chips let them combine search with a category. It fits help centers, pricing pages, checkout pages and product documentation.

How it works

The root is .tfq-faq, a two-column grid on large screens: the intro, search form and topic chips on the left, the questions on the right. Each question is a native details element with the class .tfq-item and a data-tfq-topic value, so the accordion opens and closes without JavaScript. The plus icon rotates into a cross through group-open:rotate-45.

The script initializes every .tfq-faq on DOMContentLoaded. It stores the original text of every element marked data-tfq-text and listens to the input event on data-tfq-input. The search value is split into words; an item stays visible only if all words appear in its question or answer and its topic matches the pressed chip. Matches are wrapped in mark.tfq-mark elements built with textContent, so no HTML is ever injected. Answers that contain the term open automatically and close again when the search is cleared. The data-tfq-count line reports the number of matches, and when nothing matches the list is hidden and the data-tfq-empty panel appears with a data-tfq-clear button. Escape clears the field, Enter moves focus to the first result, and pressing / anywhere on the page jumps to the search box.

Customization

  • Add questions by copying a .tfq-item block and setting its data-tfq-topic; the count updates automatically.
  • Add a topic by adding a chip with a matching data-tfq-topic value to the role="group" container.
  • bg-teal-50, text-teal-700 and aria-pressed:bg-teal-700: swap teal for another Tailwind color to retheme the section and the active chip.
  • background: #fde68a in .tfq-mark (style.css): change the highlight color of matched words.
  • lg:grid-cols-[minmax(0,5fr)_minmax(0,7fr)] on the inner grid: adjust the column ratio, or remove it for a single centered column.
  • Remove the open attribute from the first details to start with every answer collapsed.
  • In update() in script.js, pass null instead of regex to highlight() to filter the list without highlighting matches.

Use cases

  • Help centers: visitors type a few words and the question list narrows instantly with matches highlighted
  • Pricing pages: shoppers find billing answers quickly by combining search with topic chips
  • Checkout pages: buyers look up shipping and returns questions without leaving the order flow
  • Product documentation: readers jump to the search box by pressing the slash key and filter by topic

Accessibility

The form has role="search", the input has a visible label and an aria-describedby hint, and aria-controls points to the list. The match count is a polite role="status" region, so screen readers hear how many questions remain after each keystroke. Topic chips are toggle buttons with aria-pressed. The native details/summary elements are keyboard operable with Enter and Space, and every control has a visible teal focus outline. The answer reveal animation is turned off under prefers-reduced-motion: reduce.

Usage notes

For more than one FAQ on a page, give each search input and list its own id and update the matching for, aria-controls and aria-describedby values.

FAQ with Live Search Filter at a glance

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

Questions about this template

Can I use the FAQ with Live Search Filter 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.

FAQ with Live Search Filter – Tailwind CSS faq sections component screenshot
FAQ with Live Search Filter · Tailwind CSS FAQ Sections

More FAQ Sections

Two-Column FAQ – Bootstrap 5 faq sections preview

Two-Column FAQ

Bootstrap 5 FAQ section with questions split into two accordion columns, plus/minus icons and a dark contact support prompt.

FAQ Accordion Section for Shopify – Shopify faq sections preview

FAQ Accordion Section for Shopify

Shopify FAQ section with a native details accordion, an intro column with contact button, and optional FAQPage structured data.

FAQ with Category Tabs – Bootstrap 5 faq sections preview

FAQ with Category Tabs

Bootstrap 5 FAQ section where category pills switch between separate accordion sets, with question counts and a support card.

FAQ Accordion Section – Tailwind CSS faq sections preview

FAQ Accordion Section

Dark Tailwind CSS FAQ section with an accessible accordion, smooth expand animation, keyboard navigation and a support contact card.