Skip to content
English

How it works

Each item is a filled, rounded row with no outlines or separators; its round plus turns 45° into a close mark and fills with ink while the item is open. Each panel is a one-row grid whose grid-template-rows goes from 0fr to 1fr (the content's natural height), with an inner min-height:0 + overflow:hidden layer clipping it. Nothing is measured in JS, so late images or rewrapping text cannot misalign it. The content also slides down 8px and fades in, slightly after the height starts. Closing is about 80% as long, and visibility turns hidden only after the height has closed.

Use it for

  • FAQs in a help center or at the bottom of a checkout page.
  • Folding low-use advanced options on a settings page.
  • Long explanations such as shipping or return rules, collapsed by default to save space.

Look elsewhere when

  • Key information every visitor must see: folded means hidden, so lay it out flat.
  • A single item: use one disclosure such as “Show more” instead of an accordion.
  • Switching between sibling views, one at a time: tabs are clearer.

Usage

import { SmoothAccordion } from './SmoothAccordion.jsx'

export function Faq() {
  return (
    <SmoothAccordion
      defaultValue={['ship']}
      items={[
        { value: 'ship', title: 'How long does delivery take?', content: 'Usually 2 to 4 business days.' },
        { value: 'return', title: 'Can I return an item?', content: 'Yes, within 30 days if it is unused.' },
      ]}
    />
  )
}

Props

PropTypeDefaultWhat it does
items{ value, title, content, disabled? }[]—The items. Each has a unique value, a title, content, and an optional disabled flag.
allowMultiplebooleanfalseAllows several items open at once. When off, opening one closes the others; turning it off at runtime keeps only the last opened item.
valuestring[]—Controlled: the list of open values.
defaultValuestring[][]Uncontrolled: the values open at first.
onChange(value: string[]) => void—Called when the open items change.
durationnumber240Opening time in ms; closing takes 0.8 times as long. When omitted it follows --ds-duration-base.
headingLevel2 | 3 | 4 | 5 | 63Heading level wrapped around each title button; choose it to fit the page outline.
...restHTMLAttributes<HTMLDivElement>—Other attributes go to the root <div>.

Accessibility

  • Each title is a <button> with aria-expanded and aria-controls, wrapped in a heading (h3 by default) to keep the page outline.
  • Panels are role="region" labelled by their title.
  • Closed panels are visibility: hidden, so their links and buttons cannot be tabbed to or read.
  • Enter and Space toggle; Up and Down move between headings; Home and End jump to the first and last.
  • Titles are at least 48px high with a :focus-visible ring; reduced motion opens and closes without a transition.

Motion

Opening: height 240ms ease-out, content fades in over 240ms ease-out (36ms delay) and slides down 8px, the plus turns 45° on a 240ms spring while its disc fills with ink. Closing: height 192ms standard, content fades out in 120ms ease-in. A pressed plus scales to 0.9.

Add it to your project

Copy the prompt into Codex or Claude Code. The agent reads the published source, shows you what it will write and adds the component next to your own.

SmoothAccordion.jsxsmooth-accordion.csstokens.cssREADME.md

Both files install together. The stylesheet reads the design tokens in tokens.css and carries fallbacks, so it also works alone.

Navigation