Skip to main content

Collapse

Show and hide content. Bootstrap 6 animates the size in CSS, so there is no JavaScript animation code.

Bootstrap’s collapse docs describe the markup and CSS.

Example

Give the collapse a template reference and pass it to bsCollapseToggle. The toggle keeps aria-expanded and aria-controls up to date.

Some placeholder content for the collapse component. This panel is hidden by default and revealed when the user activates the toggle.
HTML
<p class="d-flex gap-2">
  <button type="button" bsButton theme="primary" [bsCollapseToggle]="details">
    Toggle details
  </button>
</p>
<div bsCollapse #details="bsCollapse">
  <div class="card card-body">
    Some placeholder content for the collapse component. This panel is hidden by default and
    revealed when the user activates the toggle.
  </div>
</div>

Two-way binding

Bind [(open)] to control the collapse from any element. shown and hidden emit after the transition.

Advanced options go here.

Events: none

<div bsFormField class="mb-3">
  <input type="checkbox" bsCheck [checked]="open()" (change)="open.set(!open())" />
  <label bsLabel>Show advanced options</label>
</div>
<div bsCollapse [(open)]="open" (shown)="log('shown')" (hidden)="log('hidden')">
  <div class="card card-body">Advanced options go here.</div>
</div>
<p class="mt-3 mb-0 fs-sm fg-3">Events: {{ events().join(', ') || 'none' }}</p>

Horizontal

Add horizontal to animate the width. Give the child element a fixed width.

This is some placeholder content for a horizontal collapse.
HTML
<p>
  <button type="button" bsButton theme="primary" [bsCollapseToggle]="side">Toggle width</button>
</p>
<div style="min-height: 120px">
  <div bsCollapse horizontal #side="bsCollapse">
    <div class="card card-body" style="width: 300px">
      This is some placeholder content for a horizontal collapse.
    </div>
  </div>
</div>

API

BsCollapse

Selector: [bsCollapse] · Exported as: bsCollapse

Inputs

NameTypeDefaultDescription
openbooleanfalseWhether the content is shown. Supports [(open)].
horizontalbooleanfalseAnimates the width instead of the height.
idstringgeneratedElement id, used for aria-controls.

Outputs

NameTypeDescription
openChangebooleanEmits when a method or toggle changes the state.
shownvoidEmits after the content is shown.
hiddenvoidEmits after the content is hidden.

Methods

NameTypeDescription
show()voidShows the content.
hide()voidHides the content.
toggle()voidToggles the content.
isOpenSignal<boolean>Current open state.

BsCollapseToggle

Selector: [bsCollapseToggle]

Inputs

NameTypeDefaultDescription
bsCollapseToggleBsCollapserequiredThe collapse to toggle.