Split FAQ
A compact list of questions, each with a small icon, outlined as one card. Open a question and its row lifts out into a card of its own: the rows above it close into one card, the rows below into another, and the answer fades in under the question. One answer is open at a time, so opening another moves the split to it. Close it and the three cards join back into one. Use Full screen to see it at page width.
One card that splits
The rows are not wrapped in card elements. Each row draws its own outline, and two props decide its shape: whether it starts a card and whether it ends one.
- A row that starts a card rounds its top corners, draws a top edge, and gets 8px of space above it. A row that ends a card rounds its bottom corners and draws a bottom edge.
- The open row both starts and ends a card. The row before it ends one, and the row after it starts one. Every other row is a plain middle row.
- Margin, radius, outline, and fill all move on one 300ms
ease-snappytransition, so the gaps open at the same pace as the answer.
Because nothing is reparented, the open row keeps its state the whole time, and its answer can play a normal exit when it closes.
A seamless outline
A border on each row would leave a line between rows that share a card. The
outline is four inset shadows instead. The two side shadows always draw, so
neighbouring rows line up into one unbroken edge. The top and bottom shadows
switch between var(--border) and transparent. The list always holds four
shadows, so the browser can fade an edge in rather than snap it on.
The open row takes a light bg-muted fill so it reads as the active card, and
other rows tint on hover.
The chevron turns one arm at a time
The chevron is two arms, each in its own 16px svg, both turning 180° about the
icon's centre. The right arm leads and the left one follows 60ms later on a
500ms spring with a little bounce. On the way up the chevron bends through an
L and a sideways < instead of spinning as one piece. Its stroke darkens from
muted to foreground while the answer is open.
Opening an answer
- The panel grows from zero height on a 350ms spring with no bounce.
- The answer trails it by 50ms. It fades in, drops 4px into place, and sharpens from a 4px blur over 300ms.
- Closing is faster. The text fades in 150ms while the panel shrinks.
Accessibility
- Each question is a real
buttoninside anh3, witharia-expandedandaria-controls. Its answer is a region labelled by the question. - The block has no visible heading, so the section takes an
aria-label(labelprop). Icons are hidden from screen readers. - Rows are at least 44px tall.
Esccloses the focused question. - With reduced motion the panel and chevron change at once and the gaps appear without a transition. The answer still fades.
Usage
import { PlantIcon, SparkleIcon } from "@phosphor-icons/react";
<SplitFaq
defaultOpen={null}
items={[
{
icon: SparkleIcon,
question: "Why motion matters?",
answer: "Principles and shared patterns that shape how people interact with digital experiences.",
},
{
icon: PlantIcon,
question: "Why we create?",
answer: "A collection of methods and ideas that bring clarity and emotion to complex interfaces.",
},
]}
/>
"use client";
import {
ChartBarIcon,
CursorClickIcon,
type Icon,
PlantIcon,
SparkleIcon,
WavesIcon,
} from "@phosphor-icons/react";
import { AnimatePresence, MotionConfig, motion, useReducedMotion } from "motion/react";
import { useId, useState } from "react";
import { cn } from "@/lib/utils";
export type SplitFaqItem = {
question: string;
answer: React.ReactNode;
/** A Phosphor icon shown before the question. */
icon?: Icon;
};
export type SplitFaqProps = {
items?: SplitFaqItem[];
/** Index of the question that starts open. */
defaultOpen?: number | null;
/** Names the section for screen readers, since the block has no visible heading. */
label?: string;
className?: string;
};
const DEFAULT_ITEMS: SplitFaqItem[] = [
{
icon: CursorClickIcon,
question: "What is interaction design?",
answer: "The craft of shaping how an interface answers you, through feedback, timing, and motion.",
},
{
icon: SparkleIcon,
question: "Why motion matters?",
answer: "Principles and shared patterns that shape how people interact with digital experiences.",
},
{
icon: PlantIcon,
question: "Why we create?",
answer: "A collection of methods and ideas that bring clarity and emotion to complex interfaces.",
},
{
icon: WavesIcon,
question: "What drives interaction?",
answer: "A balance between structure and creativity that guides every visual interaction.",
},
{
icon: ChartBarIcon,
question: "How ideas grow?",
answer: "Repeated approaches that turn abstract ideas into functional and meaningful experiences.",
},
];
const spring = { type: "spring", duration: 0.35, bounce: 0 } as const;
const settle = { type: "spring", duration: 0.5, bounce: 0.2 } as const;
// Each arm of the chevron is its own svg so it can turn about the icon's
// centre. The right arm leads and the left one follows a beat later, so the
// chevron bends through an L and a < on its way up instead of spinning whole.
const ARMS = ["M3 5.5L8 10.5", "M8 10.5L13 5.5"] as const;
function Chevron({ open }: { open: boolean }) {
const reduceMotion = useReducedMotion();
return (
<span aria-hidden className="relative size-4 shrink-0">
{ARMS.map((d, i) => (
<motion.svg
key={d}
viewBox="0 0 16 16"
initial={false}
animate={{ rotate: open ? 180 : 0 }}
transition={
reduceMotion ? { duration: 0 } : { ...settle, delay: i === 1 ? 0 : 0.06 }
}
className="absolute inset-0 size-4 overflow-visible"
>
<path
d={d}
fill="none"
strokeWidth="1.5"
strokeLinecap="round"
className={cn(
"transition-[stroke] duration-200",
open ? "stroke-foreground" : "stroke-muted-foreground",
)}
/>
</motion.svg>
))}
</span>
);
}
function Item({
item,
open,
groupStart,
groupEnd,
onToggle,
}: {
item: SplitFaqItem;
open: boolean;
/** First row of its card: rounds the top corners and opens a gap above. */
groupStart: boolean;
/** Last row of its card: rounds the bottom corners. */
groupEnd: boolean;
onToggle: () => void;
}) {
const id = useId();
const reduceMotion = useReducedMotion();
const height = reduceMotion ? { duration: 0 } : spring;
const Icon = item.icon;
return (
<div
// The outline is four inset shadows. The sides always draw, so rows in
// one card join without a seam; the top and bottom only draw at the
// card's edges. Keeping all four in the list lets the edges fade.
style={{
boxShadow: [
"inset 1px 0 0 var(--border)",
"inset -1px 0 0 var(--border)",
`inset 0 1px 0 ${groupStart ? "var(--border)" : "transparent"}`,
`inset 0 -1px 0 ${groupEnd ? "var(--border)" : "transparent"}`,
].join(", "),
}}
className={cn(
"overflow-hidden bg-card transition-[margin,border-radius,box-shadow,background-color] duration-300 ease-snappy motion-reduce:transition-none",
"first:mt-0 has-[button:hover]:bg-muted/40",
groupStart ? "mt-2 rounded-t-2xl" : "mt-0",
groupEnd && "rounded-b-2xl",
open && "bg-muted/60 has-[button:hover]:bg-muted/60",
)}
>
<h3>
<button
type="button"
id={`${id}-trigger`}
aria-expanded={open}
aria-controls={`${id}-panel`}
onClick={onToggle}
onKeyDown={(e) => {
if (e.key === "Escape" && open) onToggle();
}}
className="flex min-h-11 w-full cursor-pointer items-center gap-3 rounded-[inherit] px-4 py-2.5 text-left text-sm/5 font-medium text-foreground outline-none focus-visible:ring-[1.5px] focus-visible:ring-ring/50 focus-visible:ring-inset"
>
{Icon && <Icon aria-hidden className="size-4 shrink-0 text-muted-foreground" />}
<span className="min-w-0 flex-1 text-pretty">{item.question}</span>
<Chevron open={open} />
</button>
</h3>
<AnimatePresence initial={false}>
{open && (
<motion.div
id={`${id}-panel`}
role="region"
aria-labelledby={`${id}-trigger`}
initial={{ height: 0 }}
animate={{ height: "auto", transition: height }}
exit={{ height: 0, transition: height }}
>
{/* The answer sharpens in just behind the panel, and leaves
quicker than it came so no text hangs over an empty gap. */}
<motion.p
initial={{ opacity: 0, y: -4, filter: "blur(4px)" }}
animate={{
opacity: 1,
y: 0,
filter: "blur(0px)",
transition: { duration: 0.3, delay: 0.05, ease: [0.23, 1, 0.32, 1] },
}}
exit={{ opacity: 0, filter: "blur(2px)", transition: { duration: 0.15 } }}
className="px-4 pb-4 text-sm/6 text-pretty text-muted-foreground"
>
{item.answer}
</motion.p>
</motion.div>
)}
</AnimatePresence>
</div>
);
}
export function SplitFaq({
items = DEFAULT_ITEMS,
defaultOpen = null,
label = "Frequently asked questions",
className,
}: SplitFaqProps) {
const [open, setOpen] = useState<number | null>(defaultOpen);
// With nothing open the rows form one card. Opening a row lifts it into a
// card of its own, splitting the rest into the cards above and below it.
const startsGroup = (i: number) => i === 0 || open === i || open === i - 1;
const endsGroup = (i: number) => i === items.length - 1 || open === i || open === i + 1;
return (
<section
aria-label={label}
className={cn("@container w-full px-5 py-16 @md:px-8", className)}
>
<MotionConfig reducedMotion="user">
<div className="mx-auto flex w-full max-w-sm flex-col">
{items.map((item, i) => (
<Item
key={item.question}
item={item}
open={open === i}
groupStart={startsGroup(i)}
groupEnd={endsGroup(i)}
onToggle={() => setOpen((current) => (current === i ? null : i))}
/>
))}
</div>
</MotionConfig>
</section>
);
}