Accordion

Accordions are vertically stacked expandable items. They reduce clutter by showing only essential information initially and revealing details on demand.

When to use

  • To organize and present large amounts of content in a compact way
  • For FAQs (Frequently Asked Questions)
  • To create collapsible sections in forms or settings
  • When you need to reduce cognitive load by hiding secondary information

Anatomy

  • Container: Wraps all accordion items
  • Item: Individual collapsible section
  • Trigger: Clickable header that toggles content
  • Content: Hidden/shown area containing detailed information
  • Icon: Visual indicator showing open/closed state

Basic Accordion

pm7-ui is a modern, accessible component library designed for building beautiful user interfaces. It provides a comprehensive set of customizable components that work seamlessly across different frameworks.

You can install pm7-ui using npm or yarn:

npm install @pm7/core
# or
yarn add @pm7/core

Yes! pm7-ui is built with accessibility in mind. All components follow WAI-ARIA guidelines and are keyboard navigable, screen reader friendly, and support reduced motion preferences.

Accordion with Fixed Max Width

800px Max Width

Deze accordion heeft een maximale breedte van 800px dankzij de pm7-accordion--width-800 class. Dit is ideaal voor content die niet te breed moet worden op grote schermen.

  • Perfecte leesbreedte voor lange teksten
  • Consistent gedrag op alle schermformaten
  • Automatisch responsive op kleinere schermen
Max breedte: 800px
Min breedte: Auto (100% van parent)
Responsive: Ja, past zich aan op kleinere schermen

1000px Max Width

Deze accordion gebruikt pm7-accordion--width-1000 voor een bredere layout die meer content kan bevatten. Perfect voor dashboards en data-rijke interfaces.

Security
  • End-to-end encryption
  • Two-factor authentication
  • Role-based access control
Performance
  • 99.9% uptime SLA
  • Global CDN
  • Auto-scaling infrastructure
Integration
  • REST API
  • Webhooks
  • SSO support
Starter

€29/mo

  • Up to 10 users
  • Basic features
  • Email support
Professional

€99/mo

  • Up to 50 users
  • Advanced features
  • Priority support
Enterprise

Custom

  • Unlimited users
  • All features
  • Dedicated support

Met de bredere layout van 1000px is er meer ruimte voor gedetailleerde tijdlijnen en procesoverzichten.

Multiple Open Items

  • Modern design system
  • Fully customizable
  • Dark mode support
  • TypeScript support
  • Faster development
  • Consistent UI/UX
  • Accessible by default
  • Great developer experience

Accordion Variants

No Separator

This accordion doesn't have a separator line between the header and content when expanded.

The content flows directly from the header without visual separation.

Flush Variant

Manage your account preferences, security settings, and profile information.

Control your privacy settings, manage data sharing, and configure security options.

Size Variants

Ultra-compact design with minimal padding and smallest font size. Perfect for very tight spaces or mobile interfaces.

Minimal visual footprint for maximum content density.

Compact design with smaller padding, font size, and icon. Perfect for sidebars or dense information layouts.

Less visual weight for secondary content.

Standard size with balanced padding and typography. This is the default size used when no size modifier is specified.

Ideal for most use cases and content types.

Spacious design with larger padding, font size, and icon. Great for important content or when you need more visual emphasis.

More prominent presentation for primary content areas.

Icon Position Variants

De accordion ondersteunt drie verschillende icon posities. Hieronder zie je alle varianten naast elkaar:

Default - Icon End (Helemaal Rechts)

Dit is de standaard positie. De icon staat helemaal rechts uitgelijnd met justify-content: space-between.

Ongeacht de lengte van de titel, blijft de icon altijd helemaal rechts staan. Dit geeft een strakke, uitgelijde look.

Ideaal voor professionele interfaces waar consistente uitlijning belangrijk is.

Icon Start (Links)

Met pm7-accordion--icon-start staat de icon links van de titel. Dit wordt bereikt met flex-direction: row-reverse.

