Accordion

updated

Customers 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.

Demo

Orders ship within two working days and arrive three to five days later.

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.

Multiple

Email for mentions and replies, push for direct messages.

Your profile is visible to members of your workspaces only.

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.

Find in page

Press Ctrl+F (⌘F on a Mac) and search for “invoice”.

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.

Unmount on hide

API Reference

Every part takes a class. On AccordionContent, it styles the padded block inside.

Data attributes

data-slotAttributesDescription
accordion—The root.
accordion-itemdata-state, data-disabled, data-orientationOne item.
accordion-headerdata-state, data-disabled, data-orientationThe heading that holds the trigger.
accordion-triggerdata-state, data-disabled, data-orientationThe button that opens and closes the item.
accordion-contentdata-state, data-disabled, data-orientationThe 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.

KeyAction
TabMoves focus to the next trigger.
SpaceOpens or closes the focused item.
EnterOpens or closes the focused item.
ArrowDownMoves focus to the next trigger, wrapping at the end.
ArrowUpMoves focus to the previous trigger, wrapping at the start.
HomeMoves focus to the first trigger.
EndMoves focus to the last trigger.

Changelog

  1. registry 0.23.0

    bc6008b — Exits now use the decelerating curve, like entrances. Collapsible, Accordion, the overlay surfaces (Popover, Select, Menu, Tooltip), Drawer, Toast and InnerLoading used to close on --ease-emphasized-accelerate, which holds still for most of its duration and then snaps shut; closing on --ease-standard-decelerate starts at once and settles gently, so the same duration feels faster. The tokens themselves are unchanged.

  2. core 0.17.0

    bc6008b — Exits now use the decelerating curve, like entrances. Collapsible, Accordion, the overlay surfaces (Popover, Select, Menu, Tooltip), Drawer, Toast and InnerLoading used to close on --ease-emphasized-accelerate, which holds still for most of its duration and then snaps shut; closing on --ease-standard-decelerate starts at once and settles gently, so the same duration feels faster. The tokens themselves are unchanged.

  3. registry 0.22.0

    265cef5 — An open AccordionTrigger turns only its chevron (the last icon), not an icon placed before the question, and the chevron stops animating its turn under reduced motion.

    b827f85 — An open AccordionContent no longer clips its content: the accordion keyframes clip while the panel's height animates, as Collapsible's do, and the part drops its permanent overflow-hidden, so a focus ring or a shadow inside an open answer shows in full.

    7dffb11 — CollapsibleContent puts its class on a new div inside the animated panel, as AccordionContent does, so padding, a border or a display class no longer keep a closed panel visible: Chromium left an empty strip, and Safari, which has no hidden="until-found", showed closed content styled with a display class. The DOM gains that inner div; a selector or style that targeted the panel element through your class now finds it one level down.

  4. core 0.16.0

    b827f85 — An open AccordionContent no longer clips its content: the accordion keyframes clip while the panel's height animates, as Collapsible's do, and the part drops its permanent overflow-hidden, so a focus ring or a shadow inside an open answer shows in full.