React Accordion Component
Accordion
Build vertically collapsing accordions in combination with our React Accordion component.
Other frameworks
CoreUI components are available as native Angular, Bootstrap (Vanilla JS), and Vue components. To learn more please visit the following pages.
How to use React Accordion component.#
Click the accordions below to expand/collapse the accordion content.
.accordion-body
, though the transition does limit overflow. .accordion-body
, though the transition does limit overflow. .accordion-body
, though the transition does limit overflow. <CAccordion activeItemKey={2}> <CAccordionItem itemKey={1}> <CAccordionHeader>Accordion Item #1</CAccordionHeader> <CAccordionBody> <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. </CAccordionBody> </CAccordionItem> <CAccordionItem itemKey={2}> <CAccordionHeader>Accordion Item #2</CAccordionHeader> <CAccordionBody> <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. </CAccordionBody> </CAccordionItem> <CAccordionItem itemKey={3}> <CAccordionHeader>Accordion Item #3</CAccordionHeader> <CAccordionBody> <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. </CAccordionBody> </CAccordionItem></CAccordion>
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.
.accordion-body
, though the transition does limit overflow. .accordion-body
, though the transition does limit overflow. .accordion-body
, though the transition does limit overflow. <CAccordion flush> <CAccordionItem itemKey={1}> <CAccordionHeader>Accordion Item #1</CAccordionHeader> <CAccordionBody> <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. </CAccordionBody> </CAccordionItem> <CAccordionItem itemKey={2}> <CAccordionHeader>Accordion Item #2</CAccordionHeader> <CAccordionBody> <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. </CAccordionBody> </CAccordionItem> <CAccordionItem itemKey={3}> <CAccordionHeader>Accordion Item #3</CAccordionHeader> <CAccordionBody> <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. </CAccordionBody> </CAccordionItem></CAccordion>
Always open#
Add alwaysOpen
property to make react accordion items stay open when another item is opened.
.accordion-body
, though the transition does limit overflow. .accordion-body
, though the transition does limit overflow. .accordion-body
, though the transition does limit overflow. <CAccordion alwaysOpen activeItemKey={2}> <CAccordionItem itemKey={1}> <CAccordionHeader>Accordion Item #1</CAccordionHeader> <CAccordionBody> <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. </CAccordionBody> </CAccordionItem> <CAccordionItem itemKey={2}> <CAccordionHeader>Accordion Item #2</CAccordionHeader> <CAccordionBody> <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. </CAccordionBody> </CAccordionItem> <CAccordionItem itemKey={3}> <CAccordionHeader>Accordion Item #3</CAccordionHeader> <CAccordionBody> <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. </CAccordionBody> </CAccordionItem></CAccordion>
Customizing#
CSS variables#
React accordions use local CSS variables on .accordion
for enhanced real-time customization. Values for the CSS variables are set via Sass, so Sass customization is still supported, too.
--cui-accordion-color: #{$accordion-color};--cui-accordion-bg: #{$accordion-bg};--cui-accordion-transition: #{$accordion-transition};--cui-accordion-border-color: #{$accordion-border-color};--cui-accordion-border-width: #{$accordion-border-width};--cui-accordion-border-radius: #{$accordion-border-radius};--cui-accordion-inner-border-radius: #{$accordion-inner-border-radius};--cui-accordion-btn-padding-x: #{$accordion-button-padding-x};--cui-accordion-btn-padding-y: #{$accordion-button-padding-y};--cui-accordion-btn-color: #{$accordion-button-color};--cui-accordion-btn-bg: #{$accordion-button-bg};--cui-accordion-btn-icon: #{escape-svg($accordion-button-icon)};--cui-accordion-btn-icon-width: #{$accordion-icon-width};--cui-accordion-btn-icon-transform: #{$accordion-icon-transform};--cui-accordion-btn-icon-transition: #{$accordion-icon-transition};--cui-accordion-btn-active-icon: #{escape-svg($accordion-button-active-icon)};--cui-accordion-btn-focus-box-shadow: #{$accordion-button-focus-box-shadow};--cui-accordion-body-padding-x: #{$accordion-body-padding-x};--cui-accordion-body-padding-y: #{$accordion-body-padding-y};--cui-accordion-active-color: #{$accordion-button-active-color};--cui-accordion-active-bg: #{$accordion-button-active-bg};
How to use CSS variables#
const vars = { '--my-css-var': 10, '--my-another-css-var': "red" }return <CAccordion style={vars}>...</CAccordion>
SASS variables#
$accordion-padding-y: 1rem !default;$accordion-padding-x: 1.25rem !default;$accordion-color: var(--cui-body-color) !default;$accordion-bg: var(--cui-body-bg) !default;$accordion-border-width: var(--cui-border-width) !default;$accordion-border-color: var(--cui-border-color) !default;$accordion-border-radius: var(--cui-border-radius) !default;$accordion-inner-border-radius: subtract($accordion-border-radius, $accordion-border-width) !default;
$accordion-body-padding-y: $accordion-padding-y !default;$accordion-body-padding-x: $accordion-padding-x !default;
$accordion-button-padding-y: $accordion-padding-y !default;$accordion-button-padding-x: $accordion-padding-x !default;$accordion-button-color: var(--cui-body-color) !default;$accordion-button-bg: var(--cui-accordion-bg) !default;$accordion-transition: $btn-transition, border-radius .15s ease !default;$accordion-button-active-bg: var(--cui-primary-bg-subtle) !default;$accordion-button-active-color: var(--cui-primary-text-emphasis) !default;
// fusv-disable$accordion-button-focus-border-color: $input-focus-border-color !default; // Deprecated in v5.0.0// fusv-enable$accordion-button-focus-box-shadow: $btn-focus-box-shadow !default;
$accordion-icon-width: 1.25rem !default;$accordion-icon-color: $body-color !default;$accordion-icon-active-color: $primary-text-emphasis !default;$accordion-icon-transition: transform .2s ease-in-out !default;$accordion-icon-transform: rotate(-180deg) !default;
$accordion-button-icon: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='#{$accordion-icon-color}' stroke-linecap='round' stroke-linejoin='round'><path d='m2 5 6 6 6-6'/></svg>") !default;$accordion-button-active-icon: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='#{$accordion-icon-active-color}' stroke-linecap='round' stroke-linejoin='round'><path d='m2 5 6 6 6-6'/></svg>") !default;
API#
CAccordion#
import { CAccordion } from '@coreui/react'// orimport CAccordion from '@coreui/react/src/components/accordion/CAccordion'
Property | Description | Type | Default |
---|---|---|---|
activeItemKey | The active item key. | string | number | - |
alwaysOpen | Make accordion items stay open when another item is opened | boolean | false |
className | A string of all className you want applied to the base component. | string | - |
flush | Removes the default background-color, some borders, and some rounded corners to render accordions edge-to-edge with their parent container. | boolean | - |
CAccordionBody#
import { CAccordionBody } from '@coreui/react'// orimport CAccordionBody from '@coreui/react/src/components/accordion/CAccordionBody'
Property | Description | Type | Default |
---|---|---|---|
className | A string of all className you want applied to the base component. | string | - |
CAccordionHeader#
import { CAccordionHeader } from '@coreui/react'// orimport CAccordionHeader from '@coreui/react/src/components/accordion/CAccordionHeader'
Property | Description | Type | Default |
---|---|---|---|
className | A string of all className you want applied to the base component. | string | - |
CAccordionItem#
import { CAccordionItem } from '@coreui/react'// orimport CAccordionItem from '@coreui/react/src/components/accordion/CAccordionItem'
Property | Description | Type | Default |
---|---|---|---|
className | A string of all className you want applied to the base component. | string | - |
itemKey | Item key. | string | number | - |