Deze layout wordt vaak gebruikt in navigatie menus of wanneer de icon als visuele indicator voor de hele sectie dient.

Perfect voor file explorers of boom structuren waar de expand/collapse actie aan het begin verwacht wordt.

Icon Inline (Direct na titel)

Met pm7-accordion--icon-inline staat de icon direct 10px naast de titel. Dit gebruikt justify-content: flex-start met margin-left: 10px op de icon.

De icon "plakt" aan de tekst, wat een compactere weergave geeft. Er is geen lege ruimte tussen titel en icon.

Ideaal voor minimalistische designs of wanneer de accordion items korte labels hebben.

Vergelijking - Alle drie naast elkaar

Default (Icon End):

Icon staat helemaal rechts

Icon Start:

Icon staat links van de titel

Icon Inline:

Icon staat direct na de titel

Width Variants

Full Width (100% of parent)

Parent container with max-width: 800px

Deze accordion gebruikt de pm7-accordion--width-max class en neemt de volledige breedte van het moederelement in beslag. Perfect voor formulieren of content die de volledige beschikbare ruimte moet gebruiken.

De accordion past zich automatisch aan de breedte van het parent element aan, ongeacht de viewport grootte.

Max Width 800px

Deze accordion gebruikt pm7-accordion--width-800 en heeft een maximale breedte van 800px. Op kleinere schermen past de accordion zich automatisch aan.

De breedte blijft consistent of de accordion open of dicht is. Perfect voor een voorspelbare layout.

Max Width 1000px

Deze accordion gebruikt pm7-accordion--width-1000 en heeft een maximale breedte van 1000px. Ideaal voor bredere content layouts.

Op schermen smaller dan 1000px neemt de accordion automatisch 100% van de beschikbare breedte in.

Text Alignment

This accordion has center-aligned text in the header.

This accordion has right-aligned text in the header.

This combines icon at start with center-aligned text.

Height Variants

This accordion has a maximum height of 200px. When content exceeds this height, it becomes scrollable with a custom scrollbar.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.

This accordion has a maximum height of 400px. Perfect for medium-sized content that needs scrolling.

  • Feature 1: Lorem ipsum dolor sit amet
  • Feature 2: Consectetur adipiscing elit
  • Feature 3: Sed do eiusmod tempor incididunt
  • Feature 4: Ut labore et dolore magna aliqua
  • Feature 5: Ut enim ad minim veniam
  • Feature 6: Quis nostrud exercitation ullamco
  • Feature 7: Laboris nisi ut aliquip ex ea
  • Feature 8: Commodo consequat duis aute irure
  • Feature 9: Dolor in reprehenderit in voluptate
  • Feature 10: Velit esse cillum dolore eu fugiat

Additional content to demonstrate scrolling behavior in medium height accordions.

This accordion has a maximum height of 600px. Perfect for large content sections that still need a reasonable limit.

Complete Feature List

  • Core Features: Modern design system, fully customizable components, comprehensive theming
  • Developer Experience: TypeScript support, tree-shaking ready, zero dependencies
  • Performance: Optimized bundle size, lazy loading support, efficient rendering
  • Accessibility: WCAG 2.1 compliant, keyboard navigation, screen reader support
  • Customization: CSS variables, theme inheritance, component composition
  • Documentation: Comprehensive guides, live examples, API reference
  • Testing: Unit tests, integration tests, visual regression tests
  • Browser Support: Chrome, Firefox, Safari, Edge (latest 2 versions)

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum euismod, nisl eget consectetur sagittis, nisi nisl aliquam est, eget consectetur nisl nisl sit amet nisl.

Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum.

This accordion has a fixed height of 250px. You can set any custom height using the data-fixed-height attribute.

// Example configuration
const accordion = new PM7Accordion(element, {
  height: 'fixed',
  fixedHeight: 250
});

