---
description: Display togglable accordion panels.
links:
  - label: GitHub
    icon: i-simple-icons-github
    to: https://github.com/nuxt/ui/blob/dev/src/runtime/components/elements/Accordion.vue
  - label: Disclosure
    icon: i-simple-icons-headlessui
    to: 'https://headlessui.com/vue/disclosure'
---

## Usage

Pass an array to the `items` prop of the Accordion component. Each item can have any property from the [Button](/elements/button) component such as `label`, `icon`, `color`, `variant`, `size`, etc. but also:

- `slot` - A key to customize the item with a slot.
- `content` - The content to display in the panel by default.
- `disabled` - Determines whether the item is disabled or not.
- `defaultOpen` - Determines whether the item is initially open or closed.
- `closeOthers` - Determines whether the item click close others or not. **It only works with multiple mode**.

::component-example
#default
:accordion-example-basic

#code
```vue
<script setup>
const items = [{
  label: 'Getting Started',
  icon: 'i-heroicons-information-circle',
  defaultOpen: true,
  content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed neque elit, tristique placerat feugiat ac, facilisis vitae arcu. Proin eget egestas augue. Praesent ut sem nec arcu pellentesque aliquet. Duis dapibus diam vel metus tempus vulputate.'
}, {
  label: 'Installation',
  icon: 'i-heroicons-arrow-down-tray',
  disabled: true,
  content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed neque elit, tristique placerat feugiat ac, facilisis vitae arcu. Proin eget egestas augue. Praesent ut sem nec arcu pellentesque aliquet. Duis dapibus diam vel metus tempus vulputate.'
}, ...]
</script>

<template>
  <UAccordion :items="items" />
</template>
```
::

### Style

You can also pass any prop from the [Button](/elements/button) component directly to the Accordion component to style the buttons.

::component-card
---
baseProps:
  items:
    - label: '1. What is Nuxt UI?'
      content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit'
    - label: '2. Getting Started'
      content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit'
    - label: '3. Theming'
      content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit'
    - label: '4. Components'
      content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit'
props:
  color: 'primary'
  variant: 'soft'
  size: 'sm'
ui:
  variant:
    solid: 1
    outline: 1
    ghost: 1
    soft: 1
    link: 1
  size:
    2xs: ''
    xs: ''
    sm: ''
    md: ''
    lg: ''
    xl: ''
---
::

### Icon

Use any icon from [Iconify](https://icones.js.org) by setting the `open-icon` and `close-icon` props by using this pattern: `i-{collection_name}-{icon_name}` or change it globally in `ui.accordion.default.openIcon` and `ui.accordion.default.closeIcon`.

You can also set them to `null` to hide the icons.

::component-card
---
baseProps:
  items:
    - label: '1. What is Nuxt UI?'
      content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit'
    - label: '2. Getting Started'
      content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit'
    - label: '3. Theming'
      content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit'
    - label: '4. Components'
      content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit'
props:
  openIcon: 'i-heroicons-plus'
  closeIcon: 'i-heroicons-minus'
excludedProps:
  - openIcon
  - closeIcon
---
::

### Multiple

Use the `multiple` prop to to allow multiple elements to be opened at the same time.

::component-card
---
baseProps:
  items:
    - label: 'What is Nuxt UI?'
      content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit'
    - label: 'Getting Started'
      content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit'
    - label: 'Theming'
      content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit'
    - label: 'Components'
      content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit'
props:
  multiple: true
excludedProps:
  - defaultOpen
---
::

### Open

Use the `default-open` prop to open all items by default. Works better when the `multiple` prop is set to `true`.

::component-card
---
baseProps:
  items:
    - label: 'What is Nuxt UI?'
      content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit'
    - label: 'Getting Started'
      content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit'
    - label: 'Theming'
      content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit'
    - label: 'Components'
      content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit'
props:
  defaultOpen: true
  multiple: true
excludedProps:
  - defaultOpen
  - multiple
---
::

## Slots

You can use slots to customize the buttons and items content of the Accordion.

### `default`

Use the `#default` slot to customize the trigger buttons. You will have access to the `item`, `index`, `open` properties and `close` method in the slot scope.

::component-example
#default
:accordion-example-default-slot

#code
```vue
<script setup>
const items = [...]
</script>

<template>
  <UAccordion :items="items" :ui="{ wrapper: 'flex flex-col w-full' }">
    <template #default="{ item, index, open }">
      <UButton color="gray" variant="ghost" class="border-b border-gray-200 dark:border-gray-700" :ui="{ rounded :'rounded-none', padding: { sm:'p-3' } }">
        <template #leading>
          <div class="w-6 h-6 rounded-full bg-primary-500 dark:bg-primary-400 flex items-center justify-center -my-1">
            <UIcon :name="item.icon" class="w-4 h-4 text-white dark:text-gray-900" />
          </div>
        </template>

        <span class="truncate">{{ index + 1 }}. {{ item.label }}</span>

        <template #trailing>
          <UIcon
            name="i-heroicons-chevron-right-20-solid"
            class="w-5 h-5 ms-auto transform transition-transform duration-200"
            :class="[open && 'rotate-90']"
          />
        </template>
      </UButton>
    </template>
  </UAccordion>
</template>
```
::

### `item`

Use the `#item` slot to customize the items content or pass a `slot` property to customize a specific item. You will have access to the `item`, `index`, `open` properties and `close` method in the slot scope.

::component-example
#default
:accordion-example-item-slot

#code
```vue
<script setup>
const items = [{
  label: 'Getting Started',
  icon: 'i-heroicons-information-circle',
  defaultOpen: true,
  slot: 'getting-started'
}, {
  label: 'Installation',
  icon: 'i-heroicons-arrow-down-tray',
  defaultOpen: true,
  slot: 'installation'
}, {
  label: 'Theming',
  icon: 'i-heroicons-eye-dropper',
  defaultOpen: true,
  description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed neque elit, tristique placerat feugiat ac, facilisis vitae arcu. Proin eget egestas augue. Praesent ut sem nec arcu pellentesque aliquet. Duis dapibus diam vel metus tempus vulputate.'
}, ...]
</script>

<template>
  <UAccordion :items="items">
    <template #item="{ item }">
      <p class="italic text-gray-900 dark:text-white text-center">
        {{ item.description }}
      </p>
    </template>

    <template #getting-started>
      <div class="text-gray-900 dark:text-white text-center">
        <Logo class="w-auto h-8 mx-auto" />

        <p class="text-sm text-gray-500 dark:text-gray-400 mt-2">
          Fully styled and customizable components for Nuxt.
        </p>
      </div>
    </template>

    <template #installation="{ description }">
      <div class="flex flex-col justify-center items-center gap-1 mb-4">
        <h3 class="text-xl font-bold text-gray-900 dark:text-white">
          Installation
        </h3>
        <p class="text-sm text-gray-500 dark:text-gray-400">
          Install <code>@nuxt/ui</code> dependency to your project:
        </p>
        <p>
          {{ description }}
        </p>
      </div>

      <div class="flex flex-col items-center">
        <code>$ npm install @nuxt/ui</code>
        <code>$ yarn add @nuxt/ui</code>
        <code>$ pnpm add @nuxt/ui</code>
      </div>
    </template>
  </UAccordion>
</template>
```
::

## Props

:component-props

## Preset

:component-preset
