Skip to content

shadcn.io is an independent project built on shadcn/ui

Components

Free

Accordion for Vue

Stacked headings that each open the section under them, one at a time or several at once. An accordion for Vue on Ark UI, for FAQs and settings.

On this page9 sections
UI library: Ark UI

An accordion stacks headings in a column, and each heading opens the section under it. One section is open at a time unless you allow several. It suits an FAQ or a long settings page, where most of the content can stay folded away until someone needs it.

For one section that opens and closes on its own, use a Collapsible. When every section matters as much as the next and people move between them, Tabs keep one in view at all times.

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.

Anatomy

Accordion anatomy: root, item, item trigger, item content, item indicator

Usage

<script setup lang="ts">
import {
  Accordion, AccordionContent, AccordionItem, AccordionTrigger,
} from "@/components/ui/accordion";
</script>
<template>
  <Accordion class="w-full max-w-sm" :defaultValue='["shipping"]'>
    <AccordionItem value="shipping">
      <AccordionTrigger>What are your shipping options?</AccordionTrigger>
      <AccordionContent>
        We offer standard (5-7 days), express (2-3 days), and overnight
        shipping. Free shipping on international orders.
      </AccordionContent>
    </AccordionItem>
    <AccordionItem value="returns">
      <AccordionTrigger>What is your return policy?</AccordionTrigger>
      <AccordionContent>
        Returns accepted within 30 days. Items must be unused and in original
        packaging. Refunds processed within 5-7 business days.
      </AccordionContent>
    </AccordionItem>
    <AccordionItem value="support">
      <AccordionTrigger>How can I contact customer support?</AccordionTrigger>
      <AccordionContent>
        Reach us via email, live chat, or phone. We respond within 24 hours
        during business days.
      </AccordionContent>
    </AccordionItem>
  </Accordion>
</template>

Accessibility

Each trigger is a <button> that reports its state with aria-expanded, so a screen reader says whether a section is open and Enter or Space toggles it. The button has no heading around it. Wrap each AccordionTrigger in the heading level your page calls for, so people using a screen reader can jump from section to section.

Space
When focus is on a trigger of a collapsed item, the item is expanded.
Enter
When focus is on a trigger of a collapsed section, expands the section.
Tab
Moves focus to the next focusable element.
Shift+Tab
Moves focus to the previous focusable element.
Arrow Down
Moves focus to the next trigger.
Arrow Up
Moves focus to the previous trigger.
Home
When focus is on a trigger, moves focus to the first trigger.
End
When focus is on a trigger, moves focus to the last trigger.
Arrow Right
In a horizontal accordion, moves focus to the next trigger.
Arrow Left
In a horizontal accordion, moves focus to the previous trigger.

Demos

Basic

Account questions, one open at a time, with the password item starting open. The rows come from a list, so another question is another entry rather than a fresh block of markup. Use this for a short FAQ where two answers on screen at once would be noise. If people compare sections, let more than one stay open.

Preview width

Multiple

Three groups of account settings, with notifications open from the start and privacy or billing free to open beside it. Allow several sections at once when people compare them or check related settings in one pass. In a single-open list, opening the next group folds away the one they were still reading.

Preview width

Disabled

Premium feature information, the middle of three account questions, has disabled on its AccordionItem, so its trigger does nothing while the questions about account history and email open as usual. Leave a disabled row when the heading should stay visible as a locked feature and the upgrade path lives elsewhere on the page. If the plan will never include it, omit the row.

Preview width

Borders

The root gets a border and a radius. Each item gets a bottom border and horizontal padding, and the last item drops its border so it does not double up with the outline. Use the bordered list when the accordion is the surface, sitting on a plain page. Skip the extra edges when a card already supplies them.

Preview width

Card

The questions sit in CardContent, under a title and a short description about subscription and billing. Plans starts open. Use the card when this FAQ is one block among others, on a pricing or billing screen, and it needs a heading that is not itself a trigger. A bare accordion is enough when the page heading already names the topic.

Preview width

RTL

The same account questions, in Arabic, with the first item open and the accordion inside a Direction provider set to right to left, which is where Ark UI reads the direction. Triggers, text, and the chevron follow the inline direction, so the icon is not stuck on the physical right. Use this when the page language is Arabic or Hebrew. Only the direction of the row changes.

Preview width

FAQ

How do I let only one accordion item open at a time in Vue?

That is how it behaves with no props: opening an item closes the one that was open, and pressing the open item again closes it too. Add multiple to Accordion when several should stay open together, as the Multiple demo does. Set collapsible to false to stop the open item from closing when it is pressed again.

