<cs-accordion>
ExperimentalLayoutSince 0.1

Accordions are a vertically stacked set of interactive headings that each contain a title, representing a section of content.

Cornerstone is a comprehensive library of web components you can use to build beautiful, accessible web applications. It's built on open web standards and works with any framework. The core Cornerstone library is completely free and open source. A Pro tier is also available with additional components and features. Yes! Cornerstone components are built as native web components, so they work with any framework including React, Vue, Angular, Svelte, or plain HTML.

Accordions use accordion items to create a vertically stacked set of expandable sections.

Examples

Expanded Initially

Use the expanded attribute on an accordion item to expand it by default.

This item is expanded by default. Click the header to collapse it. This item starts collapsed. Click the header to expand it.

Disabled

Use the disabled attribute on an accordion item to prevent it from being toggled.

This item can be expanded and collapsed normally. This item is disabled and cannot be toggled.

Heading Level

Each accordion item wraps its trigger in a heading so screen reader users can navigate to it, per the W3C accordion pattern. The default is <h3>. Set the heading-level attribute to match your page’s hierarchy (values outside 1–6 fall back to 3). The level is semantic only; the accordion inherits the surrounding font, so the appearance is identical at every level.

This trigger is wrapped in an <h2>. Match the level to where this accordion sits in your document outline.

If an accordion lives outside the document outline (inside a nav or another component with its own structure), set heading-level="none" to omit the heading wrapper and render the button directly.

Adjust your preferences here. Manage how and when you receive notifications.

Size

The accordion’s text and expand/collapse icon scale with font-size. Setting font-size on a <cs-accordion> proportionally resizes the type and icon together.

Text and icon scale down together. Content here.
The default size. Content here.
Everything scales up together. Content here.

Appearance

Use the appearance attribute to change the accordion’s visual appearance.

This is the default outlined appearance. It has a subtle border that helps it stand out without being too flashy. More content here. The filled-outlined appearance combines a filled header with an outlined body. It gives the summary a bit more visual weight while keeping the content area clean. More content here. The filled appearance adds a background color to the entire component. Use this when you want the details to really pop on the page. More content here. No bells and whistles on this one. The plain appearance strips away borders and backgrounds for a minimalist look. More content here.

Mode

Use the mode attribute to control how items can be expanded.

ModeBehavior
multiple defaultAny number of items open at once; each toggles independently
singleOne item open at a time; opening another collapses it, and clicking the open item keeps it open
single-collapsibleLike single, but clicking the open item closes it — so zero open items is a valid state
Opening another section will automatically collapse this one. Only one section can be open at a time. Try opening this section to see section one collapse automatically. Clicking an already-open section won't close it — open another instead.

Use single-collapsible when you want the same one-at-a-time constraint but still want users to be able to close every section.

Opening another section will collapse this one, and clicking the open section closes it. Try opening and closing each section in turn. Zero open sections is a valid state in this mode.

Icon Placement

The expand/collapse icon appears at the end of each header by default. Set icon-placement="start" to move it to the beginning, a common pattern for sidebars and tree style navigation.

Icon is at the start of the header. More content here.

Custom Icon

Use the icon slot on an accordion item to replace the default expand/collapse icon with any icon you like.

By default the icon rotates as the item expands. You can target the icon part with ::part(icon) to customize the rotation, or set rotate: none to prevent the animation and swap the icon instead. Because expanded reflects an attribute, [expanded]::part(icon) lets you style each state.

Replace the default chevron and customize how it rotates. Prevent the rotation and swap + for − when the item expands.

HTML in the Label

To place HTML in an accordion item’s header, use the label slot instead of the label attribute. This lets you add icons, badges, or other elements alongside the label text.

Tasks 3 ready
All three tasks are ready to be reviewed.
Issues 2 open
There are two open issues that need your attention.

Expand & Collapse All

Use the expandAll() and collapseAll() methods to programmatically control all items at once. Note that expandAll() is a no-op when mode is single or single-collapsible.

Content for the first section. Content for the second section. Content for the third section.
Expand All Collapse All

Nested Accordions

Place a <cs-accordion> inside an accordion item’s default slot to nest one accordion inside another. Each accordion manages its own items independently, so toggling an inner item won’t affect outer items, and properties like mode apply only to direct children.

Crisp, sweet, and great for pies. Juicy and packed with vitamin C. Soft, sweet, and easy to peel. Crunchy and rich in beta carotene. A nutrient-dense cruciferous vegetable.

Preventing Expand or Collapse

Listen for the cs-accordion-expand or cs-accordion-collapse events and call event.preventDefault() to stop the action from completing. The event.detail.item property tells you which accordion item triggered the event.

This item is locked open — the cs-accordion-collapse event is being intercepted and prevented. This item can be toggled normally.

API

Importing

If you're using the autoloader or a hosted project, components load on demand — no manual import needed. To cherry-pick this component, use one of the following snippets.

npm Self-Hosted React
import '@cruglobal/cornerstone-components/components/accordion/accordion.js';
import './cornerstone/components/accordion/accordion.js';
import CsAccordion from '@cruglobal/cornerstone-components/react/accordion/index.js';

Slots

Learn more about using slots.

NameDescription
(default)One or more <cs-accordion-item> elements.

Attributes & Properties

Learn more about attributes and properties.

PropertyAttributeDescriptionTypeDefaultReflects
appearanceappearanceThe accordion's visual appearance.'filled' | 'outlined' | 'filled-outlined' | 'plain''outlined'Yes
headingLevelheading-levelThe heading level for child item triggers (1–6), or "none" to omit the heading wrapper. Defaults to 3.string'3'Yes
iconPlacementicon-placementThe location of the expand/collapse icon in child items.'start' | 'end''end'Yes
modemodeControls how items can be expanded. multiple (the default) allows any number of items to be open at once. single allows only one item to be open at a time; opening a new item collapses the previously open one, and clicking an open item does not collapse it. single-collapsible is the same as single except that clicking the open item collapses it, so zero open items is a valid state.'single' | 'single-collapsible' | 'multiple''multiple'Yes

Methods

Learn more about methods.

NameDescriptionArguments
collapseAll()Collapses all accordion items.
expandAll()Expands all accordion items. No-op when mode is single or single-collapsible.

Events

Learn more about events.

NameDescription
cs-accordion-after-collapseEmitted after an item finishes collapsing.
cs-accordion-after-expandEmitted after an item finishes expanding.
cs-accordion-collapseEmitted before an item collapses. Cancelable.
cs-accordion-expandEmitted before an item expands. Cancelable.

Dependencies

This component automatically imports the following elements. Sub-dependencies, if any exist, are included in this list.