Angular Accordion Component

Accordion

Build vertically collapsing accordions in combination with our Angular Collapse component.

Available in Other JavaScript Frameworks

CoreUI Angular Accordion Component is also available for Bootstrap, React, and Vue. Explore framework-specific implementations below:

Examples

Click the accordions below to expand/collapse the accordion content.

import { Component } from '@angular/core';
import {
  AccordionButtonDirective,
  AccordionComponent,
  AccordionItemComponent,
  TemplateIdDirective
} from '@coreui/angular';

@Component({
  selector: 'docs-accordion-example',
  templateUrl: './accordion-example.component.html',
  imports: [AccordionComponent, AccordionItemComponent, TemplateIdDirective, AccordionButtonDirective]
})
export class AccordionExampleComponent {
  items = [1, 2, 3, 4];
}
<c-accordion>
  <c-accordion-item #item0="cAccordionItem" [visible]="false">
    <ng-template cTemplateId="accordionHeaderTemplate">
      <button (click)="item0.toggleItem()" [collapsed]="!item0.visible" cAccordionButton>
        Accordion item #0
      </button>
    </ng-template>
    <ng-template cTemplateId="accordionBodyTemplate">
      <div class="accordion-body">
        <strong>This is the first item's accordion body.</strong> It is hidden by default,
        until the collapse plugin adds the appropriate classes that we use to style each
        element. These classes control the overall appearance, as well as the showing and
        hiding via CSS transitions. You can modify any of this with custom CSS or overriding
        our default variables. It's also worth noting that just about any HTML can go within
        the <code>.accordion-body</code>, though the transition does limit overflow.
      </div>
    </ng-template>
  </c-accordion-item>
  <c-accordion-item #item1="cAccordionItem" [visible]="true">
    <ng-template cTemplateId="accordionHeaderTemplate">
      <button (click)="item1.toggleItem()" [collapsed]="!item1.visible" cAccordionButton>
        Accordion item #1
      </button>
    </ng-template>
    <ng-template cTemplateId="accordionBodyTemplate">
      <div class="accordion-body">
        <strong>This is the second item's accordion body.</strong> It is hidden by default,
        until the collapse plugin adds the appropriate classes that we use to style each
        element. These classes control the overall appearance, as well as the showing and
        hiding via CSS transitions. You can modify any of this with custom CSS or overriding
        our default variables. It's also worth noting that just about any HTML can go within
        the <code>.accordion-body</code>, though the transition does limit overflow.
      </div>
    </ng-template>
  </c-accordion-item>
  <c-accordion-item #item2="cAccordionItem" [visible]="false">
    <ng-template cTemplateId="accordionHeaderTemplate">
      <button (click)="item2.toggleItem()" [collapsed]="!item2.visible" cAccordionButton>
        Accordion item #2
      </button>
    </ng-template>
    <ng-template cTemplateId="accordionBodyTemplate">
      <div class="accordion-body">
        <strong>This is the third item's accordion body.</strong> It is hidden by default,
        until the collapse plugin adds the appropriate classes that we use to style each
        element. These classes control the overall appearance, as well as the showing and
        hiding via CSS transitions. You can modify any of this with custom CSS or overriding
        our default variables. It's also worth noting that just about any HTML can go within
        the <code>.accordion-body</code>, though the transition does limit overflow.
      </div>
    </ng-template>
  </c-accordion-item>
</c-accordion>

Flush

Add flush to remove the default background-color, some borders, and some rounded corners to render accordions edge-to-edge with their parent container.

import { Component } from '@angular/core';
import {
  AccordionButtonDirective,
  AccordionComponent,
  AccordionItemComponent,
  TemplateIdDirective
} from '@coreui/angular';

@Component({
  selector: 'docs-accordion-flush',
  templateUrl: './accordion-flush.component.html',
  imports: [AccordionComponent, AccordionItemComponent, TemplateIdDirective, AccordionButtonDirective]
})
export class AccordionFlushComponent {
  items = [1, 2, 3, 4];
}
<c-accordion [flush]="true">
  <c-accordion-item #item0="cAccordionItem" [visible]="false">
    <ng-template cTemplateId="accordionHeaderTemplate">
      <button (click)="item0.toggleItem()" [collapsed]="!item0.visible" cAccordionButton>
        Accordion item #0
      </button>
    </ng-template>
    <ng-template cTemplateId="accordionBodyTemplate">
      <div class="accordion-body">
        <strong>This is the first item's accordion body.</strong> It is hidden by default,
        until the collapse plugin adds the appropriate classes that we use to style each
        element. These classes control the overall appearance, as well as the showing and
        hiding via CSS transitions. You can modify any of this with custom CSS or overriding
        our default variables. It's also worth noting that just about any HTML can go within
        the <code>.accordion-body</code>, though the transition does limit overflow.
      </div>
    </ng-template>
  </c-accordion-item>
  <c-accordion-item #item1="cAccordionItem" [visible]="false">
    <ng-template cTemplateId="accordionHeaderTemplate">
      <button (click)="item1.toggleItem()" [collapsed]="!item1.visible" cAccordionButton>
        Accordion item #1
      </button>
    </ng-template>
    <ng-template cTemplateId="accordionBodyTemplate">
      <div class="accordion-body">
        <strong>This is the second item's accordion body.</strong> It is hidden by default,
        until the collapse plugin adds the appropriate classes that we use to style each
        element. These classes control the overall appearance, as well as the showing and
        hiding via CSS transitions. You can modify any of this with custom CSS or overriding
        our default variables. It's also worth noting that just about any HTML can go within
        the <code>.accordion-body</code>, though the transition does limit overflow.
      </div>
    </ng-template>
  </c-accordion-item>
  <c-accordion-item #item2="cAccordionItem" [visible]="false">
    <ng-template cTemplateId="accordionHeaderTemplate">
      <button (click)="item2.toggleItem()" [collapsed]="!item2.visible" cAccordionButton>
        Accordion item #2
      </button>
    </ng-template>
    <ng-template cTemplateId="accordionBodyTemplate">
      <div class="accordion-body">
        <strong>This is the third item's accordion body.</strong> It is hidden by default,
        until the collapse plugin adds the appropriate classes that we use to style each
        element. These classes control the overall appearance, as well as the showing and
        hiding via CSS transitions. You can modify any of this with custom CSS or overriding
        our default variables. It's also worth noting that just about any HTML can go within
        the <code>.accordion-body</code>, though the transition does limit overflow.
      </div>
    </ng-template>
  </c-accordion-item>
