Skip to content
Haze UI

Accordion

List of expandable items built from an array, in three variants, with a chevron or plus icon and optional single-open behavior.

pnpm dlx shadcn@latest add @haze/accordion
Open preview in a new tab
Liveno JavaScript

When to use

  • A short list of questions and answers or settings groups, written as plain text
  • Keeping a long help page scannable with one open item at a time
  • Content that comes from data rather than from hand-written markup

When not to use

  • Items need rich content such as links or images; stack collapsible components instead
  • A full-width FAQ section; use the faq blocks

Installation

Add the Haze registry to components.json once, then install Accordion with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.

pnpm dlx shadcn@latest add @haze/accordion
First time? Registry and theme setup

1. Add to components.json:

{
  "registries": {
    "@haze": "http://localhost:4329/r/{name}.json"
  }
}

2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";

API reference

PropTypeDefaultDescription
items*{ title: string; content: string; open?: boolean }[]–One entry per row; content renders as one paragraph.
namestring–Shared details name; when set, opening one item closes the others.
variant"contained" | "plain" | "separated""contained"contained: one bordered panel with dividers. plain: hairlines only, for long FAQ lists. separated: each item is its own panel.
icon"chevron" | "plus""chevron"chevron turns over when the item opens. plus turns into a cross.
classstring–Extra classes on the outer element.

Keyboard interactions

EnterSpace
Open or close the focused item
Tab
Move to the next item's summary

Accessibility

  • Each row is a native details element, so the summary is announced as an expandable button without extra ARIA.
  • In the contained and plain variants rows are separated by hairline dividers, so the group reads as a single list; in separated each row is its own panel.
  • The panel animates its height over 300 ms where the browser supports interpolate-size; elsewhere its content rises in. Both are switched off under prefers-reduced-motion.
  • With a name set, the browser closes the previous item itself and no script runs.

Notes for AI

Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.

  • Install and use

    Install the Haze UI component "Accordion" with `npx shadcn@latest add @haze/accordion`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import Accordion from "@/components/haze/ui/accordion.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/accordion.md

  • Customize with real content

    Adapt the Haze accordion ui for our product. Replace the demo values of these props with our real content: items, name, variant, icon, class. Keep the layout, the heading level rules and these accessibility details: Each row is a native details element, so the summary is announced as an expandable button without extra ARIA. In the contained and plain variants rows are separated by hairline dividers, so the group reads as a single list; in separated each row is its own panel. The panel animates its height over 300 ms where the browser supports interpolate-size; elsewhere its content rises in. Both are switched off under prefers-reduced-motion. With a name set, the browser closes the previous item itself and no script runs. Do not add raw color classes; use the Haze tokens.

  • Choose the right block

    Before using accordion, check it fits: use it when a short list of questions and answers or settings groups, written as plain text; keeping a long help page scannable with one open item at a time; content that comes from data rather than from hand-written markup. Avoid it when items need rich content such as links or images; stack collapsible components instead; a full-width faq section; use the faq blocks. Alternatives: @haze/collapsible, @haze/tabs.

Dependencies

  • npm: @lucide/astro
  • @haze/utils
  • @haze/theme (one-time setup)

Source · Original Haze UI work.

Catalog

↑↓ moveEnter openEsc close

Keyboard shortcuts

CtrlK
Command palette
/
Focus search
←↑→↓
Move between cards
jk
Next / previous card
ci
Copy code / install command (detail page)
[]
Previous / next entry
?
This help
Esc
Close dialog