Accordion
updatedCustomers have questions? Answer them, then fold them away. Stacked sections that open one at a time or several at once, and open themselves when find in page matches their text.
Open Props in the corner of the example to try disabled. On Accordion it locks every item; disabled on one AccordionItem locks that item alone.
Installation
Usage
<script setup lang="ts">
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/components/ui/accordion'
</script>
<template>
<Accordion type="single">
<AccordionItem value="shipping">
<AccordionTrigger>How long does shipping take?</AccordionTrigger>
<AccordionContent>Orders arrive three to five days after they ship.</AccordionContent>
</AccordionItem>
</Accordion>
</template>
type="single" keeps one item open at a time. Click it again to close it: collapsible is on by default.
Examples
Multiple
type="multiple" lets several items stay open. v-model and default-value then take an array.
Find in page
Ctrl+F finds text inside closed items, and they open to show the match. Links to an anchor inside a closed item open it too.
That's why unmount-on-hide is off by default. What it means for you:
- All content is mounted from the start. Fine for text. For heavy charts or tables, turn on
unmount-on-hide. - SSR works. Closed text is in the HTML, so search engines see it too. One catch: if someone finds a match before hydration, the item opens, but the first click on it does nothing.
- Browser support. Chromium 102+ and Firefox 139+. Safari isn't there yet: closed items just aren't searched, and everything else works.
Unmount on hide
With unmount-on-hide, a closed item's content leaves the page and mounts again on open. Each item can override it: in the demo, the glossary stays mounted, so Ctrl+F still finds it.
API Reference
Every part takes a class. On AccordionContent, it styles the padded block inside.
Accordion
| Prop | Default | Type and description |
|---|---|---|
| collapsible | true | booleanIn |
| disabled | false | booleanDisables every item. |
| dir | — | DirectionReading direction. Inherits from a surrounding |
| orientation | "vertical" | DataOrientationWhich arrow keys move between triggers: up and down for |
| unmountOnHide | false | booleanRemoves a closed item's content from the page. Off by default, so closed answers stay in the page as |
| asChild | — | booleanRender the single child instead of a wrapper, merging this part's attributes and classes onto it. |
| as | — | AsTag | ComponentThe element or component to render. |
| type | — | SingleOrMultipleType
|
| modelValue | — | string | string[]The open item's value, or an array of values in |
| defaultValue | — | string | string[]The item or items open at first when |
| Event | Payload and description |
|---|---|
| update:modelValue | [value: string | string[] | undefined]Fires when an item opens or closes. |
| Slot | Scope and description |
|---|---|
| default | { modelValue: AcceptableValue | AcceptableValue[] | undefined; }The items. Receives |
AccordionItem
| Prop | Default | Type and description |
|---|---|---|
| value* | — | stringThe value that opens this item. |
| disabled | false | booleanStops this item from opening or closing. |
| unmountOnHide | undefined | booleanOverrides the accordion's |
| asChild | — | booleanRender the single child instead of a wrapper, merging this part's attributes and classes onto it. |
| as | — | AsTag | ComponentThe element or component to render. |
| Slot | Scope and description |
|---|---|
| default | { open: boolean; }The trigger and the content. Receives |
AccordionTrigger
| Prop | Default | Type and description |
|---|---|---|
| asChild | — | booleanRender the single child instead of a wrapper, merging this part's attributes and classes onto it. |
| as | — | AsTag | ComponentThe element or component to render. |
| Slot | Scope and description |
|---|---|
| default | {}The question or heading. |
| icon | {}Replaces the chevron. It rotates half a turn while the item is open. |
AccordionContent
| Prop | Default | Type and description |
|---|---|---|
| forceMount | — | booleanKeeps the content mounted and visible to animate it with an external library. |
| asChild | — | booleanRender the single child instead of a wrapper, merging this part's attributes and classes onto it. |
| as | — | AsTag | ComponentThe element or component to render. |
| Slot | Scope and description |
|---|---|
| default | {}The answer. |
Props
- collapsible
true booleanInsinglemode, lets a second click close the open item. On by default.- disabled
false booleanDisables every item.- dir
DirectionReading direction. Inherits from a surroundingConfigProviderwhen not set. Otherwiseltr.- orientation
"vertical" DataOrientationWhich arrow keys move between triggers: up and down forvertical, left and right forhorizontal.- unmountOnHide
false booleanRemoves a closed item's content from the page. Off by default, so closed answers stay in the page ashidden="until-found": the browser's find in page searches them and opens the item that matches.- asChild
booleanRender the single child instead of a wrapper, merging this part's attributes and classes onto it.- as
AsTag | ComponentThe element or component to render.- type
SingleOrMultipleTypesinglekeeps one item open at a time;multiplelets several stay open, andv-modelbecomes an array.- modelValue
string | string[]The open item's value, or an array of values inmultiplemode, bound withv-model.- defaultValue
string | string[]The item or items open at first whenv-modelis not used.
Emits
- update:modelValue
[value: string | string[] | undefined]Fires when an item opens or closes.
Slots
- default
{ modelValue: AcceptableValue | AcceptableValue[] | undefined; }The items. ReceivesmodelValue.
Props
- value*
stringThe value that opens this item.- disabled
false booleanStops this item from opening or closing.- unmountOnHide
undefined booleanOverrides the accordion'sunmount-on-hidefor this item; unset, it follows the accordion.- asChild
booleanRender the single child instead of a wrapper, merging this part's attributes and classes onto it.- as
AsTag | ComponentThe element or component to render.
Slots
- default
{ open: boolean; }The trigger and the content. Receivesopen.
Props
- asChild
booleanRender the single child instead of a wrapper, merging this part's attributes and classes onto it.- as
AsTag | ComponentThe element or component to render.
Slots
- default
{}The question or heading.- icon
{}Replaces the chevron. It rotates half a turn while the item is open.
Props
- forceMount
booleanKeeps the content mounted and visible to animate it with an external library.- asChild
booleanRender the single child instead of a wrapper, merging this part's attributes and classes onto it.- as
AsTag | ComponentThe element or component to render.
Slots
- default
{}The answer.
Data attributes
| data-slot | Attributes | Description |
|---|---|---|
| accordion | — | The root. |
| accordion-item | data-state, data-disabled, data-orientation | One item. |
| accordion-header | data-state, data-disabled, data-orientation | The heading that holds the trigger. |
| accordion-trigger | data-state, data-disabled, data-orientation | The button that opens and closes the item. |
| accordion-content | data-state, data-disabled, data-orientation | The animated panel; hidden until found while closed. |
Accessibility
Each trigger is a button inside a heading, and each panel is a region named by its trigger.
| Key | Action |
|---|---|
| Tab | Moves focus to the next trigger. |
| Space | Opens or closes the focused item. |
| Enter | Opens or closes the focused item. |
| ArrowDown | Moves focus to the next trigger, wrapping at the end. |
| ArrowUp | Moves focus to the previous trigger, wrapping at the start. |
| Home | Moves focus to the first trigger. |
| End | Moves focus to the last trigger. |