Accordion

Free

Default, flush, separated and filled styles, single- or multi-expand, icon placements, badges & subtitles and disabled items. Sizes (sm / md / lg), multi-expand, CSS-grid animation and keyboard navigation are free; the separated card style is in the Pro package.

</>sv-accordion accordiondisclosurenavigation
import { SvAccordionComponent } from '@styloviz/accordion';

Demo & usage

Basic usage

Usage example — open the gallery for the full interactive demo.

An interactive demo for this component lives in the gallery.

Open live demo

More examples

Sizes — sm / md / lg

example.htmlAngular
<sv-accordion [items]="items" size="sm" />
<sv-accordion [items]="items" size="md" />
<sv-accordion [items]="items" size="lg" />

Multi-expand, separated (Pro)

example.htmlAngular
<sv-accordion-pro [items]="items" expandMode="multi" variant="separated" iconPosition="right" (itemToggled)="onToggle($event)" />

Filterable FAQ — a search field bound to searchQuery

example.htmlAngular
<label for="faq-search">Search the FAQ</label>
<input id="faq-search" type="search" [value]="query()" (input)="query.set($any($event.target).value)" />

<!-- Matching sections open and the hits are marked; clearing the query restores
     what the reader had open. faq.matchedIds() gives the count for a summary. -->
<sv-accordion #faq [items]="items" [searchQuery]="query()" />

Expand all / collapse all and print

example.htmlAngular
<button type="button" (click)="faq.expandAll()">Expand all</button>
<button type="button" (click)="faq.collapseAll()">Collapse all</button>

<!-- expandAll() needs expandMode="multi". Printing reveals every enabled panel
     and restores the reader's open set afterwards; [expandOnPrint]="false" keeps
     collapsed panels off paper (a quiz answer). -->
<sv-accordion #faq [items]="items" expandMode="multi" [expandOnPrint]="true" />

When to use

  • Job: disclosure — owns visibility of its panels in place and never navigates, so back should do nothing (compare all seven in the “Choosing a navigation pattern” guide under Guides).
  • Condensing long content into expandable sections (FAQs, settings, details).
  • You want to reduce scroll length while keeping everything reachable.
  • For switching between mutually exclusive views, use Tabs.

Compare with

  • Expand / Collapse — Expand is the single animated height container with no header, group or keyboard model. Reach for it when one region opens and closes on its own.

Async states

None — this component has nothing to load, so it has no loading, empty or error state to drive.

Item identity & owned state

Restorable state
  • openIds

Bind these to put a saved view back — the open sections, the hidden columns, the selected rows — and read their Change events to store what the user does.

Inputs

NameTypeDefaultDescription
itemsAccordionItem[][]Array of panel definitions.
variantAccordionVariant'default'Visual style.
expandModeAccordionExpand'single'Whether one or many panels can be open at once.
sizeAccordionSize'md'Padding / font scale.
iconPositionAccordionIconPos'right'Which side the chevron appears on.
customIconstring''Icon-library NAME used as the expand/collapse indicator instead of the default chevron (e.g. `'plus'`). Leave empty to use the built-in chevron. When only this is set the glyph rotates 180° on open (good for arrows). Was `customIconPath`, which took a raw `<path d="…">`.
customIconOpenstring''Optional alternate icon-library NAME shown when the panel is **open**. Set this alongside `customIcon` for a true swap (e.g. plus → minus). When set, rotation is disabled — the glyphs switch instead. Was `customIconOpenPath`.
customClassstring''Extra CSS classes applied to the root wrapper.
headingLevelnumber3Heading level of the element wrapped around each panel header — `1`–`6`, so the panels sit correctly in the page outline and can be reached by heading navigation. A value outside `1`–`6` is clamped, with one dev warning.
findInPagebooleantrueLet browser find-in-page (`Ctrl+F`) reach the text inside COLLAPSED panels, by marking them `hidden="until-found"` where the browser supports it. The browser expands the panel it matched and the open state follows. Turn it off for content that is meant to stay hidden until asked for — a quiz answer, a spoiler. Disabled panels are never findable.
expandOnPrintbooleantrueExpand every enabled panel while the page is printed, and restore the reader's own open set afterwards. Turn it off for content that must stay hidden on paper (a quiz answer).
searchQuerystring''Reveal and highlight the panels whose title, subtitle or body contains this text. The reveal is transient: clearing the query returns every panel to the state the user left it in, and nothing is written to `openIds` or to the URL. Matching is case-insensitive substring.
urlKeystring | nullnullPut the open sections in the URL under this key, so one answer can be linked to and survives a refresh. Needs `provideSvNavLocation()` at the app root; multiple open sections are comma-separated.
openIdsSet<string> (two-way)new Set()Ids of the currently-open panels (two-way). A `model`, so the open set can be restored as well as observed: `itemToggled` reports one gesture at a time, and `defaultOpen` only ever affects panels this accordion has not seen — so binding this is how a host reopens the sections a user had left open before a route change. A bound value wins over `defaultOpen`. `defaultOpen` is applied to each new `items` array, so sections that arrive from a request can open on arrival — but only to ids this component has not seen before, which is what "default" means: a host that rebuilds its `items` on every change detection cannot reopen a section the user closed, and ids that have gone away are dropped.

Outputs

