FAQ accordion
Questions that open with a smooth height animation and a plus that turns into a cross. Built on native details elements.
import "./faq-accordion.css";
export type FaqItem = { q: string; a: string };
type FaqAccordionProps = {
items: FaqItem[];
title?: string;
theme?: "light" | "dark";
};
/**
* FaqAccordion
* Uses native <details>/<summary>: keyboard, screen readers and "find in page"
* all work with zero JavaScript. The smooth height uses `interpolate-size`
* (modern browsers); older browsers simply open instantly.
* All items share a name, so opening one closes the others.
*/
export function FaqAccordion({
items,
title = "Questions, answered",
theme = "light",
}: FaqAccordionProps) {
return (
<section className="gu-faq" data-theme={theme}>
<h2 className="gu-faq__title">{title}</h2>
<div className="gu-faq__list">
{items.map((item, i) => (
<details
key={item.q}
className="gu-faq__item"
name="gu-faq"
open={i === 0}
>
<summary className="gu-faq__q">
<span>{item.q}</span>
<span className="gu-faq__icon" aria-hidden="true" />
</summary>
<div className="gu-faq__a">
<p>{item.a}</p>
</div>
</details>
))}
</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: FAQ accordion
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
An FAQ accordion built on native <details>/<summary>. Each question row opens its answer with a smooth height animation, while a round plus icon rotates into a cross and turns orange. Opening one question closes the others.
## Layout and look
- Width up to 720px. Text #0e0e10 (dark #f3eee3), muted answers #57534b (dark #aea89c), divider lines rgba(14,14,16,0.16) (dark rgba(243,238,227,0.14)), accent #ff5a1f.
- Title: weight 900, clamp(1.8rem, 5vw, 3rem), letter-spacing -0.04em.
- Rows: hairline top border (plus a bottom border on the last row), summary min-height 64px, 18px bold question, space-between with the icon.
- Icon: 32px circle in the line color with a 2px plus drawn by two pseudo-elements.
- Answer: muted, line-height 1.6, padding 0 48px 24px 0.
## Behavior and motion
- All <details> share the same name attribute (exclusive accordion). The first one starts open.
- Height: set interpolate-size: allow-keywords on the wrapper and transition the ::details-content height from 0 to auto (450ms, cubic-bezier(0.16,1,0.3,1)) with content-visibility allow-discrete. Browsers without support open instantly.
- Open state: icon rotates 135deg with an overshoot (cubic-bezier(0.34,1.4,0.5,1)) and gets an orange background with ink lines.
- Question text turns orange on hover.
- Remove the default marker (list-style none, ::-webkit-details-marker hidden).
## Accessibility
- Native details/summary give keyboard (Enter/Space) and screen reader support. Focus ring: 2px orange outline, 4px offset.
- prefers-reduced-motion: no height or icon transitions; open icon simply rotates 45deg.
## 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.
### FaqAccordion.tsx
```tsx
import "./faq-accordion.css";
export type FaqItem = { q: string; a: string };
type FaqAccordionProps = {
items: FaqItem[];
title?: string;
theme?: "light" | "dark";
};
/**
* FaqAccordion
* Uses native <details>/<summary>: keyboard, screen readers and "find in page"
* all work with zero JavaScript. The smooth height uses `interpolate-size`
* (modern browsers); older browsers simply open instantly.
* All items share a name, so opening one closes the others.
*/
export function FaqAccordion({
items,
title = "Questions, answered",
theme = "light",
}: FaqAccordionProps) {
return (
<section className="gu-faq" data-theme={theme}>
<h2 className="gu-faq__title">{title}</h2>
<div className="gu-faq__list">
{items.map((item, i) => (
<details
key={item.q}
className="gu-faq__item"
name="gu-faq"
open={i === 0}
>
<summary className="gu-faq__q">
<span>{item.q}</span>
<span className="gu-faq__icon" aria-hidden="true" />
</summary>
<div className="gu-faq__a">
<p>{item.a}</p>
</div>
</details>
))}
</div>
</section>
);
}
```
### faq-accordion.css
```css
.gu-faq {
--text: #0e0e10;
--muted: #57534b;
--line: rgb(14 14 16 / 0.16);
--accent: #ff5a1f;
width: min(100%, 720px);
color: var(--text);
font-family: system-ui, sans-serif;
/* Lets `height: auto` animate (Chrome 129+, others fall back gracefully) */
interpolate-size: allow-keywords;
}
.gu-faq[data-theme="dark"] {
--text: #f3eee3;
--muted: #aea89c;
--line: rgb(243 238 227 / 0.14);
}
.gu-faq__title {
margin: 0 0 24px;
font-size: clamp(1.8rem, 5vw, 3rem);
font-weight: 900;
letter-spacing: -0.04em;
line-height: 1;
}
.gu-faq__item {
border-top: 1px solid var(--line);
}
.gu-faq__item:last-child {
border-bottom: 1px solid var(--line);
}
.gu-faq__q {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
min-height: 64px;
padding: 12px 0;
font-size: 1.1rem;
font-weight: 700;
letter-spacing: -0.01em;
list-style: none;
cursor: pointer;
transition: color 0.2s;
}
.gu-faq__q::-webkit-details-marker {
display: none;
}
.gu-faq__q:hover {
color: var(--accent);
}
.gu-faq__q:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 4px;
border-radius: 6px;
}
/* Plus that rotates into a cross */
.gu-faq__icon {
position: relative;
flex: none;
width: 32px;
height: 32px;
border-radius: 50%;
background: var(--line);
transition:
transform 0.45s cubic-bezier(0.34, 1.4, 0.5, 1),
background-color 0.3s;
}
.gu-faq__icon::before,
.gu-faq__icon::after {
content: "";
position: absolute;
inset: 50% 9px auto;
height: 2px;
margin-top: -1px;
border-radius: 2px;
background: currentColor;
}
.gu-faq__icon::after {
transform: rotate(90deg);
}
.gu-faq__item[open] .gu-faq__icon {
transform: rotate(135deg);
background: var(--accent);
color: #0e0e10;
}
/* Smooth height: animate the ::details-content box */
.gu-faq__item::details-content {
height: 0;
overflow: clip;
transition:
height 0.45s cubic-bezier(0.16, 1, 0.3, 1),
content-visibility 0.45s allow-discrete;
}
.gu-faq__item[open]::details-content {
height: auto;
}
.gu-faq__a p {
margin: 0;
padding: 0 48px 24px 0;
color: var(--muted);
line-height: 1.6;
}
@media (prefers-reduced-motion: reduce) {
.gu-faq__item::details-content,
.gu-faq__icon {
transition: none;
}
.gu-faq__item[open] .gu-faq__icon {
transform: rotate(45deg);
}
}
```
You might also want
Next piece: App launch pageHelp center FAQ
Templates, intermediate
Big footer with signup
Templates, intermediate
Changelog timeline
Templates, intermediate