Back to Angular

Accordion

adev/src/content/guide/aria/accordion.md

22.0.0-next.1013.3 KB
Original Source
<docs-decorative-header title="Accordion"> </docs-decorative-header> <docs-pill-row> <docs-pill href="https://www.w3.org/WAI/ARIA/apg/patterns/accordion/" title="Accordion ARIA pattern"/> <docs-pill href="/api?query=accordion#angular_aria_accordion" title="Accordion API Reference"/> </docs-pill-row>

Overview

An accordion organizes related content into expandable and collapsible sections, reducing page scrolling and helping users focus on relevant information. Each section has a trigger button and a content panel. Clicking a trigger toggles the visibility of its associated panel.

<docs-code-multifile preview hideCode path="adev/src/content/examples/aria/accordion/src/single-expansion/basic/app/app.ts"> <docs-code header="TS" path="adev/src/content/examples/aria/accordion/src/single-expansion/basic/app/app.ts"/> <docs-code header="HTML" path="adev/src/content/examples/aria/accordion/src/single-expansion/basic/app/app.html"/> <docs-code header="CSS" path="adev/src/content/examples/aria/accordion/src/single-expansion/basic/app/app.css"/> </docs-code-multifile>

Usage

Accordions work well for organizing content into logical groups where users typically need to view one section at a time.

Use accordions when:

  • Displaying FAQs with multiple questions and answers
  • Organizing long forms into manageable sections
  • Reducing scrolling on content-heavy pages
  • Progressively disclosing related information

Avoid accordions when:

  • Building navigation menus (use the Menu component instead)
  • Creating tabbed interfaces (use the Tabs component instead)
  • Showing a single collapsible section (use a disclosure pattern instead)
  • Users need to see multiple sections simultaneously (consider a different layout)

Features

  • Expansion modes - Control whether one or multiple panels can be open at the same time
  • Keyboard navigation - Navigate between triggers using arrow keys, Home, and End
  • Lazy rendering - Content is only created when a panel first expands, improving initial load performance
  • Disabled states - Disable the entire group or individual triggers
  • Focus management - Control whether disabled items can receive keyboard focus
  • Programmatic control - Expand, collapse, or toggle panels from your component code
  • RTL support - Automatic support for right-to-left languages

Examples

Single expansion mode

Set [multiExpandable]="false" to allow only one panel to be open at a time. Opening a new panel automatically closes any previously open panel.

<docs-tab-group> <docs-tab label="Basic"> <docs-code-multifile preview hideCode path="adev/src/content/examples/aria/accordion/src/single-expansion/basic/app/app.ts"> <docs-code header="TS" path="adev/src/content/examples/aria/accordion/src/single-expansion/basic/app/app.ts"/> <docs-code header="HTML" path="adev/src/content/examples/aria/accordion/src/single-expansion/basic/app/app.html"/> <docs-code header="CSS" path="adev/src/content/examples/aria/accordion/src/single-expansion/basic/app/app.css"/> </docs-code-multifile> </docs-tab> <docs-tab label="Material"> <docs-code-multifile preview hideCode path="adev/src/content/examples/aria/accordion/src/single-expansion/material/app/app.ts"> <docs-code header="TS" path="adev/src/content/examples/aria/accordion/src/single-expansion/material/app/app.ts"/> <docs-code header="HTML" path="adev/src/content/examples/aria/accordion/src/single-expansion/material/app/app.html"/> <docs-code header="CSS" path="adev/src/content/examples/aria/accordion/src/single-expansion/material/app/app.css"/> </docs-code-multifile> </docs-tab> <docs-tab label="Retro"> <docs-code-multifile preview hideCode path="adev/src/content/examples/aria/accordion/src/single-expansion/retro/app/app.ts"> <docs-code header="TS" path="adev/src/content/examples/aria/accordion/src/single-expansion/retro/app/app.ts"/> <docs-code header="HTML" path="adev/src/content/examples/aria/accordion/src/single-expansion/retro/app/app.html"/> <docs-code header="CSS" path="adev/src/content/examples/aria/accordion/src/single-expansion/retro/app/app.css"/> </docs-code-multifile> </docs-tab> </docs-tab-group>

This mode works well for FAQs or situations where you want users to focus on one answer at a time.

Multiple expansion mode

Set [multiExpandable]="true" to allow multiple panels to be open simultaneously. Users can expand as many panels as needed without closing others.

<docs-tab-group> <docs-tab label="Basic"> <docs-code-multifile preview hideCode path="adev/src/content/examples/aria/accordion/src/multi-expansion/basic/app/app.ts"> <docs-code header="TS" path="adev/src/content/examples/aria/accordion/src/multi-expansion/basic/app/app.ts"/> <docs-code header="HTML" path="adev/src/content/examples/aria/accordion/src/multi-expansion/basic/app/app.html"/> <docs-code header="CSS" path="adev/src/content/examples/aria/accordion/src/multi-expansion/basic/app/app.css"/> </docs-code-multifile> </docs-tab> <docs-tab label="Material"> <docs-code-multifile preview hideCode path="adev/src/content/examples/aria/accordion/src/multi-expansion/material/app/app.ts"> <docs-code header="TS" path="adev/src/content/examples/aria/accordion/src/multi-expansion/material/app/app.ts"/> <docs-code header="HTML" path="adev/src/content/examples/aria/accordion/src/multi-expansion/material/app/app.html"/> <docs-code header="CSS" path="adev/src/content/examples/aria/accordion/src/multi-expansion/material/app/app.css"/> </docs-code-multifile> </docs-tab> <docs-tab label="Retro"> <docs-code-multifile preview hideCode path="adev/src/content/examples/aria/accordion/src/multi-expansion/retro/app/app.ts"> <docs-code header="TS" path="adev/src/content/examples/aria/accordion/src/multi-expansion/retro/app/app.ts"/> <docs-code header="HTML" path="adev/src/content/examples/aria/accordion/src/multi-expansion/retro/app/app.html"/> <docs-code header="CSS" path="adev/src/content/examples/aria/accordion/src/multi-expansion/retro/app/app.css"/> </docs-code-multifile> </docs-tab> </docs-tab-group>

