Accordion
Sections that open to show more. Separated by space, not lines, in five styles from quiet lists to frosted glass.
Surface
Collapsible sections separated by space, not lines. The open section sits on its own surface.
Installation
$npx shadcn@latest add @stillui/accordionOr copy the source into your project. It needs the shadcn color tokens and the cn helper.
"use client";
// stillui.dev/components/accordion
import { AnimatePresence, motion, useReducedMotion } from "motion/react";
import { useId, useState, type ReactNode } from "react";
import { cn } from "@/lib/utils";
// Height opens on an on-screen ease; content fades in just after the space exists.
const HEIGHT = { duration: 0.28, ease: [0.65, 0, 0.35, 1] } as const;
const CONTENT = { duration: 0.2, ease: [0.16, 1, 0.3, 1] } as const;
export type AccordionItem = {
value: string;
title: ReactNode;
content: ReactNode;
};
type AccordionProps = {
items: AccordionItem[];
/** Allow several sections open at once. */
multiple?: boolean;
defaultOpen?: string[];
className?: string;
};
export function Accordion({ items, multiple = false, defaultOpen = [], className }: AccordionProps) {
const [open, setOpen] = useState<string[]>(defaultOpen);
const toggle = (value: string) =>
setOpen((current) => {
if (current.includes(value)) return current.filter((v) => v !== value);
return multiple ? [...current, value] : [value];
});
return (
<div className={cn("grid gap-1", className)}>
{items.map((item) => (
<Section key={item.value} item={item} open={open.includes(item.value)} onToggle={() => toggle(item.value)} />
))}
</div>
);
}
function Section({ item, open, onToggle }: { item: AccordionItem; open: boolean; onToggle: () => void }) {
const reduce = useReducedMotion();
const id = useId();
const panelId = `${id}-panel`;
const triggerId = `${id}-trigger`;
return (
<div className={cn("rounded-lg transition-colors duration-200", open && "bg-muted")}>
<h3>
<button
id={triggerId}
type="button"
aria-expanded={open}
aria-controls={panelId}
onClick={onToggle}
className={cn(
"flex w-full items-center justify-between gap-4 rounded-lg px-4 py-3 text-left text-[15px] font-medium",
"transition-[color,background-color,box-shadow,scale] active:scale-[0.99] duration-150",
!open && "hover:bg-muted",
)}
>
{item.title}
<motion.svg
viewBox="0 0 16 16"
fill="none"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
className="size-4 shrink-0 text-muted-foreground"
animate={{ rotate: open ? 180 : 0 }}
transition={reduce ? { duration: 0 } : HEIGHT}
aria-hidden
>
<path d="M4 6l4 4 4-4" />
</motion.svg>
</button>
</h3>
<AnimatePresence initial={false}>
{open ? (
<motion.div
id={panelId}
role="region"
aria-labelledby={triggerId}
className="overflow-hidden"
initial={{ height: 0 }}
animate={{ height: "auto" }}
exit={{ height: 0 }}
transition={reduce ? { duration: 0 } : HEIGHT}
>
<motion.div
className="max-w-[60ch] px-4 pb-4 text-sm leading-relaxed text-muted-foreground"
initial={{ opacity: 0, y: reduce ? 0 : -4 }}
animate={{ opacity: 1, y: 0, transition: { ...CONTENT, delay: reduce ? 0 : 0.06 } }}
exit={{ opacity: 0, transition: { duration: 0.1 } }}
>
{item.content}
</motion.div>
</motion.div>
) : null}
</AnimatePresence>
</div>
);
}States
- Closed
- Just the title and a chevron. A soft background appears on hover.
- Opening
- Height grows first; the text fades in once there is room for it.
- Open
- The section gets a muted surface so title and content read as one unit.
- Single / multiple
- By default opening one closes the others. Pass multiple to allow several.
- Keyboard
- Each title is a button inside a heading, with aria-expanded and a linked region.
- Reduced motion
- Sections open and close instantly.
Notes
Good for FAQs and settings people rarely need. Don’t hide something most visitors need to read.
Cards
Each section is its own raised card. The open card grows on a weighted spring and its neighbours glide aside.
Installation
$npx shadcn@latest add @stillui/accordion-cardsOr copy the source into your project. It needs the shadcn color tokens and the cn helper.
"use client";
// stillui.dev/components/accordion#cards
import { AnimatePresence, motion, useReducedMotion } from "motion/react";
import { useId, useState, type ReactNode } from "react";
import { cn } from "@/lib/utils";
// A weighted spring: the open card pushes its neighbours and they settle together.
const SPRING = { type: "spring", stiffness: 260, damping: 30, mass: 0.9 } as const;
export type AccordionCardItem = {
value: string;
title: ReactNode;
content: ReactNode;
};
type AccordionCardsProps = {
items: AccordionCardItem[];
defaultOpen?: string;
className?: string;
};
/** Each section is its own card. One opens at a time and the others glide out of the way. */
export function AccordionCards({ items, defaultOpen, className }: AccordionCardsProps) {
const [open, setOpen] = useState<string | undefined>(defaultOpen);
return (
<div className={cn("grid gap-2", className)}>
{items.map((item) => (
<Card
key={item.value}
item={item}
open={open === item.value}
onToggle={() => setOpen((current) => (current === item.value ? undefined : item.value))}
/>
))}
</div>
);
}
function Card({ item, open, onToggle }: { item: AccordionCardItem; open: boolean; onToggle: () => void }) {
const reduce = useReducedMotion();
const id = useId();
const transition = reduce ? { duration: 0 } : SPRING;
return (
<motion.div
layout={!reduce}
transition={transition}
className={cn("overflow-hidden rounded-xl bg-card shadow-raised", open && "my-1")}
style={{ borderRadius: 12 }}
>
<motion.h3 layout="position" transition={transition}>
<button
id={`${id}-trigger`}
type="button"
aria-expanded={open}
aria-controls={`${id}-panel`}
onClick={onToggle}
className="flex w-full items-center justify-between gap-4 px-4 py-3.5 text-left text-[15px] font-medium transition-[scale] duration-150 active:scale-[0.99]"
>
{item.title}
<span
className={cn(
"grid size-6 shrink-0 place-items-center rounded-full transition-colors duration-200",
open ? "bg-primary text-primary-foreground" : "bg-secondary text-muted-foreground",
)}
>
<motion.svg
viewBox="0 0 16 16"
fill="none"
stroke="currentColor"
strokeWidth="1.75"
strokeLinecap="round"
strokeLinejoin="round"
className="size-3.5"
animate={{ rotate: open ? 180 : 0 }}
transition={transition}
aria-hidden
>
<path d="M4 6l4 4 4-4" />
</motion.svg>
</span>
</button>
</motion.h3>
<AnimatePresence initial={false}>
{open ? (
<motion.div
id={`${id}-panel`}
role="region"
aria-labelledby={`${id}-trigger`}
initial={{ opacity: 0, height: 0 }}
animate={{ opacity: 1, height: "auto" }}
exit={{ opacity: 0, height: 0 }}
transition={transition}
>
<div className="max-w-[60ch] px-4 pb-4 text-sm leading-relaxed text-muted-foreground">{item.content}</div>
</motion.div>
) : null}
</AnimatePresence>
</motion.div>
);
}States
- Closed
- A card with the title and a round chevron button.
- Open
- The chevron fills with the primary color and turns; a little extra space separates the open card.
- Switching
- One card closes as the next opens, and every card below moves with one spring.
- Keyboard
- Titles are buttons inside headings, with aria-expanded and a linked region.
- Reduced motion
- Cards open and close instantly, without layout movement.
Notes
Works best with three to six short questions, such as a pricing FAQ.
Plus
Large titles with a plus that folds into a minus. While one answer is open, the other titles step back.
Installation
$npx shadcn@latest add @stillui/accordion-plusOr copy the source into your project. It needs the shadcn color tokens and the cn helper.
"use client";
// stillui.dev/components/accordion#plus
import { AnimatePresence, motion, useReducedMotion } from "motion/react";
import { useId, useState, type ReactNode } from "react";
import { cn } from "@/lib/utils";
const EASE = { duration: 0.32, ease: [0.65, 0, 0.35, 1] } as const;
export type AccordionPlusItem = {
value: string;
title: ReactNode;
content: ReactNode;
};
type AccordionPlusProps = {
items: AccordionPlusItem[];
defaultOpen?: string;
className?: string;
};
/** Large titles with a plus that folds into a minus. While one is open, the other titles step back. */
export function AccordionPlus({ items, defaultOpen, className }: AccordionPlusProps) {
const [open, setOpen] = useState<string | undefined>(defaultOpen);
return (
<div className={cn("grid", className)}>
{items.map((item) => (
<Row
key={item.value}
item={item}
open={open === item.value}
dimmed={open !== undefined && open !== item.value}
onToggle={() => setOpen((current) => (current === item.value ? undefined : item.value))}
/>
))}
</div>
);
}
type RowProps = {
item: AccordionPlusItem;
open: boolean;
dimmed: boolean;
onToggle: () => void;
};
function Row({ item, open, dimmed, onToggle }: RowProps) {
const reduce = useReducedMotion();
const id = useId();
const transition = reduce ? { duration: 0 } : EASE;
return (
<div>
<h3>
<button
id={`${id}-trigger`}
type="button"
aria-expanded={open}
aria-controls={`${id}-panel`}
onClick={onToggle}
className={cn(
"flex w-full items-center justify-between gap-6 py-4 text-left text-lg font-medium leading-snug tracking-[-0.01em] transition-[color,background-color,box-shadow,scale] active:scale-[0.99] duration-200",
dimmed ? "text-muted-foreground hover:text-foreground" : "text-foreground",
)}
>
{item.title}
<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" className="size-4 shrink-0" aria-hidden>
<path d="M3 8h10" />
{/* The vertical bar turns flat, so plus becomes minus. */}
<motion.path d="M8 3v10" animate={{ rotate: open ? 90 : 0 }} transition={transition} style={{ originX: "8px", originY: "8px" }} />
</svg>
</button>
</h3>
<AnimatePresence initial={false}>
{open ? (
<motion.div
id={`${id}-panel`}
role="region"
aria-labelledby={`${id}-trigger`}
className="overflow-hidden"
initial={{ height: 0, opacity: 0 }}
animate={{ height: "auto", opacity: 1 }}
exit={{ height: 0, opacity: 0 }}
transition={transition}
>
<div className="max-w-[60ch] pb-5 text-[15px] leading-relaxed text-muted-foreground">{item.content}</div>
</motion.div>
) : null}
</AnimatePresence>
</div>
);
}States
- Closed
- Only titles, at a size that works on marketing pages.
- Open
- The plus’s vertical bar turns flat into a minus while the answer unfolds.
- Focus on one
- Other titles fade to the muted color, and come back on hover.
- Keyboard
- Titles are buttons inside headings, with aria-expanded and a linked region.
- Reduced motion
- Answers appear and disappear instantly.
Notes
Separated only by space, so give it room. It suits FAQ sections more than dense settings.
Icon rows
Rows with an icon and a one-line summary, like a settings list. Several can be open, and content lines up under the text.
Installation
$npx shadcn@latest add @stillui/accordion-iconsOr copy the source into your project. It needs the shadcn color tokens and the cn helper.
"use client";
// stillui.dev/components/accordion#icons
import { AnimatePresence, motion, useReducedMotion } from "motion/react";
import { useId, useState, type ReactNode } from "react";
import { cn } from "@/lib/utils";
const HEIGHT = { duration: 0.26, ease: [0.65, 0, 0.35, 1] } as const;
export type AccordionIconItem = {
value: string;
icon: ReactNode;
title: ReactNode;
/** One line under the title, visible while closed. */
summary?: ReactNode;
content: ReactNode;
};
type AccordionIconsProps = {
items: AccordionIconItem[];
multiple?: boolean;
defaultOpen?: string[];
className?: string;
};
/** Rows with an icon and a one-line summary, like a settings list. Content lines up under the text. */
export function AccordionIcons({ items, multiple = true, defaultOpen = [], className }: AccordionIconsProps) {
const [open, setOpen] = useState<string[]>(defaultOpen);
const toggle = (value: string) =>
setOpen((current) => {
if (current.includes(value)) return current.filter((v) => v !== value);
return multiple ? [...current, value] : [value];
});
return (
<div className={cn("grid gap-1", className)}>
{items.map((item) => (
<Row key={item.value} item={item} open={open.includes(item.value)} onToggle={() => toggle(item.value)} />
))}
</div>
);
}
function Row({ item, open, onToggle }: { item: AccordionIconItem; open: boolean; onToggle: () => void }) {
const reduce = useReducedMotion();
const id = useId();
const transition = reduce ? { duration: 0 } : HEIGHT;
return (
<div className="rounded-xl transition-colors duration-200 hover:bg-muted/60">
<h3>
<button
id={`${id}-trigger`}
type="button"
aria-expanded={open}
aria-controls={`${id}-panel`}
onClick={onToggle}
className="flex w-full items-center gap-3 rounded-xl p-3 text-left transition-[scale] duration-150 active:scale-[0.99]"
>
<span
className={cn(
"grid size-9 shrink-0 place-items-center rounded-lg transition-colors duration-200 [&_svg]:size-[18px]",
open ? "bg-primary text-primary-foreground" : "bg-secondary text-muted-foreground",
)}
aria-hidden
>
{item.icon}
</span>
<span className="grid min-w-0 flex-1 gap-0.5">
<span className="text-[15px] font-medium leading-5">{item.title}</span>
{item.summary ? <span className="truncate text-[13px] leading-5 text-muted-foreground">{item.summary}</span> : null}
</span>
<motion.svg
viewBox="0 0 16 16"
fill="none"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
className="size-4 shrink-0 text-muted-foreground"
animate={{ rotate: open ? 90 : 0 }}
transition={transition}
aria-hidden
>
<path d="M6 4l4 4-4 4" />
</motion.svg>
</button>
</h3>
<AnimatePresence initial={false}>
{open ? (
<motion.div
id={`${id}-panel`}
role="region"
aria-labelledby={`${id}-trigger`}
className="overflow-hidden"
initial={{ height: 0, opacity: 0 }}
animate={{ height: "auto", opacity: 1 }}
exit={{ height: 0, opacity: 0 }}
transition={transition}
>
{/* Indented to the text column so the content reads as part of the row. */}
<div className="max-w-[60ch] pb-4 pl-[60px] pr-4 text-sm leading-relaxed text-muted-foreground">{item.content}</div>
</motion.div>
) : null}
</AnimatePresence>
</div>
);
}States
- Closed
- Icon, title and a summary of the current value, so people often don’t need to open it.
- Open
- The icon tile fills with the primary color and the arrow turns down.
- Multiple
- Several rows can be open by default. Pass multiple={false} to allow only one.
- Keyboard
- Titles are buttons inside headings, with aria-expanded and a linked region.
- Reduced motion
- Rows open and close instantly.
Notes
Write the summary as the current state (“Pro plan, renews 3 March”), not a description of the section.
Glass
One sheet of frosted glass. The open section lifts out as its own card, catches a passing light, and its answer comes into focus.
Installation
$npx shadcn@latest add @stillui-pro/accordion-glassA paid component. The command needs the token from your account in STILLUI_TOKEN; your account page shows the one-time setup.
This is a paid component. Its source and install come with access.
States
- Closed
- All sections share one sheet of glass, with no lines between them.
- Hover
- One soft surface follows the pointer from row to row, even across the gaps between cards.
- Opening
- The section parts from its neighbours, a band of light crosses it once, and the answer sharpens from a blur.
- Closing
- The answer blurs out first, then the card melts back into the sheet.
- Single / multiple
- By default opening one closes the others. Pass multiple to allow several.
- Keyboard
- Each title is a button inside a heading, with aria-expanded and a linked region.
- Reduced motion
- Sections open and close instantly, with no light or blur.
Notes
Glass needs something behind it. On a flat background it reads as a quiet raised surface, which is fine too.