How do I make an accordion item open by default?

List its value in defaultValue on Accordion, which takes an array even for one item: ["shipping"] opens the item whose value is shipping. Every item starts closed when you leave the prop out. To open several from the start, add multiple and list each one.

The Basic demo opens its first item this way.

How do I open or close accordion items from my own code?

Hold the open items in a ref and bind it with v-model, which reads and writes an array of the open items' values.

Once the state is yours, anything can change it. A link to one question can open that item by reading the hash from the URL, and where several may be open, an Expand all button lists every item at once.

Do form fields inside a closed accordion item still submit?

Not as it ships. A closed item's content is left out of the DOM, so its fields aren't part of the form. Set lazyMount and unmountOnExit to false on Accordion to render every section and hide the closed ones, and their fields submit.

A hidden field can't show the browser's own validation message, though. If a closed section holds a required field, validate it yourself and open that section when it fails.

Why can't Ctrl+F find text inside a closed accordion section?

The browser's find in page only searches what is rendered and visible, and a closed section's content isn't in the DOM. Ark UI has no option that changes this. On a long FAQ where people search for a word, start the sections open, or put a search field above the list that opens the items that match.

Is the Ark UI accordion accessible with the keyboard?

Yes. Every trigger is a button in the tab order, Enter and Space toggle its section, and the arrow keys, Home and End move between triggers without tabbing through the open content.

The Accessibility section lists each key. Keep links and buttons out of the trigger itself, because a button can't hold other controls.

How do I change the accordion's chevron icon?

Edit AccordionTrigger in components/ui/accordion, which is your code once installed. It renders two icons, ChevronDownIcon while the section is closed and ChevronUpIcon while it is open, and classes keyed on aria-expanded show one and hide the other.

Swap both imports for the pair you want, a plus and a minus for example. For a single icon that rotates, keep one of the two and turn it with a rotate class under the same aria-expanded variant.

When should I use an accordion instead of tabs or a collapsible?

Use an accordion when the sections are read one after another on the same page and most can stay closed: an FAQ, a filter sidebar, a long settings page. Headings stay visible, so people scan them and open what they need.

Tabs fit when there are few sections, their labels fit on one row and one must always show. A Collapsible is one section with its own trigger, with no group around it and nothing else closing when it opens.

API Reference

Accordion

<div> data-slot="accordion"

PropType
value?string[]

The controlled value of the expanded accordion items. Two-way with v-model.

defaultValue?string[]

The initial value of the expanded accordion items. Use when you don't need to control the value of the accordion.

collapsible?boolean

Whether an accordion item can be closed after it has been expanded. Ark default: false.

Default
true
dir?"ltr" | "rtl"

The document's text/writing direction.

Type
"ltr" | "rtl"
Default
"ltr"
disabled?boolean

Whether the accordion items are disabled.

hideMode?"display-none" | "activity"

How to hide content when mounted but not present. - display-none: HTML hidden attribute. Effects stay alive. - activity: React 19 <Activity mode="hidden">. Effects pause. Requires React 19+.

Type
"display-none" | "activity"
Default
"display-none"
id?string

The unique identifier of the machine.

ids?object

The ids of the elements in the accordion. Useful for composition.

Type
{ root?: string; item?: (value: string) → string; itemContent?: (value: string) → string; itemTrigger?: (value: string) → string }
lazyMount?boolean

Whether to enable lazy mounting. Ark default: false.

Default
true when `orientation` is not `"horizontal"`
multiple?boolean

Whether multiple accordion items can be expanded at the same time.

Default
false
orientation?"horizontal" | "vertical"

The orientation of the accordion items.

Type
"horizontal" | "vertical"
Default
"vertical"
unmountOnExit?boolean

Whether to unmount on exit. Ark default: false.

Default
true when `orientation` is not `"horizontal"`
asChild?boolean

Use the provided child element as the default rendered element, combining their props and behavior.

class?string

Merged with the part's classes.

EventType
@value-change(details: ValueChangeDetails) → void

The callback fired when the state of expanded/collapsed accordion items changes.

Type
(details: ValueChangeDetails) → void
Parameters

details – { value: string[] }

Returns
void
@focus-change(details: FocusChangeDetails) → void

The callback fired when the focused accordion item changes.

Type
(details: FocusChangeDetails) → void
Parameters

details – { value: string | null }

Returns
void
AttributeType
data-motion?string

Present after onValueChange.

