Socket
Book a DemoInstallSign in
Socket

@spectrum-web-components/accordion

Package Overview
Dependencies
Maintainers
7
Versions
362
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@spectrum-web-components/accordion

The `<sp-accordion>` element contains a list of items that can be expanded or collapsed to reveal additional content or information associated with each item. There can be zero expanded items, exactly one expanded item, or more than one item expanded at a

latest
Source
npmnpm
Version
1.8.0
Version published
Weekly downloads
2.8K
33.57%
Maintainers
7
Weekly downloads
 
Created
Source

Overview

The <sp-accordion> element contains a list of items that can be expanded or collapsed to reveal additional content or information associated with each item. There can be zero expanded items, exactly one expanded item, or more than one item expanded at a time, depending on the configuration. This list of items is defined by child <sp-accordion-item> elements that are targeted to the default slot of their <sp-accordion> parent.

Usage

See it on NPM! How big is this package in your project? Try it on Stackblitz

yarn add @spectrum-web-components/accordion

Import the side effectful registration of <sp-accordion> and <sp-accordion-item> via:

import '@spectrum-web-components/accordion/sp-accordion.js';
import '@spectrum-web-components/accordion/sp-accordion-item.js';

When looking to leverage the Accordion and AccordionItem base class as a type and/or for extension purposes, do so via:

import { Accordion, AccordionItem } from '@spectrum-web-components/accordion';

Anatomy

The accordion consists of several key parts:

  • A container element that manages the accordion behavior
  • Individual accordion items that can be expanded or collapsed
  • Each item has a header with a label and chevron icon
  • Content that is revealed when an item is expanded
<sp-accordion>
    <sp-accordion-item label="Bellows">
        <div>
            The bellows is the expandable section in the middle of the
            accordion.
        </div>
    </sp-accordion-item>
    <sp-accordion-item disabled label="Treble">
        <div>
            The treble section of the accordion is the right-hand section for
            playing melodies.
        </div>
    </sp-accordion-item>
    <sp-accordion-item label="Bass">
        <div>
            The bass section of the accordion is the left-hand section for
            playing accompaniment.
        </div>
    </sp-accordion-item>
</sp-accordion>

Options

Sizes

Small
<sp-accordion size="s">
    <sp-accordion-item label="Key Accordion">
        <div>
            A key accordion, or a chromatic piano accordion, includes a keyboard
            for the right hand.
        </div>
    </sp-accordion-item>
    <sp-accordion-item disabled label="Button Accordion">
        <div>
            A button accoridon, or a chromatic accordion, has buttons instead of
            keys.
        </div>
    </sp-accordion-item>
    <sp-accordion-item label="Diatonic Accordion">
        <div>
            Produces two different tones or notes depending on whether the
            bellows is pulled or pushed.
        </div>
    </sp-accordion-item>
    <sp-accordion-item label="Concertina">
        <div>
            A concertina has buttons on both sides and each button makes two
            different notes or tones depending on whether the bellows is pulled
            or pushed.
        </div>
    </sp-accordion-item>
</sp-accordion>
Medium
<sp-accordion size="m">
    <sp-accordion-item label="Key Accordion">
        <div>
            A key accordion, or a chromatic piano accordion, includes a keyboard
            for the right hand.
        </div>
    </sp-accordion-item>
    <sp-accordion-item disabled label="Button Accordion">
        <div>
            A button accoridon, or a chromatic accordion, has buttons instead of
            keys.
        </div>
    </sp-accordion-item>
    <sp-accordion-item label="Diatonic Accordion">
        <div>
            Produces two different tones or notes depending on whether the
            bellows is pulled or pushed.
        </div>
    </sp-accordion-item>
    <sp-accordion-item label="Concertina">
        <div>
            A concertina has buttons on both sides and each button makes two
            different notes or tones depending on whether the bellows is pulled
            or pushed.
        </div>
    </sp-accordion-item>
</sp-accordion>
Large
<sp-accordion size="l">
    <sp-accordion-item label="Key Accordion">
        <div>
            A key accordion, or a chromatic piano accordion, includes a keyboard
            for the right hand.
        </div>
    </sp-accordion-item>
    <sp-accordion-item disabled label="Button Accordion">
        <div>
            A button accoridon, or a chromatic accordion, has buttons instead of
            keys.
        </div>
    </sp-accordion-item>
    <sp-accordion-item label="Diatonic Accordion">
        <div>
            Produces two different tones or notes depending on whether the
            bellows is pulled or pushed.
        </div>
    </sp-accordion-item>
    <sp-accordion-item label="Concertina">
        <div>
            A concertina has buttons on both sides and each button makes two
            different notes or tones depending on whether the bellows is pulled
            or pushed.
        </div>
    </sp-accordion-item>
</sp-accordion>
Extra Large
<sp-accordion size="xl">
    <sp-accordion-item label="Key Accordion">
        <div>
            A key accordion, or a chromatic piano accordion, includes a keyboard
            for the right hand.
        </div>
    </sp-accordion-item>
    <sp-accordion-item disabled label="Button Accordion">
        <div>
            A button accoridon, or a chromatic accordion, has buttons instead of
            keys.
        </div>
    </sp-accordion-item>
    <sp-accordion-item label="Diatonic Accordion">
        <div>
            Produces two different tones or notes depending on whether the
            bellows is pulled or pushed.
        </div>
    </sp-accordion-item>
    <sp-accordion-item label="Concertina">
        <div>
            A concertina has buttons on both sides and each button makes two
            different notes or tones depending on whether the bellows is pulled
            or pushed.
        </div>
    </sp-accordion-item>
