Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Collapsible examples · Faq

FAQ Item Collapsible for React

An FAQ question with a plus that turns into a cross when its answer opens, above a bottom border.

Framework
UI library

The plainest FAQ row: a question, a plus, and an answer underneath, separated from the next question by a bottom border. The question is a heading that wraps the trigger, and the plus turns into a cross while the answer is open. Stack a few for a light FAQ section.

Preview

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

FAQ

Why is the question an h3?

The h3 wraps CollapsibleTrigger, so the question is a heading in the page outline and the trigger inside it is still the button. Pick the heading level that fits your page.

Does the Plus icon change when the answer opens?

Yes, it turns 45 degrees into a cross. The trigger has the group class and sets aria-expanded while open, so group-aria-expanded:rotate-45 on PlusIcon turns it, eased by transition-transform duration-200.

What do items-start, gap-4, and text-start do on the trigger?

items-start keeps the plus level with the first line when the question wraps, gap-4 keeps it clear of the text, and text-start lines the question up with the start edge instead of centering it.

How do I separate the next question?

Each item has border-b pb-4, so stacking them draws a line under each answer. Give the list a gap-4 or a top margin on each item for space above the next question.

How do I start this answer open?

Set defaultOpen on Collapsible.

It starts closed.

When is a stack of these an Accordion?

Each Collapsible opens on its own. When several sit in one list and only one should be open at a time, with arrow keys between the headers, use an Accordion.