This is useful when you need precise control over the accordion's expanded height, regardless of content size.

The content will scroll if it exceeds the fixed height, maintaining a consistent layout.

Gradient Border Accordion

Default Gradient Border

This accordion item features a beautiful gradient border using the pm7-gradient-border class. The gradient transitions from purple to yellow to orange.

Using pm7-gradient-border-blue for a cool blue gradient effect.

Using pm7-gradient-border-green for a fresh green gradient.

Different Border Thicknesses

A thicker 2px gradient border using pm7-gradient-border-2.

An even bolder 4px gradient border using pm7-gradient-border-4.

Installation

npm install @pm7/core

Important Implementation Notes

⚠️ Common Issues & Solutions

  • Content structure: Always wrap content in pm7-accordion-content-inner
  • JavaScript loading: Include <script type="module" src="@pm7/core/dist/pm7.js"></script>
  • Full width: Use pm7-accordion--width-max to remove width constraints
  • Icons with text: Wrap in flex container for proper alignment (see demo)

CSS Classes

Class Description
Base Classes
.pm7-accordion Container for accordion items
.pm7-accordion-item Individual accordion section
.pm7-accordion-trigger Clickable header button
.pm7-accordion-content Collapsible content area
.pm7-accordion-content-inner Inner wrapper for content padding
.pm7-accordion-icon Chevron icon for open/close state
Variants
.pm7-accordion--flush Removes borders and background
Size Modifiers
.pm7-accordion--xs Extra small size with minimal padding and 14px icon
.pm7-accordion--sm Small size with reduced padding, font size, and 16px icon
.pm7-accordion--md Medium size (default) with balanced proportions
.pm7-accordion--lg Large size with increased padding, font size, and icon
.pm7-accordion--compact Legacy: Same as .pm7-accordion--sm (deprecated)
.pm7-accordion--separated Adds spacing between items
.pm7-accordion--icon-start Positions the expand/collapse icon at the start
.pm7-accordion--icon-inline Icon appears directly after text (10px gap) instead of right-aligned
.pm7-accordion--text-left Left-aligns the header text (default)
.pm7-accordion--text-center Center-aligns the header text
.pm7-accordion--text-right Right-aligns the header text
.pm7-accordion--no-separator Removes the separator line between header and content
Width Modifiers
.pm7-accordion--width-max Forces accordion to take 100% width of parent element
.pm7-accordion--width-800 Sets maximum width to 800px with responsive behavior
.pm7-accordion--width-1000 Sets maximum width to 1000px with responsive behavior
Height Variants
.pm7-accordion--height-sm Small height limit (200px max) with scrollbar
.pm7-accordion--height-md Medium height limit (400px max) with scrollbar
.pm7-accordion--height-lg Large height limit (600px max) with scrollbar
.pm7-accordion--height-fixed Fixed height with custom value via CSS variable

Data Attributes

Attribute Type Default Description
data-pm7-accordion Boolean - Enables automatic initialization
data-allow-multiple Boolean false Allow multiple items open simultaneously
data-default-open Number|"all" null Index of item(s) to open by default
data-state "open"|"closed" "closed" Current state of accordion item
data-icon-position "start"|"end" "end" Position of the expand/collapse icon
data-text-align "left"|"center"|"right" "left" Text alignment in the header
data-height "sm"|"md"|"lg"|"fixed" null Height limit for accordion content
data-fixed-height Number 300 Custom height in pixels when using "fixed" height

Basic Usage

<!-- Default accordion -->
<div class="pm7-accordion" data-pm7-accordion>
  <div class="pm7-accordion-item">
    <button class="pm7-accordion-trigger">
      <span>Accordion Header</span>
      <svg class="pm7-accordion-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
        <path d="M19 9l-7 7-7-7"/>
      </svg>
    </button>
    <div class="pm7-accordion-content">
      <div class="pm7-accordion-content-inner">
        <p>Your content here</p>
      </div>
    </div>
  </div>
