Accordion
A stack of sections that open and close, like an FAQ. Same markup and props in every style: switch the style in the header to see it change.
One at a time
Opening a section closes the others. In HTML, give every <details> the same name; no JavaScript needed.
Is VinUI free?
Do I need React?
Can I change the colours?
<div class="vin-accordion" style="max-width: 480px">
<details class="vin-accordion__item" name="faq" open>
<summary class="vin-accordion__trigger">Is VinUI free?</summary>
<div class="vin-accordion__content">Yes. Every component is MIT licensed, so you can use it in personal and commercial work.</div>
</details>
<details class="vin-accordion__item" name="faq">
<summary class="vin-accordion__trigger">Do I need React?</summary>
<div class="vin-accordion__content">No. Each component comes as plain HTML and CSS too, with one small script for the interactive parts.</div>
</details>
<details class="vin-accordion__item" name="faq">
<summary class="vin-accordion__trigger">Can I change the colours?</summary>
<div class="vin-accordion__content">Pick any accent colour, light or dark mode, and one of eight styles.</div>
</details>
</div>Is VinUI free?
Do I need React?
Can I change the colours?
import { Accordion } from "@/components/vin/accordion";
const faq = [
{ value: "free", title: "Is VinUI free?", content: "Yes. Every component is MIT licensed, so you can use it in personal and commercial work." },
{ value: "react", title: "Do I need React?", content: "No. Each component comes as plain HTML and CSS too, with one small script for the interactive parts." },
{ value: "colours", title: "Can I change the colours?", content: "Pick any accent colour, light or dark mode, and one of eight styles." },
];
export function AccordionBasic() {
return <Accordion items={faq} defaultValue={["free"]} style={{ maxWidth: 480 }} />;
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Accordion from "@/components/vin/accordion.vue";
const faq = [
{ value: "free", title: "Is VinUI free?", content: "Yes. Every component is MIT licensed, so you can use it in personal and commercial work." },
{ value: "react", title: "Do I need React?", content: "No. Each component comes as plain HTML and CSS too, with one small script for the interactive parts." },
{ value: "colours", title: "Can I change the colours?", content: "Pick any accent colour, light or dark mode, and one of eight styles." },
];
</script>
<template>
<Accordion :items="faq" :default-value="['free']" style="max-width: 480px" />
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Accordion from "$lib/components/vin/accordion.svelte";
const faq = [
{ value: "free", title: "Is VinUI free?", content: "Yes. Every component is MIT licensed, so you can use it in personal and commercial work." },
{ value: "svelte", title: "Do I need Svelte?", content: "No. Each component comes as plain HTML and CSS too, with one small script for the interactive parts." },
{ value: "colours", title: "Can I change the colours?", content: "Pick any accent colour, light or dark mode, and one of eight styles." },
];
</script>
<Accordion items={faq} value={["free"]} style="max-width: 480px" />Many at a time
Leave out the name and each section opens on its own.
Shipping
Returns
Warranty
<div class="vin-accordion" style="max-width: 480px">
<details class="vin-accordion__item" open>
<summary class="vin-accordion__trigger">Shipping</summary>
<div class="vin-accordion__content">Orders leave our warehouse within two working days.</div>
</details>
<details class="vin-accordion__item" open>
<summary class="vin-accordion__trigger">Returns</summary>
<div class="vin-accordion__content">Send it back within 30 days for a full refund.</div>
</details>
<details class="vin-accordion__item">
<summary class="vin-accordion__trigger">Warranty</summary>
<div class="vin-accordion__content">Two years on every product, parts and labour.</div>
</details>
</div>Shipping
Returns
Warranty
import { Accordion } from "@/components/vin/accordion";
const items = [
{ value: "shipping", title: "Shipping", content: "Orders leave our warehouse within two working days." },
{ value: "returns", title: "Returns", content: "Send it back within 30 days for a full refund." },
{ value: "warranty", title: "Warranty", content: "Two years on every product, parts and labour." },
];
export function AccordionMultiple() {
return <Accordion type="multiple" items={items} defaultValue={["shipping", "returns"]} style={{ maxWidth: 480 }} />;
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Accordion from "@/components/vin/accordion.vue";
const items = [
{ value: "shipping", title: "Shipping", content: "Orders leave our warehouse within two working days." },
{ value: "returns", title: "Returns", content: "Send it back within 30 days for a full refund." },
{ value: "warranty", title: "Warranty", content: "Two years on every product, parts and labour." },
];
</script>
<template>
<Accordion type="multiple" :items="items" :default-value="['shipping', 'returns']" style="max-width: 480px" />
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Accordion from "$lib/components/vin/accordion.svelte";
const items = [
{ value: "shipping", title: "Shipping", content: "Orders leave our warehouse within two working days." },
{ value: "returns", title: "Returns", content: "Send it back within 30 days for a full refund." },
{ value: "warranty", title: "Warranty", content: "Two years on every product, parts and labour." },
];
</script>
<Accordion type="multiple" {items} value={["shipping", "returns"]} style="max-width: 480px" />Outline
Each section in its own frame.
Free
Team
Enterprise
<div class="vin-accordion vin-accordion--outline" style="max-width: 480px">
<details class="vin-accordion__item" name="plan" open>
<summary class="vin-accordion__trigger">Free</summary>
<div class="vin-accordion__content">All components, all styles, for one project.</div>
</details>
<details class="vin-accordion__item" name="plan">
<summary class="vin-accordion__trigger">Team</summary>
<div class="vin-accordion__content">Shared themes and up to 10 people.</div>
</details>
<details class="vin-accordion__item" name="plan">
<summary class="vin-accordion__trigger">Enterprise</summary>
<div class="vin-accordion__content">Single sign-on and priority support.</div>
</details>
</div>Free
Team
Enterprise
import { Accordion } from "@/components/vin/accordion";
const plans = [
{ value: "free", title: "Free", content: "All components, all styles, for one project." },
{ value: "team", title: "Team", content: "Shared themes and up to 10 people." },
{ value: "enterprise", title: "Enterprise", content: "Single sign-on and priority support." },
];
export function AccordionOutline() {
return <Accordion variant="outline" items={plans} defaultValue={["free"]} style={{ maxWidth: 480 }} />;
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Accordion from "@/components/vin/accordion.vue";
const plans = [
{ value: "free", title: "Free", content: "All components, all styles, for one project." },
{ value: "team", title: "Team", content: "Shared themes and up to 10 people." },
{ value: "enterprise", title: "Enterprise", content: "Single sign-on and priority support." },
];
</script>
<template>
<Accordion variant="outline" :items="plans" :default-value="['free']" style="max-width: 480px" />
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Accordion from "$lib/components/vin/accordion.svelte";
const plans = [
{ value: "free", title: "Free", content: "All components, all styles, for one project." },
{ value: "team", title: "Team", content: "Shared themes and up to 10 people." },
{ value: "enterprise", title: "Enterprise", content: "Single sign-on and priority support." },
];
</script>
<Accordion variant="outline" items={plans} value={["free"]} style="max-width: 480px" />Installation
React, Vue and Svelte: add the component to your project with the CLI. It reads your framework from vin.json and also copies any component this one needs. Then import it:
npx @vinish/ui add accordionimport { Accordion } from "@/components/vin/accordion";import Accordion from "@/components/vin/accordion.vue";import Accordion from "$lib/components/vin/accordion.svelte";The import paths assume the default folders: @/components/vin (React and Vue, with the usual @ → src alias) and $lib/components/vin (SvelteKit). Use your own if you chose another folder in init. How the Vue and Svelte versions pass values and content is in Frameworks.
Plain HTML: the classes come with the style's stylesheet. It needs no JavaScript.
API
From spec/accordion.json, which every framework version is tested against.
| Prop | Values | Default | In HTML |
|---|---|---|---|
typeOne section open at a time, or any number. | singlemultiple | single | single: the same name="…" on every <details> |
items | { value, title, content }[] | — | details.vin-accordion__item > summary.vin-accordion__trigger + .vin-accordion__content |
defaultValue / valueWhich sections are open. Use onValueChange to hear about changes. | string | string[] | — | open attribute |
variant | defaultoutline | default | vin-accordion--outline |
Parts
| React, Vue, Svelte | HTML classes |
|---|---|
<Accordion> | .vin-accordion.vin-accordion--outline.vin-accordion__item.vin-accordion__trigger.vin-accordion__content |
Accessibility
- Built on <details> and <summary>: the browser makes each header a button that says "expanded" or "collapsed", and Enter or Space toggles it.
- Find-in-page (Ctrl+F) opens a closed section when it finds text inside.
- The chevron is decoration drawn by CSS.
- With reduced motion, sections open without the slide.
Customize
Saved in this browser. Style and accent are in the header.