Getting started with Angular Accordion component
28 Jul 202610 minutes to read
The Accordion component allows users to expand and collapse content panels, enabling efficient organization and presentation of information in a limited space.
This guide provides step-by-step instructions for setting up an Angular project with TypeScript using Angular CLI, and integrating Syncfusion® Angular Accordion component. The recommended setup below targets modern Angular (CLI ng add). For module-based or framework host setups, see See Also.
The Angular CLI simplifies creating, managing, and building Angular applications so you can start development quickly.
Prerequisites
- Install a supported Node.js LTS release and npm (or another Node package manager) before continuing.
- Ensure your environment meets the System Requirements for Syncfusion® Angular UI Components.
- Supported Angular and Syncfusion package combinations are listed in the Version Compatibility guide. This walkthrough assumes Angular 17+ with the default application scaffolding (
src/app/app.tsor the equivalent root component generated by your CLI version).
Setup the Angular application
A straightforward approach to beginning with Angular is to create a new application using the Angular CLI. Install Angular CLI globally with the following command:
npm install -g @angular/cliAngular 21 Standalone Architecture: Standalone components are the default in Angular 21. This guide uses the modern standalone architecture. If you need more information about the standalone architecture, refer to the Standalone Guide.
Create a new application
With Angular CLI installed, execute this command to generate a new application:
ng new syncfusion-angular-app- This command will prompt you to configure settings like enabling Angular routing and choosing a stylesheet format.
? Which stylesheet format would you like to use? (Use arrow keys)
> CSS [ https://developer.mozilla.org/docs/Web/CSS ]
Sass (SCSS) [ https://sass-lang.com/documentation/syntax#scss ]
Sass (Indented) [ https://sass-lang.com/documentation/syntax#the-indented-syntax ]
Less [ http://lesscss.org ]- By default, a CSS-based application is created. Use SCSS if required:
ng new syncfusion-angular-app --style=scss- During project setup, when prompted for the Server-side rendering (SSR) option, choose the appropriate configuration.

- Select the required AI tool or ‘none’ if you do not need any AI tool.

- Navigate to your newly created application directory:
cd syncfusion-angular-appNote: In Angular 19 and below, it uses
app.component.ts,app.component.html,app.component.cssetc. In Angular 20+, the CLI generates a simpler structure withsrc/app/app.ts,app.html, andapp.css(no.component.suffixes).
Adding the Syncfusion® Angular Accordion package
To install the Syncfusion® Angular Accordion package, use the following command:
ng install @syncfusion/ej2-angular-navigationsThe ng add command installs the package, registers it in package.json, and configures the required entries in your workspace automatically.
If ng add is unavailable in your setup, install the package manually with:
npm install @syncfusion/ej2-angular-navigationsAdding CSS reference
Themes for the Syncfusion® Accordion component can be applied using CSS files provided through npm theme packages. For available themes, refer to the Themes documentation.
Install the Material 3 theme package using the following npm command:
npm install @syncfusion/ej2-material3-themeThen add the following CSS reference to the src/styles.css file. This is the default global stylesheet registered under styles in angular.json:
@import "../node_modules/@syncfusion/ej2-material3-theme/styles/accordion/index.css";Add Syncfusion® Accordion component
After package and theme setup, update the root component. File name and class name can vary by Angular CLI version (src/app/app.ts with export class App, or app.component.ts with AppComponent). Replace the root component content with the sample below, or merge the Accordion import, template, and data into your generated file.
For the full property list, see the Accordion API reference.
import { AccordionModule } from '@syncfusion/ej2-angular-navigations';
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
imports: [AccordionModule],
templateUrl: './app.html',
styleUrl: './app.css',
})
export class App {
public accordionItems = [
{
header: 'ASP.NET',
content: `Microsoft ASP.NET is a set of technologies in the Microsoft .NET Framework for building Web applications and XML Web services. ASP.NET pages execute on the server and generate markup such as HTML, WML, or XML that is sent to a desktop or mobile browser. ASP.NET pages use a compiled, event-driven programming model that improves performance and enables the separation of application logic and user interface.`,
expanded: true,
},
{
header: 'ASP.NET MVC',
content: `The Model-View-Controller (MVC) architectural pattern separates an application into three main components: the model, the view, and the controller. The ASP.NET MVC framework provides an alternative to the ASP.NET Web Forms pattern for creating Web applications. It is lightweight, highly testable, and integrates with existing ASP.NET features like master pages and membership-based authentication.`,
},
{
header: 'JavaScript',
content: `JavaScript (JS) is an interpreted programming language originally implemented in web browsers to enable client-side scripting. It allows interaction with users, asynchronous communication, and dynamic content updates. Today, JavaScript is widely used in game development and desktop application creation as well.`,
},
];
}Place the following markup in the component template file referenced by `templateUrl` (for example, `src/app/app.html`):
```html
<ejs-accordion [items]="accordionItems"></ejs-accordion>
Running the application
From the project root:
npm startWhen the build succeeds, the CLI reports a local URL (default: http://localhost:4200). Open that URL in a browser to view the Accordion. If the port is already in use, the CLI prompts for another port, or you can run ng serve --port 4201
Stop the server with Ctrl+C in the terminal.
The following example illustrates the output in your browser.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { AccordionModule } from '@syncfusion/ej2-angular-navigations'
import { Component, ViewChild } from '@angular/core';
@Component({
imports: [
AccordionModule
],
standalone: true,
selector: 'app-root',
template: `
<ejs-accordion>
<e-accordionitems>
<e-accordionitem expanded='true'>
<ng-template #header>
<div>ASP.NET</div>
</ng-template>
<ng-template #content>
<div>Microsoft ASP.NET is a set of technologies in the Microsoft .NET Framework for building Web applications and XML Web
services. ASP.NET pages execute on the server and generate markup such as HTML, WML, or XML that is sent to a desktop
or mobile browser. ASP.NET pages use a compiled,event-driven programming model that improves performance and enables
the separation of application logic and user interface.</div>
</ng-template>
</e-accordionitem>
<e-accordionitem>
<ng-template #header>
<div>ASP.NET MVC</div>
</ng-template>
<ng-template #content>
<div>The Model-View-Controller (MVC) architectural pattern separates an application into three main components: the model,
the view, and the controller. The ASP.NET MVC framework provides an alternative to the ASP.NET Web Forms pattern for
creating Web applications. The ASP.NET MVC framework is a lightweight, highly testable presentation framework that
(as with Web Forms-based applications) is integrated with existing ASP.NET features, such as master pages and membership-based
authentication.
</div>
</ng-template>
</e-accordionitem>
<e-accordionitem>
<ng-template #header>
<div>JavaScript</div>
</ng-template>
<ng-template #content>
<div>JavaScript (JS) is an interpreted computer programming language.It was originally implemented as part of web browsers
so that client-side scripts could interact with the user, control the browser, communicate asynchronously, and alter
the document content that was displayed.More recently, however, it has become common in both game development and
the creation of desktop applications.</div>
</ng-template>
</e-accordionitem>
</e-accordionitems>
</ejs-accordion>
`
})
export class AppComponent {
}