This mode is useful for form sections or when users need to compare content across multiple panels.

NOTE: The multiExpandable input defaults to true. Set it to false explicitly if you want single expansion behavior.

Disabled accordion items

Disable specific triggers using the disabled input. Control how disabled items behave during keyboard navigation using the softDisabled input on the accordion group.

<docs-tab-group> <docs-tab label="Basic"> <docs-code-multifile preview hideCode path="adev/src/content/examples/aria/accordion/src/disabled-focusable/basic/app/app.ts"> <docs-code header="TS" path="adev/src/content/examples/aria/accordion/src/disabled-focusable/basic/app/app.ts"/> <docs-code header="HTML" path="adev/src/content/examples/aria/accordion/src/disabled-focusable/basic/app/app.html"/> <docs-code header="CSS" path="adev/src/content/examples/aria/accordion/src/disabled-focusable/basic/app/app.css"/> </docs-code-multifile> </docs-tab> <docs-tab label="Material"> <docs-code-multifile preview hideCode path="adev/src/content/examples/aria/accordion/src/disabled-focusable/material/app/app.ts"> <docs-code header="TS" path="adev/src/content/examples/aria/accordion/src/disabled-focusable/material/app/app.ts"/> <docs-code header="HTML" path="adev/src/content/examples/aria/accordion/src/disabled-focusable/material/app/app.html"/> <docs-code header="CSS" path="adev/src/content/examples/aria/accordion/src/disabled-focusable/material/app/app.css"/> </docs-code-multifile> </docs-tab> <docs-tab label="Retro"> <docs-code-multifile preview hideCode path="adev/src/content/examples/aria/accordion/src/disabled-focusable/retro/app/app.ts"> <docs-code header="TS" path="adev/src/content/examples/aria/accordion/src/disabled-focusable/retro/app/app.ts"/> <docs-code header="HTML" path="adev/src/content/examples/aria/accordion/src/disabled-focusable/retro/app/app.html"/> <docs-code header="CSS" path="adev/src/content/examples/aria/accordion/src/disabled-focusable/retro/app/app.css"/> </docs-code-multifile> </docs-tab> </docs-tab-group>

When [softDisabled]="true" (the default), disabled items can receive focus but cannot be activated. When [softDisabled]="false", disabled items are skipped entirely during keyboard navigation.

Lazy content rendering

Use the ngAccordionContent directive on an ng-template to defer rendering content until the panel first expands. This improves performance for accordions with heavy content like images, charts, or complex components.

angular-html
<div ngAccordionGroup>
  <div>
    <button ngAccordionTrigger panelId="item-1">Trigger Text</button>
    <div ngAccordionPanel panelId="item-1">
      <ng-template ngAccordionContent>
        <!-- This content only renders when the panel first opens -->
        
        <app-expensive-component />
      </ng-template>
    </div>
  </div>
</div>

By default, content remains in the DOM after the panel collapses. Set [preserveContent]="false" to remove the content from the DOM when the panel closes.

APIs

AccordionGroup

The container directive that manages keyboard navigation and expansion behavior for a group of accordion items.

Inputs

PropertyTypeDefaultDescription
disabledbooleanfalseDisables all triggers in the group
multiExpandablebooleantrueWhether multiple panels can be expanded simultaneously
softDisabledbooleantrueWhen true, disabled items are focusable. When false, they are skipped
wrapbooleanfalseWhether keyboard navigation wraps from last to first item and vice versa

Methods

MethodParametersDescription
expandAllnoneExpands all panels (only works when multiExpandable is true)
collapseAllnoneCollapses all panels

AccordionTrigger

The directive applied to the button element that toggles panel visibility.

Inputs

PropertyTypeDefaultDescription
idstringautoUnique identifier for the trigger
panelIdstringRequired. Must match the panelId of the associated panel
disabledbooleanfalseDisables this trigger
expandedbooleanfalseWhether the panel is expanded (supports two-way binding)

Signals

PropertyTypeDescription
activeSignal<boolean>Whether the trigger currently has focus

Methods

MethodParametersDescription
expandnoneExpands the associated panel
collapsenoneCollapses the associated panel
togglenoneToggles the panel expansion state

AccordionPanel

The directive applied to the element containing the collapsible content.

Inputs

PropertyTypeDefaultDescription
idstringautoUnique identifier for the panel
panelIdstringRequired. Must match the panelId of the associated trigger
preserveContentbooleantrueWhether to keep content in DOM after panel collapses

Signals

PropertyTypeDescription
visibleSignal<boolean>Whether the panel is currently expanded

Methods

MethodParametersDescription
expandnoneExpands this panel
collapsenoneCollapses this panel
togglenoneToggles the expansion state

AccordionContent

The structural directive applied to an ng-template inside an accordion panel to enable lazy rendering.

This directive has no inputs, outputs, or methods. Apply it to an ng-template element:

angular-html
<div ngAccordionPanel panelId="item-1">
  <ng-template ngAccordionContent>
    <!-- Content here is lazily rendered -->
  </ng-template>
</div>