data-orientation"horizontal" | "vertical"

The orientation of the accordion.

Type
"horizontal" | "vertical"

AccordionItem

<div> data-slot="accordion-item"

PropType
valuestring

The value of the accordion item.

disabled?boolean

Whether the accordion item is disabled.

asChild?boolean

Use the provided child element as the default rendered element, combining their props and behavior.

class?string

Merged with the part's classes.

AttributeType
data-disabled?string

Present when disabled.

data-focus?string

Present when focused.

data-orientation"horizontal" | "vertical"

The orientation of the item.

Type
"horizontal" | "vertical"
data-state"open" | "closed"

"open" or "closed".

Type
"open" | "closed"

AccordionTrigger

<button> data-slot="accordion-trigger"

PropType
asChild?boolean

Use the provided child element as the default rendered element, combining their props and behavior.

class?string

Merged with the part's classes.

AttributeType
data-controlsstring

Id of the itemContent part.

data-focus?string

Present when focused.

data-orientation"horizontal" | "vertical"

The orientation of the item.

Type
"horizontal" | "vertical"
data-ownedbystring

Id of the root part.

data-state"open" | "closed"

"open" or "closed".

Type
"open" | "closed"

AccordionContent

<div> data-slot="accordion-content"

PropType
asChild?boolean

Use the provided child element as the default rendered element, combining their props and behavior.

class?string

Merged with the part's classes.

AttributeType
data-disabled?string

Present when disabled.

data-focus?string

Present when focused.

data-orientation"horizontal" | "vertical"

The orientation of the item.

Type
"horizontal" | "vertical"
data-size-vars""
Default
""
data-state"open" | "closed"

"open" or "closed".

Type
"open" | "closed"
CSS variableType
--heightstring

The measured height, for animating open and closed.

--widthstring

The measured width, for animating open and closed.

AccordionRootProvider

<div> data-slot="accordion"

PropType
valueUseAccordionReturn

What useAccordion() returns: the state and API, made outside the component to control it.

hideMode?"display-none" | "activity"

How to hide content when mounted but not present. - display-none: HTML hidden attribute. Effects stay alive. - activity: React 19 <Activity mode="hidden">. Effects pause. Requires React 19+.

Type
"display-none" | "activity"
Default
"display-none"
lazyMount?boolean

Whether to enable lazy mounting.

Default
false
unmountOnExit?boolean

Whether to unmount on exit.

Default
false
asChild?boolean

Use the provided child element as the default rendered element, combining their props and behavior.

class?string

Merged with the part's classes.

AttributeType
data-orientation"horizontal" | "vertical"

Mirrors the orientation prop.

Type
"horizontal" | "vertical"

useAccordion

PropType
value?string[]

The controlled value of the expanded accordion items. Two-way with v-model.

defaultValue?string[]

The initial value of the expanded accordion items. Use when you don't need to control the value of the accordion.

collapsible?boolean

Whether an accordion item can be closed after it has been expanded.

Default
false
disabled?boolean

Whether the accordion items are disabled.

id?string

The unique identifier of the machine.

ids?object

The ids of the elements in the accordion. Useful for composition.

Type
{ root?: string; item?: (value: string) → string; itemContent?: (value: string) → string; itemTrigger?: (value: string) → string }
multiple?boolean

Whether multiple accordion items can be expanded at the same time.

Default
false
orientation?"horizontal" | "vertical"

The orientation of the accordion items.

Type
"horizontal" | "vertical"
Default
"vertical"
EventType
@value-change(details: ValueChangeDetails) → void

The callback fired when the state of expanded/collapsed accordion items changes.

Type
(details: ValueChangeDetails) → void
Parameters

details – { value: string[] }

Returns
void
@focus-change(details: FocusChangeDetails) → void

The callback fired when the focused accordion item changes.

Type
(details: FocusChangeDetails) → void
Parameters

details – { value: string | null }

Returns
void

AccordionContext

PropType
focusedValuestring | null

The value of the focused accordion item.

Type
string | null
getItemState(props: ItemProps) → ItemState

Returns the state of an accordion item.

Parameters

props – { value: string; disabled?: boolean }

Returns
ItemState
setValue(value: string[]) → void

Sets the value of the accordion.

Parameters

value – string[]

Returns
void
valuestring[]

The value of the accordion.

AccordionItemContext

PropType
disabledboolean

Whether the accordion item is disabled.

expandedboolean

Whether the accordion item is expanded.

focusedboolean

Whether the accordion item is focused.