Help center FAQ
A searchable FAQ with topic chips: answers filter as you type, matching words light up, and each question opens smoothly with a 'Was this helpful?' prompt.
"use client";
import { useId, useState, type ReactNode } from "react";
import "./help-faq.css";
type Item = { q: string; a: string; topic: string };
const TOPICS = ["All", "Billing", "Account", "Shipping", "Returns"];
const ITEMS: Item[] = [
{
topic: "Billing",
q: "When will I be charged?",
a: "On the day your trial ends, and then on the same date each month. You get an email reminder three days before the first charge.",
},
{
topic: "Billing",
q: "Can I get an invoice with my company details?",
a: "Yes. Add your company name, address and tax number under Settings → Billing, and every new invoice will include them. Older invoices can be regenerated from the same page.",
},
{
topic: "Account",
q: "How do I change my email address?",
a: "Go to Settings → Profile and edit the email field. We send a confirmation link to the new address; the change applies once you click it.",
},
{
topic: "Account",
q: "Can I delete my account?",
a: "Yes, from Settings → Privacy. Your data is removed within 30 days. Download an export first if you want to keep anything.",
},
{
topic: "Shipping",
q: "How long does delivery take?",
a: "Two to four working days within the EU and five to eight days elsewhere. You get a tracking link as soon as the parcel leaves our warehouse.",
},
{
topic: "Shipping",
q: "Do you ship to PO boxes?",
a: "We ship to PO boxes in most countries, but express delivery is not available for them.",
},
{
topic: "Returns",
q: "What is your return policy?",
a: "Return anything unused within 30 days for a full refund. Start a return from your order page and print the prepaid label.",
},
{
topic: "Returns",
q: "When will I get my refund?",
a: "Within five working days after the return arrives at our warehouse. Your bank may take a few more days to show it.",
},
];
/** Highlight every occurrence of any search word. */
function mark(text: string, words: string[]): ReactNode {
if (!words.length) return text;
const re = new RegExp(
`(${words.map((w) => w.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|")})`,
"gi",
);
return text
.split(re)
.map((part, i) => (i % 2 ? <mark key={i}>{part}</mark> : part));
}
/**
* HelpFaq
* - Every word in the search must appear in the question or answer.
* - Answers use the grid-template-rows 0fr → 1fr trick to animate to their natural height.
*/
export function HelpFaq({ theme = "light" }: { theme?: "light" | "dark" }) {
const id = useId();
const [query, setQuery] = useState("");
const [topic, setTopic] = useState("All");
const [open, setOpen] = useState<string | null>(ITEMS[0].q);
const [voted, setVoted] = useState<Record<string, "yes" | "no">>({});
const words = query.toLowerCase().split(/\s+/).filter(Boolean);
const shown = ITEMS.filter(
(it) =>
(topic === "All" || it.topic === topic) &&
words.every((w) => `${it.q} ${it.a}`.toLowerCase().includes(w)),
);
return (
<section className="gu-help" data-theme={theme}>
<header>
<h2>How can we help?</h2>
<div className="gu-help__search">
<svg viewBox="0 0 24 24" aria-hidden="true">
<circle cx="11" cy="11" r="6.5" />
<path d="m16 16 4.5 4.5" />
</svg>
<label htmlFor={id} className="gu-sr">
Search questions
</label>
<input
id={id}
type="search"
placeholder="Search “refund”, “invoice”, “delivery”…"
value={query}
onChange={(e) => setQuery(e.target.value)}
/>
</div>
<div className="gu-help__topics" role="group" aria-label="Topics">
{TOPICS.map((t) => (
<button
key={t}
type="button"
aria-pressed={topic === t}
onClick={() => setTopic(t)}
>
{t}
<span>
{t === "All"
? ITEMS.length
: ITEMS.filter((i) => i.topic === t).length}
</span>
</button>
))}
</div>
</header>
<p className="gu-help__count" role="status">
{shown.length
? `${shown.length} ${shown.length === 1 ? "answer" : "answers"}`
: ""}
</p>
{shown.length ? (
<ul className="gu-help__list">
{shown.map((it) => {
const isOpen = open === it.q || words.length > 0;
const pid = `${id}-${ITEMS.indexOf(it)}`;
return (
<li key={it.q} data-open={isOpen ? "" : undefined}>
<h3>
<button
type="button"
aria-expanded={isOpen}
aria-controls={pid}
onClick={() => setOpen(open === it.q ? null : it.q)}
>
<span className="gu-help__topic">{it.topic}</span>
<span className="gu-help__q">{mark(it.q, words)}</span>
<span className="gu-help__plus" aria-hidden="true" />
</button>
</h3>
<div
className="gu-help__panel"
id={pid}
role="region"
aria-label={it.q}
>
<div>
<p>{mark(it.a, words)}</p>
<div className="gu-help__vote">
{voted[it.q] ? (
<span>
{voted[it.q] === "yes"
? "Glad it helped."
: "Thanks. We'll make this answer clearer."}
</span>
) : (
<>
<span>Was this helpful?</span>
<button
type="button"
onClick={() =>
setVoted((v) => ({ ...v, [it.q]: "yes" }))
}
>
Yes
</button>
<button
type="button"
onClick={() =>
setVoted((v) => ({ ...v, [it.q]: "no" }))
}
>
No
</button>
</>
)}
</div>
</div>
</div>
</li>
);
})}
</ul>
) : (
<div className="gu-help__empty">
<p>
<b>No answers for “{query}”.</b> Try fewer words, or ask us
directly.
</p>
<a href="#contact">Contact support</a>
</div>
)}
</section>
);
}
Paste this into ChatGPT, Claude, Cursor, v0, Lovable or Bolt. It describes the layout, motion, colors and accessibility and includes the code, so the AI can rebuild it in any framework.
# Build this UI piece: Help center FAQ
You are a senior front-end engineer. Recreate the piece below in my project. If I don't say which framework I use, ask once, then build it in that framework (React, Vue, Svelte, Angular, Astro, plain HTML/CSS/JS or anything else). Keep the behavior, motion, colors, spacing and accessibility exactly as described. Keep the code clean and commented for beginners.
## What it is
A help-center FAQ section: giant "How can we help?" title, a big search field, topic chips with counts, and an accordion of answers. Typing filters live, opens all matches and highlights matched words in lime. Each answer ends with "Was this helpful? Yes / No".
## Layout and look
- Cream section (dark Ink), content max 760px. Title clamp 38–80px, weight 900, tracking -0.05em.
- Search: 64px tall, radius 20px, search icon inside.
- Topic chips: 42px pills with a small count bubble; the active chip is Ink with an orange count.
- Items: cards with radius 20px; question row 64px with a tiny topic tag, bold question and a 28px round plus icon that becomes an orange minus (rotates 180°).
- Answer text muted, line height 1.6. Highlights: lime #d7ff3a background with dark text.
- Empty state: dashed box, "No answers for '…'" and an orange "Contact support" button.
## Behavior and motion
1. Filter = topic match AND every typed word appears in question or answer.
2. With a search, all matching items are open. Otherwise one open at a time.
3. Answers animate with grid-template-rows 0fr → 1fr (450ms cubic-bezier(0.16, 1, 0.3, 1)). Items fade up 6px when they appear.
4. Voting replaces the buttons with a thank-you line.
## Touch
Chips scroll sideways; tall rows.
## Accessibility
- Buttons inside h3 with aria-expanded/aria-controls; panels are labelled regions. Chips use aria-pressed. Result count in a status region.
- prefers-reduced-motion: no height or item animation.
## Props
theme. Edit TOPICS and ITEMS.
## Reference implementation
The original is written in React with one plain CSS file. Dependencies: none (plain React and CSS). Translate it faithfully; do not add new libraries unless my framework needs them.
### HelpFaq.tsx
```tsx
"use client";
import { useId, useState, type ReactNode } from "react";
import "./help-faq.css";
type Item = { q: string; a: string; topic: string };
const TOPICS = ["All", "Billing", "Account", "Shipping", "Returns"];
const ITEMS: Item[] = [
{
topic: "Billing",
q: "When will I be charged?",
a: "On the day your trial ends, and then on the same date each month. You get an email reminder three days before the first charge.",
},
{
topic: "Billing",
q: "Can I get an invoice with my company details?",
a: "Yes. Add your company name, address and tax number under Settings → Billing, and every new invoice will include them. Older invoices can be regenerated from the same page.",
},
{
topic: "Account",
q: "How do I change my email address?",
a: "Go to Settings → Profile and edit the email field. We send a confirmation link to the new address; the change applies once you click it.",
},
{
topic: "Account",
q: "Can I delete my account?",
a: "Yes, from Settings → Privacy. Your data is removed within 30 days. Download an export first if you want to keep anything.",
},
{
topic: "Shipping",
q: "How long does delivery take?",
a: "Two to four working days within the EU and five to eight days elsewhere. You get a tracking link as soon as the parcel leaves our warehouse.",
},
{
topic: "Shipping",
q: "Do you ship to PO boxes?",
a: "We ship to PO boxes in most countries, but express delivery is not available for them.",
},
{
topic: "Returns",
q: "What is your return policy?",
a: "Return anything unused within 30 days for a full refund. Start a return from your order page and print the prepaid label.",
},
{
topic: "Returns",
q: "When will I get my refund?",
a: "Within five working days after the return arrives at our warehouse. Your bank may take a few more days to show it.",
},
];
/** Highlight every occurrence of any search word. */
function mark(text: string, words: string[]): ReactNode {
if (!words.length) return text;
const re = new RegExp(
`(${words.map((w) => w.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|")})`,
"gi",
);
return text
.split(re)
.map((part, i) => (i % 2 ? <mark key={i}>{part}</mark> : part));
}
/**
* HelpFaq
* - Every word in the search must appear in the question or answer.
* - Answers use the grid-template-rows 0fr → 1fr trick to animate to their natural height.
*/
export function HelpFaq({ theme = "light" }: { theme?: "light" | "dark" }) {
const id = useId();
const [query, setQuery] = useState("");
const [topic, setTopic] = useState("All");
const [open, setOpen] = useState<string | null>(ITEMS[0].q);
const [voted, setVoted] = useState<Record<string, "yes" | "no">>({});
const words = query.toLowerCase().split(/\s+/).filter(Boolean);
const shown = ITEMS.filter(
(it) =>
(topic === "All" || it.topic === topic) &&
words.every((w) => `${it.q} ${it.a}`.toLowerCase().includes(w)),
);
return (
<section className="gu-help" data-theme={theme}>
<header>
<h2>How can we help?</h2>
<div className="gu-help__search">
<svg viewBox="0 0 24 24" aria-hidden="true">
<circle cx="11" cy="11" r="6.5" />
<path d="m16 16 4.5 4.5" />
</svg>
<label htmlFor={id} className="gu-sr">
Search questions
</label>
<input
id={id}
type="search"
placeholder="Search “refund”, “invoice”, “delivery”…"
value={query}
onChange={(e) => setQuery(e.target.value)}
/>
</div>
<div className="gu-help__topics" role="group" aria-label="Topics">
{TOPICS.map((t) => (
<button
key={t}
type="button"
aria-pressed={topic === t}
onClick={() => setTopic(t)}
>
{t}
<span>
{t === "All"
? ITEMS.length
: ITEMS.filter((i) => i.topic === t).length}
</span>
</button>
))}
</div>
</header>
<p className="gu-help__count" role="status">
{shown.length
? `${shown.length} ${shown.length === 1 ? "answer" : "answers"}`
: ""}
</p>
{shown.length ? (
<ul className="gu-help__list">
{shown.map((it) => {
const isOpen = open === it.q || words.length > 0;
const pid = `${id}-${ITEMS.indexOf(it)}`;
return (
<li key={it.q} data-open={isOpen ? "" : undefined}>
<h3>
<button
type="button"
aria-expanded={isOpen}
aria-controls={pid}
onClick={() => setOpen(open === it.q ? null : it.q)}
>
<span className="gu-help__topic">{it.topic}</span>
<span className="gu-help__q">{mark(it.q, words)}</span>
<span className="gu-help__plus" aria-hidden="true" />
</button>
</h3>
<div
className="gu-help__panel"
id={pid}
role="region"
aria-label={it.q}
>
<div>
<p>{mark(it.a, words)}</p>
<div className="gu-help__vote">
{voted[it.q] ? (
<span>
{voted[it.q] === "yes"
? "Glad it helped."
: "Thanks. We'll make this answer clearer."}
</span>
) : (
<>
<span>Was this helpful?</span>
<button
type="button"
onClick={() =>
setVoted((v) => ({ ...v, [it.q]: "yes" }))
}
>
Yes
</button>
<button
type="button"
onClick={() =>
setVoted((v) => ({ ...v, [it.q]: "no" }))
}
>
No
</button>
</>
)}
</div>
</div>
</div>
</li>
);
})}
</ul>
) : (
<div className="gu-help__empty">
<p>
<b>No answers for “{query}”.</b> Try fewer words, or ask us
directly.
</p>
<a href="#contact">Contact support</a>
</div>
)}
</section>
);
}
```
### help-faq.css
```css
/* HelpFaq: change these colors to match your brand. */
.gu-help {
--bg: #f3eee3;
--card: #fbf8f2;
--text: #0e0e10;
--muted: #57534b;
--line: rgb(14 14 16 / 0.12);
--accent: #ff5a1f;
--mark: #d7ff3a;
--focus: #2b35ff;
--ease: cubic-bezier(0.16, 1, 0.3, 1);
container-type: inline-size;
padding: clamp(40px, 7%, 88px) clamp(16px, 4%, 48px);
background: var(--bg);
color: var(--text);
font-family: system-ui, sans-serif;
}
.gu-help[data-theme="dark"] {
--bg: #0e0e10;
--card: #18181b;
--text: #f3eee3;
--muted: #aea89c;
--line: rgb(243 238 227 / 0.12);
--focus: #d7ff3a;
}
.gu-help > * {
max-width: 760px;
margin-inline: auto;
}
.gu-help header {
display: grid;
gap: 18px;
}
.gu-help h2 {
margin: 0;
font-size: clamp(2.4rem, 8cqi, 5rem);
font-weight: 900;
letter-spacing: -0.05em;
line-height: 0.92;
}
.gu-help__search {
position: relative;
}
.gu-help__search svg {
position: absolute;
top: 50%;
left: 20px;
width: 22px;
translate: 0 -50%;
fill: none;
stroke: var(--muted);
stroke-width: 2;
stroke-linecap: round;
}
.gu-help__search input {
width: 100%;
height: 64px;
padding: 0 20px 0 54px;
border: 1.5px solid var(--line);
border-radius: 20px;
outline: none;
background: var(--card);
color: inherit;
font: inherit;
font-size: 1.05rem;
}
.gu-help__search input:focus {
border-color: var(--focus);
box-shadow: 0 0 0 4px color-mix(in srgb, var(--focus) 18%, transparent);
}
.gu-help__topics {
display: flex;
gap: 8px;
overflow-x: auto;
scrollbar-width: none;
}
.gu-help__topics button {
display: inline-flex;
flex: none;
align-items: center;
gap: 8px;
min-height: 42px;
padding: 0 8px 0 16px;
border: 1.5px solid var(--line);
border-radius: 999px;
background: none;
color: inherit;
font: inherit;
font-weight: 700;
cursor: pointer;
}
.gu-help__topics button span {
display: grid;
place-items: center;
min-width: 26px;
height: 26px;
border-radius: 999px;
background: var(--line);
font-size: 0.75rem;
}
.gu-help__topics [aria-pressed="true"] {
border-color: var(--text);
background: var(--text);
color: var(--bg);
}
.gu-help__topics [aria-pressed="true"] span {
background: var(--accent);
color: #0e0e10;
}
.gu-help button:focus-visible,
.gu-help a:focus-visible {
outline: 3px solid var(--focus);
outline-offset: 2px;
}
.gu-help__count {
min-height: 1.2em;
margin-block: 24px 8px;
color: var(--muted);
font-size: 0.85rem;
font-weight: 700;
}
.gu-help__list {
display: grid;
gap: 8px;
padding: 0;
list-style: none;
}
.gu-help__list li {
border: 1px solid var(--line);
border-radius: 20px;
background: var(--card);
animation: gu-help-in 0.35s var(--ease);
transition: border-color 0.25s;
}
@keyframes gu-help-in {
from {
opacity: 0;
transform: translateY(6px);
}
}
.gu-help__list li[data-open] {
border-color: color-mix(in srgb, var(--text) 30%, transparent);
}
.gu-help h3 {
margin: 0;
}
.gu-help h3 button {
display: grid;
grid-template-columns: auto 1fr 28px;
align-items: center;
gap: 14px;
width: 100%;
min-height: 64px;
padding: 14px 18px;
border: 0;
border-radius: 20px;
background: none;
color: inherit;
font: inherit;
font-size: 1.05rem;
font-weight: 800;
text-align: left;
cursor: pointer;
}
.gu-help__topic {
padding: 3px 9px;
border-radius: 999px;
background: var(--line);
color: var(--muted);
font-size: 0.72rem;
}
.gu-help__plus {
position: relative;
width: 28px;
height: 28px;
border-radius: 50%;
background: var(--line);
transition:
background-color 0.3s,
transform 0.4s var(--ease);
}
.gu-help__plus::before,
.gu-help__plus::after {
content: "";
position: absolute;
top: 13px;
left: 8px;
width: 12px;
height: 2px;
border-radius: 2px;
background: currentColor;
}
.gu-help__plus::after {
rotate: 90deg;
transition: rotate 0.4s var(--ease);
}
[data-open] .gu-help__plus {
background: var(--accent);
color: #0e0e10;
transform: rotate(180deg);
}
[data-open] .gu-help__plus::after {
rotate: 0deg;
}
.gu-help__panel {
display: grid;
grid-template-rows: 0fr;
transition: grid-template-rows 0.45s var(--ease);
}
[data-open] .gu-help__panel {
grid-template-rows: 1fr;
}
.gu-help__panel > div {
overflow: hidden;
}
.gu-help__panel p {
margin: 0;
padding: 0 18px;
color: var(--muted);
line-height: 1.6;
}
.gu-help mark {
border-radius: 4px;
background: var(--mark);
color: #0e0e10;
}
.gu-help__vote {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
padding: 14px 18px 18px;
color: var(--muted);
font-size: 0.85rem;
font-weight: 600;
}
.gu-help__vote button {
min-height: 36px;
padding: 0 14px;
border: 1px solid var(--line);
border-radius: 999px;
background: none;
color: inherit;
font: inherit;
cursor: pointer;
}
.gu-help__vote button:hover {
border-color: var(--text);
color: var(--text);
}
.gu-help__empty {
display: grid;
justify-items: start;
gap: 14px;
padding: 28px;
border: 1.5px dashed var(--line);
border-radius: 20px;
}
.gu-help__empty p {
margin: 0;
color: var(--muted);
}
.gu-help__empty b {
color: var(--text);
}
.gu-help__empty a {
display: inline-grid;
place-items: center;
min-height: 46px;
padding: 0 20px;
border-radius: 999px;
background: var(--accent);
color: #0e0e10;
font-weight: 800;
text-decoration: none;
}
.gu-sr {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip-path: inset(50%);
}
@container (max-width: 520px) {
.gu-help h3 button {
grid-template-columns: 1fr 28px;
}
.gu-help__topic {
grid-column: 1;
justify-self: start;
}
.gu-help__q {
grid-column: 1;
}
.gu-help__plus {
grid-column: 2;
grid-row: 1 / span 2;
}
}
@media (prefers-reduced-motion: reduce) {
.gu-help__panel,
.gu-help__plus,
.gu-help__plus::after {
transition: none;
}
.gu-help__list li {
animation: none;
}
}
```
You might also want
Next piece: Hold to confirmFAQ accordion
Templates, beginner
404 page section
Templates, intermediate
Big footer with signup
Templates, intermediate