Inside your body are 206 bones. Each bone plays a very important role in making all the mechanics of your body function properly. If a bone is broken, all the bones around it can’t perform their duty properly.
The stapes, a bone in your inner ear, is the smallest of all your bones. This bone is also sometimes called the stirrup because of its Y shape. Together with the anvil and hammer bones, the stapes helps translate sounds you hear into waves your brain can understand.
The hyoid bone, which is in your throat, is the only bone that doesn’t connect to a joint. The hyoid is responsible for holding your tongue in place.
<script lang="ts">
import { Accordion } from '@skeletonlabs/skeleton-svelte';
// Attribution: https://www.healthline.com/health/fun-facts-about-the-skeletal-system#8-More-than-half-your-bones-are-in-your-hands-and-feet
const content = [
{
id: '001',
title: 'Your skeleton is made of more than 200 bones',
description:
'Inside your body are 206 bones. Each bone plays a very important role in making all the mechanics of your body function properly. If a bone is broken, all the bones around it can’t perform their duty properly.',
},
{
id: '002',
title: 'The smallest bone in the body is in your ear',
description:
'The stapes, a bone in your inner ear, is the smallest of all your bones. This bone is also sometimes called the stirrup because of its Y shape. Together with the anvil and hammer bones, the stapes helps translate sounds you hear into waves your brain can understand.',
},
{
id: '003',
title: 'One bone isn’t connected to any other bones',
description:
'The hyoid bone, which is in your throat, is the only bone that doesn’t connect to a joint. The hyoid is responsible for holding your tongue in place.',
},
];
</script>
<Accordion>
{#each content as item (item)}
<Accordion.Item value={item.id}>
<h3>
<Accordion.ItemTrigger class="font-bold">{item.title}</Accordion.ItemTrigger>
</h3>
<Accordion.ItemContent>{item.description}</Accordion.ItemContent>
</Accordion.Item>
{/each}
</Accordion>
Inside your body are 206 bones. Each bone plays a very important role in making all the mechanics of your body function properly. If a bone is broken, all the bones around it can’t perform their duty properly.
The stapes, a bone in your inner ear, is the smallest of all your bones. This bone is also sometimes called the stirrup because of its Y shape. Together with the anvil and hammer bones, the stapes helps translate sounds you hear into waves your brain can understand.
The hyoid bone, which is in your throat, is the only bone that doesn’t connect to a joint. The hyoid is responsible for holding your tongue in place.
import { Accordion } from '@skeletonlabs/skeleton-react';
export default function Default() {
// Attribution: https://www.healthline.com/health/fun-facts-about-the-skeletal-system#8-More-than-half-your-bones-are-in-your-hands-and-feet
const content = [
{
id: '001',
title: 'Your skeleton is made of more than 200 bones',
description:
'Inside your body are 206 bones. Each bone plays a very important role in making all the mechanics of your body function properly. If a bone is broken, all the bones around it can’t perform their duty properly.',
},
{
id: '002',
title: 'The smallest bone in the body is in your ear',
description:
'The stapes, a bone in your inner ear, is the smallest of all your bones. This bone is also sometimes called the stirrup because of its Y shape. Together with the anvil and hammer bones, the stapes helps translate sounds you hear into waves your brain can understand.',
},
{
id: '003',
title: 'One bone isn’t connected to any other bones',
description:
'The hyoid bone, which is in your throat, is the only bone that doesn’t connect to a joint. The hyoid is responsible for holding your tongue in place.',
},
];
return (
<Accordion>
{content.map((item) => (
<Accordion.Item key={item.id} value={item.id}>
<h3>
<Accordion.ItemTrigger className="font-bold">{item.title}</Accordion.ItemTrigger>
</h3>
<Accordion.ItemContent>{item.description}</Accordion.ItemContent>
</Accordion.Item>
))}
</Accordion>
);
}
Controlled
Use the open and onOpenChange props to control the state.
Content for item 1
Content for item 2
Content for item 3
<script lang="ts">
import { Accordion } from '@skeletonlabs/skeleton-svelte';
let value = $state(['1']);
</script>
<Accordion {value} onValueChange={(details) => (value = details.value)}>
{#each ['1', '2', '3'] as item (item)}
<Accordion.Item value={item}>
<h3>
<Accordion.ItemTrigger>Item {item}</Accordion.ItemTrigger>
</h3>
<Accordion.ItemContent>Content for item {item}</Accordion.ItemContent>
</Accordion.Item>
{/each}
</Accordion>
Content for item 1
Content for item 2
Content for item 3
import { Accordion } from '@skeletonlabs/skeleton-react';
import { useState } from 'react';
export default function Controlled() {
const [value, setValue] = useState(['1']);
return (
<Accordion value={value} onValueChange={(details) => setValue(details.value)}>
{['1', '2', '3'].map((item) => (
<Accordion.Item key={item} value={item}>
<h3>
<Accordion.ItemTrigger>Item {item}</Accordion.ItemTrigger>
</h3>
<Accordion.ItemContent>Content for item {item}</Accordion.ItemContent>
</Accordion.Item>
))}
</Accordion>
);
}
Multiple
Allow multiple accordion items to stay open at once using the multiple prop.
Content for item 1
Content for item 2
Content for item 3
<script lang="ts">
import { Accordion } from '@skeletonlabs/skeleton-svelte';
</script>
<Accordion multiple>
{#each ['1', '2', '3'] as item (item)}
<Accordion.Item value={item}>
<h3>
<Accordion.ItemTrigger>Item {item}</Accordion.ItemTrigger>
</h3>
<Accordion.ItemContent>Content for item {item}</Accordion.ItemContent>
</Accordion.Item>
{/each}
</Accordion>
Content for item 1
Content for item 2
Content for item 3
import { Accordion } from '@skeletonlabs/skeleton-react';
export default function Multiple() {
return (
<Accordion multiple>
{['1', '2', '3'].map((item) => (
<Accordion.Item key={item} value={item}>
<h3>
<Accordion.ItemTrigger>Item {item}</Accordion.ItemTrigger>
</h3>
<Accordion.ItemContent>Content for item {item}</Accordion.ItemContent>
</Accordion.Item>
))}
</Accordion>
);
}
Collapsible
Allow closing all items when one is open using the collapsible prop.
Content for item 1
Content for item 2
Content for item 3
<script lang="ts">
import { Accordion } from '@skeletonlabs/skeleton-svelte';
</script>
<Accordion collapsible>
{#each ['1', '2', '3'] as item (item)}
<Accordion.Item value={item}>
<h3>
<Accordion.ItemTrigger>Item {item}</Accordion.ItemTrigger>
</h3>
<Accordion.ItemContent>Content for item {item}</Accordion.ItemContent>
</Accordion.Item>
{/each}
</Accordion>
Content for item 1
Content for item 2
Content for item 3
import { Accordion } from '@skeletonlabs/skeleton-react';
export default function Collapsible() {
return (
<Accordion collapsible>
{['1', '2', '3'].map((item) => (
<Accordion.Item key={item} value={item}>
<h3>
<Accordion.ItemTrigger>Item {item}</Accordion.ItemTrigger>
</h3>
<Accordion.ItemContent>Content for item {item}</Accordion.ItemContent>
</Accordion.Item>
))}
</Accordion>
);
}
Indicator
Add a custom indicator to accordion triggers.
Content for item 1
Content for item 2
Content for item 3
<script lang="ts">
import { PlusIcon, MinusIcon } from '@lucide/svelte';
import { Accordion } from '@skeletonlabs/skeleton-svelte';
</script>
<Accordion>
{#each ['1', '2', '3'] as item (item)}
<Accordion.Item value={item}>
<h3>
<Accordion.ItemTrigger class="flex justify-between items-center">
Item {item}
<Accordion.ItemIndicator class="group">
<MinusIcon class="size-4 group-data-[state=open]:block hidden" />
<PlusIcon class="size-4 group-data-[state=open]:hidden block" />
</Accordion.ItemIndicator>
</Accordion.ItemTrigger>
</h3>
<Accordion.ItemContent>Content for item {item}</Accordion.ItemContent>
</Accordion.Item>
{/each}
</Accordion>
Content for item 1
Content for item 2
Content for item 3
import { Accordion } from '@skeletonlabs/skeleton-react';
import { MinusIcon, PlusIcon } from 'lucide-react';
export default function Indicator() {
return (
<Accordion>
{['1', '2', '3'].map((item) => (
<Accordion.Item key={item} value={item}>
<h3>
<Accordion.ItemTrigger className="flex justify-between items-center">
Item {item}
<Accordion.ItemIndicator className="group">
<MinusIcon className="size-4 group-data-[state=open]:block hidden" />
<PlusIcon className="size-4 group-data-[state=open]:hidden block" />
</Accordion.ItemIndicator>
</Accordion.ItemTrigger>
</h3>
<Accordion.ItemContent>Content for item {item}</Accordion.ItemContent>
</Accordion.Item>
))}
</Accordion>
);
}
Orientation
Render the accordion vertically or horizontally using the orientation prop.
Content for item 1
Content for item 2
Content for item 3
<script lang="ts">
import { Accordion } from '@skeletonlabs/skeleton-svelte';
</script>
<Accordion orientation="horizontal">
{#each ['1', '2', '3'] as item (item)}
<Accordion.Item value={item} class="data-[state=open]:flex-1">
<h3>
<Accordion.ItemTrigger>Item {item}</Accordion.ItemTrigger>
</h3>
<Accordion.ItemContent>Content for item {item}</Accordion.ItemContent>
</Accordion.Item>
{/each}
</Accordion>
Content for item 1
Content for item 2
Content for item 3
import { Accordion } from '@skeletonlabs/skeleton-react';
export default function Orientation() {
return (
<Accordion orientation="horizontal">
{['1', '2', '3'].map((item) => (
<Accordion.Item key={item} value={item} className="data-[state=open]:flex-1">
<h3>
<Accordion.ItemTrigger>Item {item}</Accordion.ItemTrigger>
</h3>
<Accordion.ItemContent>Content for item {item}</Accordion.ItemContent>
</Accordion.Item>
))}
</Accordion>
);
}
Dir
Set the text direction (ltr or rtl) using the dir prop.
Content for item 1
Content for item 2
Content for item 3
<script lang="ts">
import { Accordion } from '@skeletonlabs/skeleton-svelte';
</script>
<Accordion dir="rtl">
{#each ['1', '2', '3'] as item (item)}
<Accordion.Item value={item}>
<h3>
<Accordion.ItemTrigger>Item {item}</Accordion.ItemTrigger>
</h3>
<Accordion.ItemContent>Content for item {item}</Accordion.ItemContent>
</Accordion.Item>
{/each}
</Accordion>
Content for item 1
Content for item 2
Content for item 3
import { Accordion } from '@skeletonlabs/skeleton-react';
export default function Dir() {
return (
<Accordion dir="rtl">
{['1', '2', '3'].map((item) => (
<Accordion.Item key={item} value={item}>
<h3>
<Accordion.ItemTrigger>Item {item}</Accordion.ItemTrigger>
</h3>
<Accordion.ItemContent>Content for item {item}</Accordion.ItemContent>
</Accordion.Item>
))}
</Accordion>
);
}
API Reference
Root
| Property | Default | Type |
|---|---|---|
ids | - | Partial<{ root: string; item: (value: string) => string; itemContent: (value: string) => string; itemTrigger: (value: string) => string; }> | undefined The ids of the elements in the accordion. Useful for composition. |
multiple | false | boolean | undefinedWhether multiple accordion items can be expanded at the same time. |
collapsible | false | boolean | undefinedWhether an accordion item can be closed after it has been expanded. |
value | - | string[] | undefinedThe controlled value of the expanded accordion items. |
defaultValue | - | string[] | undefinedThe initial value of the expanded accordion items. Use when you don't need to control the value of the accordion. |
disabled | - | boolean | undefinedWhether the accordion items are disabled |
onValueChange | - | ((details: ValueChangeDetails) => void) | undefinedThe callback fired when the state of expanded/collapsed accordion items changes. |
onFocusChange | - | ((details: FocusChangeDetails) => void) | undefinedThe callback fired when the focused accordion item changes. |
orientation | "vertical" | "horizontal" | "vertical" | undefinedThe orientation of the accordion items. |
dir | "ltr" | "ltr" | "rtl" | undefinedThe document's text/writing direction. |
getRootNode | - | (() => ShadowRoot | Node | Document) | undefinedA root node to correctly resolve document in custom environments. E.x.: Iframes, Electron. |
element | - | ((attributes: HTMLAttributes<"div">) => Element) | undefinedRender the element yourself |
RootProvider
| Property | Default | Type |
|---|---|---|
value | - | AccordionApi<PropTypes> |
element | - | ((attributes: HTMLAttributes<"div">) => Element) | undefinedRender the element yourself |
RootContext
| Property | Default | Type |
|---|---|---|
children | - | (accordion: AccordionApi<PropTypes>) => ReactNode |
Item
| Property | Default | Type |
|---|---|---|
value | - | stringThe value of the accordion item. |
disabled | - | boolean | undefinedWhether the accordion item is disabled. |
children | - | ReactNode |
element | - | ((attributes: HTMLAttributes<"div">) => Element) | undefinedRender the element yourself |
ItemTrigger
| Property | Default | Type |
|---|---|---|
children | - | ReactNode |
element | - | ((attributes: HTMLAttributes<"button">) => Element) | undefinedRender the element yourself |
ItemIndicator
| Property | Default | Type |
|---|---|---|
children | - | ReactNode |
element | - | ((attributes: HTMLAttributes<"div">) => Element) | undefinedRender the element yourself |
ItemContent
| Property | Default | Type |
|---|---|---|
children | - | ReactNode |
element | - | ((attributes: HTMLAttributes<"div">) => Element) | undefinedRender the element yourself |