</c-accordion>

Always open

Make accordion items stay open when another item is opened.

import { Component } from '@angular/core';
import {
  AccordionButtonDirective,
  AccordionComponent,
  AccordionItemComponent,
  TemplateIdDirective
} from '@coreui/angular';

@Component({
  selector: 'docs-accordion-always-open',
  templateUrl: './accordion-always-open.component.html',
  imports: [AccordionComponent, AccordionItemComponent, TemplateIdDirective, AccordionButtonDirective]
})
export class AccordionAlwaysOpenComponent {
  items = [1, 2, 3, 4];
}
<c-accordion [alwaysOpen]="true">
  <c-accordion-item #item0="cAccordionItem" [visible]="false">
    <ng-template cTemplateId="accordionHeaderTemplate">
      <button (click)="item0.toggleItem()" [collapsed]="!item0.visible" cAccordionButton>
        Accordion item #0
      </button>
    </ng-template>
    <ng-template cTemplateId="accordionBodyTemplate">
      <div class="accordion-body">
        <strong>This is the first item's accordion body.</strong> It is hidden by default,
        until the collapse plugin adds the appropriate classes that we use to style each
        element. These classes control the overall appearance, as well as the showing and
        hiding via CSS transitions. You can modify any of this with custom CSS or overriding
        our default variables. It's also worth noting that just about any HTML can go within
        the <code>.accordion-body</code>, though the transition does limit overflow.
      </div>
    </ng-template>
  </c-accordion-item>
  <c-accordion-item #item1="cAccordionItem" [visible]="false">
    <ng-template cTemplateId="accordionHeaderTemplate">
      <button (click)="item1.toggleItem()" [collapsed]="!item1.visible" cAccordionButton>
        Accordion item #1
      </button>
    </ng-template>
    <ng-template cTemplateId="accordionBodyTemplate">
      <div class="accordion-body">
        <strong>This is the second item's accordion body.</strong> It is hidden by default,
        until the collapse plugin adds the appropriate classes that we use to style each
        element. These classes control the overall appearance, as well as the showing and
        hiding via CSS transitions. You can modify any of this with custom CSS or overriding
        our default variables. It's also worth noting that just about any HTML can go within
        the <code>.accordion-body</code>, though the transition does limit overflow.
      </div>
    </ng-template>
  </c-accordion-item>
  <c-accordion-item #item2="cAccordionItem" [visible]="false">
    <ng-template cTemplateId="accordionHeaderTemplate">
      <button (click)="item2.toggleItem()" [collapsed]="!item2.visible" cAccordionButton>
        Accordion item #2
      </button>
    </ng-template>
    <ng-template cTemplateId="accordionBodyTemplate">
      <div class="accordion-body">
        <strong>This is the third item's accordion body.</strong> It is hidden by default,
        until the collapse plugin adds the appropriate classes that we use to style each
        element. These classes control the overall appearance, as well as the showing and
        hiding via CSS transitions. You can modify any of this with custom CSS or overriding
        our default variables. It's also worth noting that just about any HTML can go within
        the <code>.accordion-body</code>, though the transition does limit overflow.
      </div>
    </ng-template>
  </c-accordion-item>
</c-accordion>

API

Accordion Module

import { AccordionModule, SharedModule } from '@coreui/angular';

@NgModule({
    imports: [
      AccordionModule,
      SharedModule
    ]
})
export class AppModule(){}

c-accordion

component

jsx
import { AccordionComponent } from '@coreui/angular'
PropertyDefaultType
alwaysOpenfalseboolean

Make accordion items stay open when another item is opened

flushfalseboolean

Removes the default background-color, some borders, and some rounded corners to render accordions edge-to-edge with their parent container.

c-accordion-item

component

jsx
import { AccordionItemComponent } from '@coreui/angular'
PropertyDefaultType
visiblefalseboolean

Toggle an accordion item programmatically

cAccordionButton

directive

jsx
import { AccordionButtonDirective } from '@coreui/angular'
PropertyDefaultType
collapsedundefinedboolean

Toggles an accordion button collapsed state. Use in accordionHeaderTemplate.

type'button'string

Default type for cAccordionButton

Shared Module

cTemplateId

directive

jsx
import { TemplateIdDirective } from '@coreui/angular'
PropertyDefaultType
cTemplateId-string

Predefined template name (id) for optional slots

templates:

template iddescription
accordionHeaderheader content only
accordionBodybody content only
accordionHeaderTemplateheader full template
accordionBodyTemplatebody full template

internals:

AccordionService

service

proptypedefaultdescription
itemsAccordionItemComponent[][ ]array of accordion items
alwaysOpenbooleanfalsein sync with AccordionComponent.alwaysOpen prop