# Accordion

Host: Base UI. Path: transitions. Preset: `collapse`. Built against [@base-ui/react 1.5.0](https://www.npmjs.com/package/@base-ui/react/v/1.5.0).

A grid row rather than a height, so the preset reads none of the four panel-height variables the two libraries publish between them.

The page this file mirrors mounts the component twice, once with the attribute and once without, so the only difference between the two is the library.

Upstream documentation: [Base UI documentation](https://base-ui.com/react/components/accordion)

The same component in other hosts: [Radix UI](/radix/accordion.md).

## Where the attribute goes

The parts this demo composes, and the value each one carries. Everything inside an animated part is that part's content, so the tree stops there.

```text
Accordion.Root
  Accordion.Item
    Accordion.Header
      Accordion.Trigger
    Accordion.Panel  data-motion="collapse"
```

## How the match works

| Step | Value |
| --- | --- |
| host writes | `data-open / data-closed, plus data-ending-style` |
| easeful matches | `[data-motion~="collapse"][data-ending-style] { grid-template-rows: 0fr }` |
| what runs | `transition: grid-template-rows 150ms` |
| you write | `<Accordion.Panel data-motion="collapse" />` |

## Every value that works here

Every value the manifest allows on this host, single presets and the pairs that compose. The first is what this component ships with. Both stages are the same component, so anything that changes between them is the attribute.

| Value | Link |
| --- | --- |
| `collapse` | the default |
| `fade` | [fade](/base-ui/accordion#motion=fade) |
| `scale-fade` | [scale-fade](/base-ui/accordion#motion=scale-fade) |
| `slide-up` | [slide-up](/base-ui/accordion#motion=slide-up) |
| `fade collapse` | [fade collapse](/base-ui/accordion#motion=fade%20collapse) |
| `fade slide-up` | [fade slide-up](/base-ui/accordion#motion=fade%20slide-up) |
| `scale-fade slide-up` | [scale-fade slide-up](/base-ui/accordion#motion=scale-fade%20slide-up) |

## Source

`apps/docs/components/demos/base-ui/accordion.tsx`

```tsx
"use client"

import { Accordion } from "@base-ui/react/accordion"
import type { DemoProps } from "@/components/demos/props"

export function BaseUiAccordion({ motion }: DemoProps) {
  return (
    <Accordion.Root>
      <Accordion.Item value="one">
        <Accordion.Header style={{ margin: 0 }}>
          <Accordion.Trigger className="btn">What ships to the browser?</Accordion.Trigger>
        </Accordion.Header>
        <Accordion.Panel data-motion={motion}>
          <div className="panel" style={{ marginTop: 12 }}>
            <p className="panel__body">
              CSS only. The panel is a grid with one row, and the child inside it is the clip.
            </p>
          </div>
        </Accordion.Panel>
      </Accordion.Item>
    </Accordion.Root>
  )
}
```
