Blazor Accordion
Build vertically collapsing accordions in combination with our Collapse component.
How it works #
The
Accordion
component uses the Collapse
component internally to make it collapsible.
INFO
The animation effect of this component is dependent on the
See the reduced motion section of our accessibility documentation.
prefers-reduced-motion
media query. See the reduced motion section of our accessibility documentation.
Examples #
Click the accordions below to expand/collapse the accordion content.
This is the first item's accordion body. It is shown 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 .accordion-body, though the transition does limit overflow.
This is the second item's accordion body. 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 .accordion-body, though the transition does limit overflow.
This is the third item's accordion body. 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 .accordion-body, though the transition does limit overflow.
<Accordion>
<AccordionItem Title="Accordion Item #1">
<Content>
<b>This is the first item's accordion body.</b> It is shown 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 .accordion-body, though the transition does limit overflow.
</Content>
</AccordionItem>
<AccordionItem Title="Accordion Item #2">
<Content>
<b>This is the second item's accordion body.</b> 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 .accordion-body, though the transition does limit overflow.
</Content>
</AccordionItem>
<AccordionItem Title="Accordion Item #3">
<Content>
<b>This is the third item's accordion body.</b> 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 .accordion-body, though the transition does limit overflow.
</Content>
</AccordionItem>
</Accordion>
Title with Icon #
To customize the accordion title, use
TitleTemplate
, as shown in the below example.
This is the first item's accordion body. It is shown 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 .accordion-body, though the transition does limit overflow.
This is the second item's accordion body. 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 .accordion-body, though the transition does limit overflow.
This is the third item's accordion body. 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 .accordion-body, though the transition does limit overflow.
<Accordion>
<AccordionItem>
<TitleTemplate>
<Icon Name="IconName.HouseFill" Class="me-1" /> Accordion Item #1
</TitleTemplate>
<Content>
<b>This is the first item's accordion body.</b> It is shown 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 .accordion-body, though the transition does limit overflow.
</Content>
</AccordionItem>
<AccordionItem>
<TitleTemplate>
<Icon Name="IconName.PersonFill" Class="me-1" /> Accordion Item #2
</TitleTemplate>
<Content>
<b>This is the second item's accordion body.</b> 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 .accordion-body, though the transition does limit overflow.
</Content>
</AccordionItem>
<AccordionItem>
<TitleTemplate>
<Icon Name="IconName.PhoneFill" Class="me-1" /> Accordion Item #3
</TitleTemplate>
<Content>
<b>This is the third item's accordion body.</b> 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 .accordion-body, though the transition does limit overflow.
</Content>
</AccordionItem>
</Accordion>
Flush #
Set the
Flush
parameter to true
to remove borders and rounded corners to render accordions edge-to-edge with their parent container.
Set default active accordion item #
Set the
Active
parameter to true
to keep the accordion item open by default.
Always open #
Set the
AlwaysOpen
parameter to true
to keep accordion items open when another item is opened.
Show / hide individual accordion items #
You can show and hide individual accordion items in several ways.
- To show an accordion item, use predefined methods
ShowFirstAccordionItemAsync
,ShowLastAccordionItemAsync
,ShowAccordionItemByNameAsync
, andShowAccordionItemByIndexAsync
. - To hide an accordion item, use predefined methods
HideFirstAccordionItemAsync
,HideLastAccordionItemAsync
,HideAccordionItemByNameAsync
, andHideAccordionItemByIndexAsync
.
Show / hide all accordion items #
When the
AlwaysOpen
parameter is set to true
, you can show all accordion items simultaneously using the ShowAllAccordionItemsAsync
method.
The HideAllAccordionItemsAsync
method will hide all accordion items, regardless of the value of AlwaysOpen
.
Events #
Blazor Bootstrap Accordion component exposes a few events for hooking into accordion functionality.
Event Name | Description |
---|---|
OnHiding |
This event is fired immediately when the hide method has been called. |
OnHidden |
This event is fired when a accordion item has been hidden from the user (will wait for CSS transitions to complete). |
OnShowing |
This event fires immediately when the show method is called. |
OnShown |
This event is fired when a accordion item has been made visible to the user (will wait for CSS transitions to complete). |
NOTE
If no accordion item is active, then the
OnHiding
and OnHidden
events will not be fired.