</div>

<!-- Accordion with icon at start -->
<div class="pm7-accordion" data-pm7-accordion data-icon-position="start">
  <!-- Accordion items -->
</div>

<!-- Or using CSS class directly -->
<div class="pm7-accordion pm7-accordion--icon-start" data-pm7-accordion>
  <!-- Accordion items -->
</div>

<!-- Accordion with inline icon (direct after text) -->
<div class="pm7-accordion pm7-accordion--icon-inline" data-pm7-accordion>
  <!-- Icon appears 10px after text instead of right-aligned -->
</div>

<!-- Accordion with height limit -->
<div class="pm7-accordion" data-pm7-accordion data-height="sm">
  <!-- Accordion items with small height limit (200px) -->
</div>

<!-- Accordion with fixed custom height -->
<div class="pm7-accordion" data-pm7-accordion data-height="fixed" data-fixed-height="350">
  <!-- Accordion items with fixed height of 350px -->
</div>

<!-- Full width accordion -->
<div class="pm7-accordion pm7-accordion--width-max" data-pm7-accordion>
  <!-- Accordion takes 100% width of parent container -->
</div>

<!-- Fixed max-width accordions -->
<div class="pm7-accordion pm7-accordion--width-800" data-pm7-accordion>
  <!-- Accordion with max-width of 800px -->
</div>

<div class="pm7-accordion pm7-accordion--width-1000" data-pm7-accordion>
  <!-- Accordion with max-width of 1000px -->
</div>

JavaScript API

import { PM7Accordion } from '@pm7/core';

// Manual initialization
const accordionElement = document.querySelector('.pm7-accordion');
const accordion = new PM7Accordion(accordionElement, {
  allowMultiple: true,
  defaultOpen: 0, // Open first item by default
  iconPosition: 'start', // Position icon at the start
  textAlign: 'center', // Center align header text
  height: 'md', // Set height limit ('sm', 'md', 'lg', 'fixed', or null)
  fixedHeight: 350 // Custom height when using 'fixed' option
});

// Methods
accordion.open(0);      // Open specific item
accordion.close(0);     // Close specific item
accordion.openAll();    // Open all items
accordion.closeAll();   // Close all items
accordion.toggle(0);    // Toggle specific item

Advanced Example

<!-- Accordion with custom configuration -->
<div class="pm7-accordion pm7-accordion--lg pm7-accordion--separated" data-pm7-accordion data-allow-multiple="true">
  <div class="pm7-accordion-item">
    <button class="pm7-accordion-trigger">
      <span>Section 1</span>
      <svg class="pm7-accordion-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
        <path d="M19 9l-7 7-7-7"/>
      </svg>
    </button>
    <div class="pm7-accordion-content">
      <div class="pm7-accordion-content-inner">
        Content for section 1
      </div>
    </div>
  </div>
  <div class="pm7-accordion-item">
    <button class="pm7-accordion-trigger">
      <span>Section 2</span>
      <svg class="pm7-accordion-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
        <path d="M19 9l-7 7-7-7"/>
      </svg>
    </button>
    <div class="pm7-accordion-content">
      <div class="pm7-accordion-content-inner">
        Content for section 2
      </div>
    </div>
  </div>
</div>

Accessibility

  • Keyboard navigation with Tab, Enter, and Space keys
  • Proper ARIA attributes (aria-expanded)
  • Focus management and visible focus indicators
  • Screen reader announcements for state changes

Copy this link that can be used as documentation for working with this component:

https://raw.githubusercontent.com/patrickmast/pm7-ui/main/packages/core/src/components/accordion/README.md

🤖 AI-Optimized Documentation

This link contains complete Markdown documentation that is perfectly readable by AI assistants, developers, and other automated systems. Directly accessible on GitHub - including all essential PM7 Accordion implementation guidance.

Perfect for ChatGPT, Claude, and other AI code assistants