Basic Accordion

A basic accordion with multiple items that can be opened independently.

Single-Select Accordion

Only one item can be open at a time. Opening a new item closes the previously opened one.

Without Chevron

A simpler accordion design without the chevron indicator.

Keyboard Navigation Demo

Try focusing on the accordion below and using keyboard navigation:

Programmatic Control

You can also control accordions programmatically using JavaScript.

HTML Structure

Here's the basic HTML structure for an accordion:

<div class="accordion">
  <div class="item">
    <button class="control chevron" aria-expanded="false" aria-controls="content-1">
      Control Text
    </button>
    <div class="content" id="content-1" hidden data-animate="accordion">
      Content goes here
    </div>
  </div>
</div>

JavaScript Integration

Initialize accordions with enhanced functionality:

import { initAccordions, createAccordion } from '@/accordion/scripts/services/accordion'

// Initialize all accordions on the page
initAccordions()

// Or create a specific accordion instance
const accordion = createAccordion('#my-accordion', {
  multiSelect: false,
  keyboard: true,
  onOpen: (element, target) => console.log('Opened:', element),
  onClose: (element, target) => console.log('Closed:', element)
})

// Programmatic control
accordion.open(0)
accordion.close(0)
accordion.toggle(0)