EventPayload typeDescription
itemToggledAccordionToggleEventFires whenever a panel is opened or closed. `source` says what did it — `'user'` for a click or key, `'find-in-page'` when the browser revealed the panel itself. A transient reveal (a search query, `reveal()`) does not fire.
unresolvedSvUnresolvedValue<readonly string[]>Emitted when the open set named sections this accordion cannot show. Carries the set as bound, the set after pruning, and whether `openIds` was written back.
openIdsChangeSet<string>Emits the new `openIds` whenever it changes — the output half of `[(openIds)]`.

<sv-accordion-pro>

Also in this family — SvAccordionProComponent from @styloviz-pro/accordion.

Async states

None — this component has nothing to load, so it has no loading, empty or error state to drive.

Item identity & owned state

Restorable state
  • openIds

Bind these to put a saved view back — the open sections, the hidden columns, the selected rows — and read their Change events to store what the user does.

Inputs

NameTypeDefaultDescription
itemsAccordionItem[][]Array of panel definitions.
variantAccordionVariant'default'Visual style.
expandModeAccordionExpand'single'Whether one or many panels can be open at once.
sizeAccordionSize'md'Padding / font scale.
iconPositionAccordionIconPos'right'Which side the chevron appears on.
customIconstring''Icon-library NAME used as the expand/collapse indicator instead of the default chevron (e.g. `'plus'`). Leave empty to use the built-in chevron. When only this is set the glyph rotates 180° on open (good for arrows). Was `customIconPath`, which took a raw `<path d="…">`.
customIconOpenstring''Optional alternate icon-library NAME shown when the panel is **open**. Set this alongside `customIcon` for a true swap (e.g. plus → minus). When set, rotation is disabled — the glyphs switch instead. Was `customIconOpenPath`.
customClassstring''Extra CSS classes applied to the root wrapper.
headingLevelnumber3Heading level of the element wrapped around each panel header — `1`–`6`, so the panels sit correctly in the page outline and can be reached by heading navigation. A value outside `1`–`6` is clamped, with one dev warning.
findInPagebooleantrueLet browser find-in-page (`Ctrl+F`) reach the text inside COLLAPSED panels, by marking them `hidden="until-found"` where the browser supports it. The browser expands the panel it matched and the open state follows. Turn it off for content that is meant to stay hidden until asked for — a quiz answer, a spoiler. Disabled panels are never findable.
expandOnPrintbooleantrueExpand every enabled panel while the page is printed, and restore the reader's own open set afterwards. Turn it off for content that must stay hidden on paper (a quiz answer).
searchQuerystring''Reveal and highlight the panels whose title, subtitle or body contains this text. The reveal is transient: clearing the query returns every panel to the state the user left it in, and nothing is written to `openIds` or to the URL. Matching is case-insensitive substring.
urlKeystring | nullnullPut the open sections in the URL under this key, so one answer can be linked to and survives a refresh. Needs `provideSvNavLocation()` at the app root; multiple open sections are comma-separated.
openIdsSet<string> (two-way)new Set()Ids of the currently-open panels (two-way). A `model`, so the open set can be restored as well as observed: `itemToggled` reports one gesture at a time, and `defaultOpen` only ever affects panels this accordion has not seen — so binding this is how a host reopens the sections a user had left open before a route change. A bound value wins over `defaultOpen`. `defaultOpen` is applied to each new `items` array, so sections that arrive from a request can open on arrival — but only to ids this component has not seen before, which is what "default" means: a host that rebuilds its `items` on every change detection cannot reopen a section the user closed, and ids that have gone away are dropped.

Outputs

EventPayload typeDescription
itemToggledAccordionToggleEventFires whenever a panel is opened or closed. `source` says what did it — `'user'` for a click or key, `'find-in-page'` when the browser revealed the panel itself. A transient reveal (a search query, `reveal()`) does not fire.
unresolvedSvUnresolvedValue<readonly string[]>Emitted when the open set named sections this accordion cannot show. Carries the set as bound, the set after pruning, and whether `openIds` was written back.
openIdsChangeSet<string>Emits the new `openIds` whenever it changes — the output half of `[(openIds)]`.

Customization & theming

  • Three sizes: sm / md / lg.
  • Single- or multi-expand via `expandMode`.
  • Flush and filled styles; the separated card style is Pro (`sv-accordion-pro`).
  • Badges, subtitles and icon placement.
  • expandAll() / collapseAll() for an "Expand all" control (expandAll needs expandMode="multi").
  • A filterable FAQ: bind a search field to searchQuery and read matchedIds() for the count.

Best practices

  • Do: Use single-expand for guided reading; multi-expand when users compare sections.
  • Do: Write headers that summarize their panel so users can scan without opening.
  • Don't: Don't hide critical primary content behind a collapsed panel by default.

Accessibility

  • Headers are native buttons with aria-expanded; panels linked via aria-controls.
  • Keyboard: Enter/Space toggles, ↑↓/Home/End move focus between headers.
  • Collapsed panels are out of the tab order and the accessibility tree: hidden="until-found" where the browser supports it (so Ctrl+F still finds their text and opens the panel), inert where it does not.
  • Print and find-in-page contract: printing reveals every enabled panel and restores the reader's own open set afterwards (expandOnPrint, on by default); a find-in-page hit opens its panel; disabled panels stay closed in both.
  • searchQuery announces how many sections matched through the shared live region, so a search field beside it needs no live region of its own.

Feedback on Accordion

Spotted a gap in this page, or something that didn't work as described? Comments are GitHub Discussions in the public styloviz/community repo, so posting needs a GitHub account.

Loads giscus.app and GitHub — nothing is fetched until you click.