</sp-accordion>

Density

The density property, when applied, accepts the values of compact or spacious.

Compact
<div
    style="
  display: grid;
  grid-gap: 20px;
  grid-template-columns: 1fr 1fr"
>
    <sp-accordion density="compact" size="s">
        <sp-accordion-item label="Compact Density">
            <div>This accordion is compact.</div>
        </sp-accordion-item>
        <sp-accordion-item label="Small Size">
            <div>This accordion is also small.</div>
        </sp-accordion-item>
    </sp-accordion>
    <sp-accordion density="compact" size="m">
        <sp-accordion-item label="Compact Density">
            <div>This accordion is compact.</div>
        </sp-accordion-item>
        <sp-accordion-item label="Medium Size">
            <div>This accordion is also medium.</div>
        </sp-accordion-item>
    </sp-accordion>
    <sp-accordion density="compact" size="l">
        <sp-accordion-item label="Compact Density">
            <div>This accordion is compact.</div>
        </sp-accordion-item>
        <sp-accordion-item label="Large Size">
            <div>This accordion is also large.</div>
        </sp-accordion-item>
    </sp-accordion>
    <sp-accordion density="compact" size="xl">
        <sp-accordion-item label="Compact Density">
            <div>This accordion is compact.</div>
        </sp-accordion-item>
        <sp-accordion-item label="Extra Large Size">
            <div>This accordion is also extra large.</div>
        </sp-accordion-item>
    </sp-accordion>
</div>
Spacious
<div
    style="
  display: grid;
  grid-gap: 20px;
    grid-template-columns: 1fr 1fr"
>
    <sp-accordion density="spacious" size="s">
        <sp-accordion-item label="Spacious Density">
            <div>This accordion is spacious.</div>
        </sp-accordion-item>
        <sp-accordion-item label="Small Size">
            <div>This accordion is also small.</div>
        </sp-accordion-item>
    </sp-accordion>
    <sp-accordion density="spacious" size="m">
        <sp-accordion-item label="Spacious Density">
            <div>This accordion is spacious.</div>
        </sp-accordion-item>
        <sp-accordion-item label="Medium Size">
            <div>This accordion is also medium.</div>
        </sp-accordion-item>
    </sp-accordion>
    <sp-accordion density="spacious" size="l">
        <sp-accordion-item label="Spacious Density">
            <div>This accordion is spacious.</div>
        </sp-accordion-item>
        <sp-accordion-item label="Large Size">
            <div>This accordion is also large.</div>
        </sp-accordion-item>
    </sp-accordion>
    <sp-accordion density="spacious" size="xl">
        <sp-accordion-item label="Spacious Density">
            <div>This accordion is spacious.</div>
        </sp-accordion-item>
        <sp-accordion-item label="Extra Large Size">
            <div>This accordion is also extra large.</div>
        </sp-accordion-item>
    </sp-accordion>
</div>

States

Allow Multiple

By default, only one accordion item can be expanded at a time. Use the allow-multiple attribute to allow multiple items to be expanded simultaneously.

<sp-accordion allow-multiple>
    <sp-accordion-item label="Kermit">
        <div>Kermit is a frog.</div>
    </sp-accordion-item>
    <sp-accordion-item label="Fozzie">
        <div>Fozzie is a bear.</div>
    </sp-accordion-item>
    <sp-accordion-item label="Miss Piggy">
        <div>Miss Piggy is a pig.</div>
    </sp-accordion-item>
</sp-accordion>

Disabled

Individual accordion items can be disabled using the disabled attribute. Disabled items cannot be expanded or collapsed.

<sp-accordion>
    <sp-accordion-item label="Apples">
        <div>
            We have some of the most popular varieties include Red Delicious,
            Gala, Granny Smith, Honeycrisp, and Fuji.
        </div>
    </sp-accordion-item>
    <sp-accordion-item disabled label="Bananas">
        <div>We have the Gros Michel.</div>
    </sp-accordion-item>
    <sp-accordion-item label="Oranges">
        <div>We have Mandarins, Seville Oranges, and Clementines.</div>
    </sp-accordion-item>
</sp-accordion>

Accessibility

The accordion component provides proper ARIA attributes and keyboard navigation:

  • Each accordion item header has aria-expanded to indicate its current state
  • The header button has aria-controls pointing to the content region
  • The content region has role="region" and aria-labelledby pointing to the header
  • Disabled items have aria-disabled="true" applied
  • The accordion supports keyboard navigation with arrow keys and Enter/Space for activation

Include descriptive labels

Each accordion item should have a clear, descriptive label that indicates what content will be revealed when expanded.

Use appropriate content

Accordion content should be related to the header label and provide additional information or functionality that users can access when needed.

Keywords

design-system

FAQs

Package last updated on 23 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts