FAQ accordion
The FAQ from joinstarlight.com: dark question cards that lift on hover while a beam of blue light circles their edge, and slide their answer open on click.
Build a React 19 + TypeScript component called FaqAccordion: a dark FAQ section whose question cards lift on hover while a beam of blue light travels around their 1px edge, and open one answer at a time.
Constraints
- One .tsx file, "use client", imports from react only, default export, no required props. Optional props: items ({ question, answer }[], default five general questions that fit most products: how it works, what it costs, cancelling, data security, getting help), title ("Frequently asked questions"), subtitle ("Questions, answered"). All CSS in a template string rendered as <style href="ui-faq-accordion" precedence="ui">, every class prefixed "fq-".
- The root fills its parent (width/height 100%, isolation isolate, background #0a0a0f), scrolls vertically inside itself with the scrollbar hidden, and is a flex column whose section has margin auto, so it centres when there's room. It is an inline-size container named fq; the one breakpoint (640px) is a container query, never the window. Font: var(--font-google-sans-flex, "Google Sans Flex"), system-ui, sans-serif, antialiased, line-height 1.5.
- Colours: ink #F0F0F5, muted #8A8AA3, card face #14141F. Text selection is white with black glyphs on ink text, #3B82F6 with white glyphs on muted text.
Layout
- Section: max-width 768px, padding clamp(40px, 8cqi, 64px) 24px.
- Header, centred, 48px above the list: h2 30px, line-height 1.2, weight 700, ink (40px from 640px). Subtitle 16px below, max-width 672px, font-size clamp(0.875rem, 3cqi, 1.0625rem), muted (20px/28px from 640px).
- List: a column of cards 12px apart.
- Card: position relative, overflow hidden, radius 12px, padding 1px, background white at 8%. The 1px padding is the border: its tint shows through. Inside, a face with radius 11px and background #14141F.
- Question: a full-width <button> (cursor default, no native styles), flex, space-between, centred, padding 20px 24px, left-aligned. Text 16px/24px weight 500 ink (18px/28px from 640px). On the right, 16px from the text and never shrinking, Heroicons' 24px solid chevron-down drawn at 20px in muted.
- Answer: padding 0 24px 20px, 16px, line-height 1.625, muted.
Behaviour
- One open at a time; clicking the open one closes it. The button has aria-expanded and aria-controls pointing at its panel (ids from useId).
- Answers stay mounted. The panel is a grid going from grid-template-rows 0fr and opacity 0 to 1fr and 1, with its child min-height 0 and overflow hidden, over 200ms cubic-bezier(0, 0, 0.58, 1). The answer is inert while closed. The chevron rotates 180deg on the same timing.
- The edge light: an aria-hidden span absolutely centred in the card (left/top 50%, translate -50% -50%), 150% of the card's width, square, background conic-gradient(from 0deg, transparent 0deg, transparent 130deg, rgba(96,165,250,0.25) 200deg, #93c5fd 250deg, #e0f2fe 264deg, #60a5fa 278deg, rgba(96,165,250,0) 330deg, transparent 360deg), spinning 360deg every 4s, linear, infinite. It sits under the face, so only the 1px rim shows it. Opacity 0, fading to 1 over 300ms cubic-bezier(0.4, 0, 0.2, 1) on hover and held at 1 while the card is open.
- The card scales to 1.02 on hover and while open, over 300ms cubic-bezier(0, 0, 0.2, 1). A closed card's tint rises to white at 15% on hover. Hover styles only under (hover: hover).
- Focus: when the button is focus-visible, a 2px #60A5FA outline 2px outside the card.
- Under prefers-reduced-motion: reduce, no scale and no spin; the light still fades in, standing still."use client";
/**
* FaqAccordion: the "Frequently asked questions" section from Starlight (joinstarlight.com).
*
* On the live site it sits near the end of the landing page and every comparison page: a centred heading
* and subtitle over a stack of dark cards, one question each. Here it ships with five general questions in
* place of Starlight's own, so it drops into any site. Hover a card and it grows 2% while a
* beam of blue light starts circling its 1px edge; click it and the answer slides open under the
* question, the chevron flips, and the card keeps the beam and the lift for as long as it stays open.
* Only one answer is open at a time.
*
* How it works
* - Each card is a 1px-padded wrapper whose own tint (white at 8%, 15% on hover) shows through that padding
* as the border. Behind the card's face sits a square 150% as wide as the card, filled with a conic
* gradient that's transparent for most of its turn and a bright blue-to-ice streak for the rest. It
* spins once every 4s; the face covers all but the 1px rim, so the streak reads as light travelling
* around the edge. It fades in over 300ms on hover and stays while the card is open.
* - The answer panel animates its height with the grid-rows trick (0fr → 1fr) and its opacity, both over
* 200ms ease-out, and the chevron turns 180° on the same curve. Answers stay mounted (and `inert` while
* shut), so they're in the server HTML for crawlers, as on the site.
* - The root is its own scroll area and an inline-size container: the 640px step up in type size is
* measured on the frame, not the window. If the frame is taller than the section, the section centres.
* - With reduced motion the cards don't grow and the edge light holds still instead of circling.
*
* Usage
* <FaqAccordion />
* <FaqAccordion items={[{ question: "…", answer: "…" }]} title="FAQ" subtitle="Questions, answered" />
* Give it a height to scroll inside, or none to stand at the section's own height.
*
* Requirements: React 19 (for the hoisted <style>), no other dependencies, a browser with container
* queries and :has(). Set in Google Sans Flex when the page provides `--font-google-sans-flex`, else the
* system sans.
*/
import { useId, useState } from "react";
export type FaqItem = { question: string; answer: string };
// ── Content: general questions that fit most products; swap ITEMS (or pass `items`) for your own ─────
const ITEMS: FaqItem[] = [
{
question: "How does it work?",
answer:
"Sign up, tell us what you need, and we take it from there. Most people are up and running in a few minutes, with no setup on their side.",
},
{
question: "How much does it cost?",
answer:
"One simple monthly price with everything included. No setup fees, no hidden costs, and no long-term contract.",
},
{
question: "Can I cancel anytime?",
answer: "Yes. Cancel from your account settings in one click, and you won't be charged again.",
},
{
question: "Is my data secure?",
answer:
"Your data is encrypted in transit and at rest, and we never sell or share it. You can export or delete it whenever you like.",
},
{
question: "How do I get help?",
answer:
"Reach us by email or live chat. A real person replies, usually within a few hours on business days.",
},
];
const css = `
.fq-root {
--fq-ink: #f0f0f5;
--fq-muted: #8a8aa3;
--fq-face: #14141f;
--fq-sel-bg: #fff;
--fq-sel-fg: #000;
position: relative;
display: flex;
flex-direction: column;
width: 100%;
height: 100%;
overflow-x: hidden;
overflow-y: auto;
scrollbar-width: none;
isolation: isolate;
container: fq / inline-size;
background: #0a0a0f;
color: var(--fq-ink);
font-family: var(--font-google-sans-flex, "Google Sans Flex"), system-ui, sans-serif;
line-height: 1.5;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-rendering: optimizeLegibility;
}
.fq-root::-webkit-scrollbar { display: none; }
.fq-root *, .fq-root *::before, .fq-root *::after { box-sizing: border-box; }
/* The site's selection: white on white copy, blue on the grey copy. */
.fq-root ::selection { background: var(--fq-sel-bg); color: var(--fq-sel-fg); text-shadow: none; }
.fq-muted { --fq-sel-bg: #3b82f6; --fq-sel-fg: #fff; }
.fq-section {
width: 100%;
max-width: 768px;
margin: auto;
padding: clamp(40px, 8cqi, 64px) 24px;
}
.fq-head { margin-bottom: 48px; text-align: center; }
.fq-title { margin: 0; font-size: 30px; line-height: 1.2; font-weight: 700; color: var(--fq-ink); }
.fq-sub {
max-width: 672px;
margin: 16px auto 0;
font-size: clamp(0.875rem, 3cqi, 1.0625rem);
color: var(--fq-muted);
}
.fq-list { display: flex; flex-direction: column; gap: 12px; }
/* The 1px padding is the border: the card's own tint shows through it at rest. */
.fq-item {
position: relative;
overflow: hidden;
padding: 1px;
border-radius: 12px;
background: rgb(255 255 255 / 0.08);
transition: scale 300ms cubic-bezier(0, 0, 0.2, 1);
}
.fq-item:has(.fq-q:focus-visible) { outline: 2px solid #60a5fa; outline-offset: 2px; }
/* Light travelling around the edge. */
.fq-ring {
position: absolute;
left: 50%;
top: 50%;
width: 150%;
aspect-ratio: 1;
translate: -50% -50%;
opacity: 0;
pointer-events: none;
background: conic-gradient(from 0deg, transparent 0deg, transparent 130deg, rgba(96, 165, 250, 0.25) 200deg, #93c5fd 250deg, #e0f2fe 264deg, #60a5fa 278deg, rgba(96, 165, 250, 0) 330deg, transparent 360deg);
transition: opacity 300ms cubic-bezier(0.4, 0, 0.2, 1);
}
.fq-item[data-open] .fq-ring { opacity: 1; }
@media (hover: hover) {
.fq-item:not([data-open]):hover { background: rgb(255 255 255 / 0.15); }
.fq-item:hover .fq-ring { opacity: 1; }
}
@media (prefers-reduced-motion: no-preference) {
.fq-item { will-change: scale; }
.fq-item[data-open] { scale: 1.02; }
.fq-ring { will-change: transform; animation: fq-spin 4s linear infinite; }
}
@media (prefers-reduced-motion: no-preference) and (hover: hover) {
.fq-item:hover { scale: 1.02; }
}
@keyframes fq-spin { to { transform: rotate(360deg); } }
.fq-face { position: relative; border-radius: 11px; background: var(--fq-face); }
.fq-q {
display: flex;
width: 100%;
align-items: center;
justify-content: space-between;
margin: 0;
padding: 20px 24px;
border: 0;
background: none;
color: inherit;
font: inherit;
text-align: left;
cursor: default;
-webkit-tap-highlight-color: transparent;
}
.fq-q:focus-visible { outline: none; }
.fq-q-text { font-size: 16px; line-height: 24px; font-weight: 500; color: var(--fq-ink); }
.fq-chev {
flex-shrink: 0;
margin-left: 16px;
transition: rotate 200ms cubic-bezier(0, 0, 0.58, 1);
}
.fq-item[data-open] .fq-chev { rotate: 180deg; }
.fq-chev svg { display: block; width: 20px; height: 20px; color: var(--fq-muted); }
/* Height 0 → its content's, then back: the grid-rows trick, on the same 200ms ease-out as the chevron. */
.fq-panel {
display: grid;
grid-template-rows: 0fr;
opacity: 0;
transition: grid-template-rows 200ms cubic-bezier(0, 0, 0.58, 1), opacity 200ms cubic-bezier(0, 0, 0.58, 1);
}
.fq-item[data-open] .fq-panel { grid-template-rows: 1fr; opacity: 1; }
.fq-clip { min-height: 0; overflow: hidden; }
.fq-a { padding: 0 24px 20px; font-size: 16px; line-height: 1.625; color: var(--fq-muted); }
@container fq (min-width: 640px) {
.fq-title { font-size: 40px; }
.fq-sub { font-size: 20px; line-height: 28px; }
.fq-q-text { font-size: 18px; line-height: 28px; }
}
`;
/** Heroicons' 24px solid chevron-down, the icon on the site. */
function Chevron() {
return (
<svg viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
<path
fillRule="evenodd"
d="M12.53 16.28a.75.75 0 0 1-1.06 0l-7.5-7.5a.75.75 0 0 1 1.06-1.06L12 14.69l6.97-6.97a.75.75 0 1 1 1.06 1.06l-7.5 7.5Z"
clipRule="evenodd"
/>
</svg>
);
}
export default function FaqAccordion({
items = ITEMS,
title = "Frequently asked questions",
subtitle = "Questions, answered",
}: {
items?: FaqItem[];
title?: string;
subtitle?: string;
}) {
const [openIndex, setOpenIndex] = useState<number | null>(null);
const id = useId();
return (
<div className="fq-root">
<style href="ui-faq-accordion" precedence="ui">
{css}
</style>
<section className="fq-section" aria-labelledby={`${id}-title`}>
<div className="fq-head">
<h2 id={`${id}-title`} className="fq-title">
{title}
</h2>
{subtitle && <p className="fq-sub fq-muted">{subtitle}</p>}
</div>
<div className="fq-list">
{items.map((item, index) => {
const isOpen = openIndex === index;
const panelId = `${id}-answer-${index}`;
return (
<div key={item.question} className="fq-item" data-open={isOpen || undefined}>
<span className="fq-ring" aria-hidden="true" />
<div className="fq-face">
<button
type="button"
className="fq-q"
onClick={() => setOpenIndex(isOpen ? null : index)}
aria-expanded={isOpen}
aria-controls={panelId}
>
<span className="fq-q-text">{item.question}</span>
<span className="fq-chev">
<Chevron />
</span>
</button>
<div id={panelId} className="fq-panel">
<div className="fq-clip">
<div className="fq-a fq-muted" inert={!isOpen}>
{item.answer}
</div>
</div>
</div>
</div>
</div>
);
})}
</div>
</section>
</div>
);
}
