npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@spectrum-web-components/accordion

v1.12.1

Published

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

Readme

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

<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>
<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>
<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>
<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.

<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>
<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>

Heading level

The level attribute controls the semantic heading level (2-6) used for all accordion item titles. This helps maintain proper document structure and accessibility. The range is restricted to 2-6 as there should only be one h1 per page. Defaults to 3.

All items within an accordion will use the same heading level, ensuring items of equal importance have consistent semantic meaning.

<h1>Main Page Title</h1>

<sp-accordion level="2">
  <sp-accordion-item label="First Section">
    <div>Content for the first main section.</div>
  </sp-accordion-item>
  <sp-accordion-item label="Second Section">
    <div>Content for the second main section.</div>
  </sp-accordion-item>
  <sp-accordion-item label="Third Section">
    <div>Content for the third main section.</div>
  </sp-accordion-item>
</sp-accordion>

<h2>Subsection Title</h2>

<sp-accordion level="3">
  <sp-accordion-item label="Subsection A">
    <div>Content for subsection A.</div>
  </sp-accordion-item>
  <sp-accordion-item label="Subsection B">
    <div>Content for subsection B.</div>
  </sp-accordion-item>
</sp-accordion>

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.