React List Group Component
List group
React List Group component allows displaying a series of content. Learn how to use react list group to build complex list structure on your website.
Other frameworks
CoreUI components are available as native Angular, Bootstrap (Vanilla JS), and Vue components. To learn more please visit the following pages.
Basic example#
The default list group is an unordered list with items and the proper CSS classes. Build upon it with the options that follow, or with your CSS as required.
- Cras justo odio
- Dapibus ac facilisis in
- Morbi leo risus
- Porta ac consectetur ac
- Vestibulum at eros
<CListGroup> <CListGroupItem>Cras justo odio</CListGroupItem> <CListGroupItem>Dapibus ac facilisis in</CListGroupItem> <CListGroupItem>Morbi leo risus</CListGroupItem> <CListGroupItem>Porta ac consectetur ac</CListGroupItem> <CListGroupItem>Vestibulum at eros</CListGroupItem></CListGroup>
Active items#
Add active
boolean property to a <CListGroupItem>
to show the current active selection.
- Cras justo odio
- Dapibus ac facilisis in
- Morbi leo risus
- Porta ac consectetur ac
- Vestibulum at eros
<CListGroup> <CListGroupItem active>Cras justo odio</CListGroupItem> <CListGroupItem>Dapibus ac facilisis in</CListGroupItem> <CListGroupItem>Morbi leo risus</CListGroupItem> <CListGroupItem>Porta ac consectetur ac</CListGroupItem> <CListGroupItem>Vestibulum at eros</CListGroupItem></CListGroup>
Disabled items#
Add disabled
boolean property to a <CListGroupItem>
to make it appear disabled.
- Cras justo odio
- Dapibus ac facilisis in
- Morbi leo risus
- Porta ac consectetur ac
- Vestibulum at eros
<CListGroup> <CListGroupItem disabled>Cras justo odio</CListGroupItem> <CListGroupItem>Dapibus ac facilisis in</CListGroupItem> <CListGroupItem>Morbi leo risus</CListGroupItem> <CListGroupItem>Porta ac consectetur ac</CListGroupItem> <CListGroupItem>Vestibulum at eros</CListGroupItem></CListGroup>
Links and buttons#
Use <a>
s or <button>
s to create actionable list group items with hover, disabled, and active states by adding as="a|button"
. We separate these pseudo-classes to ensure list groups made of non-interactive elements (like <li>
s or <div>
s) don't provide a click or tap affordance.
<CListGroup> <CListGroupItem as="a" href="#" active> Cras justo odio </CListGroupItem> <CListGroupItem as="a" href="#"> Dapibus ac facilisis in </CListGroupItem> <CListGroupItem as="a" href="#"> Morbi leo risus </CListGroupItem> <CListGroupItem as="a" href="#"> Porta ac consectetur ac </CListGroupItem> <CListGroupItem as="a" href="#" disabled> Vestibulum at eros </CListGroupItem></CListGroup>
<CListGroup> <CListGroupItem as="button" active> Cras justo odio </CListGroupItem> <CListGroupItem as="button">Dapibus ac facilisis in</CListGroupItem> <CListGroupItem as="button">Morbi leo risus</CListGroupItem> <CListGroupItem as="button">Porta ac consectetur ac</CListGroupItem> <CListGroupItem as="button" disabled> Vestibulum at eros </CListGroupItem></CListGroup>
Flush#
Add flush
boolean property to remove some borders and rounded corners to render list group items edge-to-edge in a parent container (e.g., cards).
- Cras justo odio
- Dapibus ac facilisis in
- Morbi leo risus
- Porta ac consectetur ac
- Vestibulum at eros
<CListGroup flush> <CListGroupItem>Cras justo odio</CListGroupItem> <CListGroupItem>Dapibus ac facilisis in</CListGroupItem> <CListGroupItem>Morbi leo risus</CListGroupItem> <CListGroupItem>Porta ac consectetur ac</CListGroupItem> <CListGroupItem>Vestibulum at eros</CListGroupItem></CListGroup>
Horizontal#
Add layout="horizontal"
to change the layout of list group items from vertical to horizontal across all breakpoints. Alternatively, choose a responsive variant .layout="horizontal-{sm|md|lg|xl|xxl}"
to make a list group horizontal starting at that breakpoint's min-width
. Currently horizontal list groups cannot be combined with flush list groups.
- Cras justo odio
- Dapibus ac facilisis in
- Morbi leo risus
- Cras justo odio
- Dapibus ac facilisis in
- Morbi leo risus
- Cras justo odio
- Dapibus ac facilisis in
- Morbi leo risus
- Cras justo odio
- Dapibus ac facilisis in
- Morbi leo risus
- Cras justo odio
- Dapibus ac facilisis in
- Morbi leo risus
- Cras justo odio
- Dapibus ac facilisis in
- Morbi leo risus
<> {['', '-sm', '-md', '-lg', '-xl', '-xxl'].map((breakpoint, index) => ( <CListGroup className="mb-2" layout={`horizontal${breakpoint}`} key={index}> <CListGroupItem>Cras justo odio</CListGroupItem> <CListGroupItem>Dapibus ac facilisis in</CListGroupItem> <CListGroupItem>Morbi leo risus</CListGroupItem> </CListGroup> ))}</>
Contextual classes#
Use contextual classes to style list items with a stateful background and color.
- Dapibus ac facilisis in
- A simple primary list group item
- A simple secondary list group item
- A simple success list group item
- A simple danger list group item
- A simple warning list group item
- A simple info list group item
- A simple light list group item
- A simple dark list group item
<CListGroup> <CListGroupItem>Dapibus ac facilisis in</CListGroupItem> {['primary', 'secondary', 'success', 'danger', 'warning', 'info', 'light', 'dark'].map( (color, index) => ( <CListGroupItem color={color} key={index}> A simple {color} list group item </CListGroupItem> ), )}</CListGroup>
Contextual classes also work with <a>
s or <button>
s. Note the addition of the hover styles here not present in the previous example. Also supported is the active
state; apply it to indicate an active selection on a contextual list group item.
<CListGroup> <CListGroupItem as="a" href="#"> Dapibus ac facilisis in </CListGroupItem> {['primary', 'secondary', 'success', 'danger', 'warning', 'info', 'light', 'dark'].map( (color, index) => ( <CListGroupItem as="a" href="#" color={color} key={index}> A simple {color} list group item </CListGroupItem> ), )}</CListGroup>
Conveying meaning to assistive technologies
Using color to add meaning only provides a visual indication, which will not be conveyed to
users of assistive technologies – such as screen readers. Ensure that information denoted by the
color is either obvious from the content itself (e.g. the visible text), or is included through
alternative means, such as additional text hidden with the .visually-hidden
class.
With badges#
Add badges to any list group item to show unread counts, activity, and more.
- Cras justo odio 14
- Dapibus ac facilisis in 2
- Morbi leo risus 1
<CListGroup> <CListGroupItem className="d-flex justify-content-between align-items-center"> Cras justo odio <CBadge color="primary" shape="rounded-pill"> 14 </CBadge> </CListGroupItem> <CListGroupItem className="d-flex justify-content-between align-items-center"> Dapibus ac facilisis in <CBadge color="primary" shape="rounded-pill"> 2 </CBadge> </CListGroupItem> <CListGroupItem className="d-flex justify-content-between align-items-center"> Morbi leo risus <CBadge color="primary" shape="rounded-pill"> 1 </CBadge> </CListGroupItem></CListGroup>
Custom content#
Add nearly any HTML within, even for linked list groups like the one below, with the help of flexbox utilities.
List group item heading
3 days agoDonec id elit non mi porta gravida at eget metus. Maecenas sed diam eget risus varius blandit.
Donec id elit non mi porta.List group item heading
3 days agoDonec id elit non mi porta gravida at eget metus. Maecenas sed diam eget risus varius blandit.
Donec id elit non mi porta.List group item heading
3 days agoDonec id elit non mi porta gravida at eget metus. Maecenas sed diam eget risus varius blandit.
Donec id elit non mi porta.<CListGroup> <CListGroupItem as="a" href="#" active> <div className="d-flex w-100 justify-content-between"> <h5 className="mb-1">List group item heading</h5> <small>3 days ago</small> </div> <p className="mb-1"> Donec id elit non mi porta gravida at eget metus. Maecenas sed diam eget risus varius blandit. </p> <small>Donec id elit non mi porta.</small> </CListGroupItem> <CListGroupItem as="a" href="#"> <div className="d-flex w-100 justify-content-between"> <h5 className="mb-1">List group item heading</h5> <small className="text-body-secondary">3 days ago</small> </div> <p className="mb-1"> Donec id elit non mi porta gravida at eget metus. Maecenas sed diam eget risus varius blandit. </p> <small className="text-body-secondary">Donec id elit non mi porta.</small> </CListGroupItem> <CListGroupItem as="a" href="#"> <div className="d-flex w-100 justify-content-between"> <h5 className="mb-1">List group item heading</h5> <small className="text-body-secondary">3 days ago</small> </div> <p className="mb-1"> Donec id elit non mi porta gravida at eget metus. Maecenas sed diam eget risus varius blandit. </p> <small className="text-body-secondary">Donec id elit non mi porta.</small> </CListGroupItem></CListGroup>
Checkboxes and radios#
Place CoreUI's checkboxes and radios within list group items and customize as needed.
<CListGroup> <CListGroupItem> <CFormCheck label="Cras justo odio" /> </CListGroupItem> <CListGroupItem> <CFormCheck label="Dapibus ac facilisis in" defaultChecked /> </CListGroupItem> <CListGroupItem> <CFormCheck label="Morbi leo risus" defaultChecked /> </CListGroupItem> <CListGroupItem> <CFormCheck label="orta ac consectetur ac" /> </CListGroupItem> <CListGroupItem> <CFormCheck label="Vestibulum at eros" /> </CListGroupItem></CListGroup>
And if you want <label>
s as the .list-group-item
for large hit areas, you can do that, too.
<CListGroup> <CListGroupItem> <CFormCheck hitArea="full" label="First checkbox" value="" id="firstCheckboxStretched" /> </CListGroupItem> <CListGroupItem> <CFormCheck hitArea="full" label="Second checkbox" value="" id="secondCheckboxStretched" defaultChecked/> </CListGroupItem> <CListGroupItem> <CFormCheck hitArea="full" label="Third checkbox" value="" id="thirdCheckboxStretched"/> </CListGroupItem></CListGroup>
Customizing#
CSS variables#
React list groups use local CSS variables on .list-group
for enhanced real-time customization. Values for the CSS variables are set via Sass, so Sass customization is still supported, too.
--cui-list-group-color: #{$list-group-color};--cui-list-group-bg: #{$list-group-bg};--cui-list-group-border-color: #{$list-group-border-color};--cui-list-group-border-width: #{$list-group-border-width};--cui-list-group-border-radius: #{$list-group-border-radius};--cui-list-group-item-padding-x: #{$list-group-item-padding-x};--cui-list-group-item-padding-y: #{$list-group-item-padding-y};--cui-list-group-action-color: #{$list-group-action-color};--cui-list-group-action-hover-color: #{$list-group-action-hover-color};--cui-list-group-action-hover-bg: #{$list-group-hover-bg};--cui-list-group-action-active-color: #{$list-group-action-active-color};--cui-list-group-action-active-bg: #{$list-group-action-active-bg};--cui-list-group-disabled-color: #{$list-group-disabled-color};--cui-list-group-disabled-bg: #{$list-group-disabled-bg};--cui-list-group-active-color: #{$list-group-active-color};--cui-list-group-active-bg: #{$list-group-active-bg};--cui-list-group-active-border-color: #{$list-group-active-border-color};
How to use CSS variables#
const vars = { '--my-css-var': 10, '--my-another-css-var': "red" }return <CListGroup style={vars}>...</CListGroup>
SASS variables#
$list-group-color: var(--cui-body-color) !default;$list-group-bg: var(--cui-body-bg) !default;$list-group-border-color: var(--cui-border-color) !default;$list-group-border-width: var(--cui-border-width) !default;$list-group-border-radius: var(--cui-border-radius) !default;
$list-group-item-padding-y: $spacer * .5 !default;$list-group-item-padding-x: $spacer !default;// fusv-disable$list-group-item-bg-scale: -80% !default; // Deprecated in v5.0.0$list-group-item-color-scale: 40% !default; // Deprecated in v5.0.0// fusv-enable
$list-group-hover-bg: var(--cui-tertiary-bg) !default;$list-group-active-color: $component-active-color !default;$list-group-active-bg: $component-active-bg !default;$list-group-active-border-color: $list-group-active-bg !default;
$list-group-disabled-color: var(--cui-secondary-color) !default;$list-group-disabled-bg: $list-group-bg !default;
$list-group-action-color: var(--cui-secondary-color) !default;$list-group-action-hover-color: var(--cui-emphasis-color) !default;
$list-group-action-active-color: var(--cui-body-color) !default;$list-group-action-active-bg: var(--cui-secondary-bg) !default;
API#
CListGroup#
import { CListGroup } from '@coreui/react'// orimport CListGroup from '@coreui/react/src/components/list-group/CListGroup'
Property | Description | Type | Default |
---|---|---|---|
as | Component used for the root node. Either a string to use a HTML element or a component. | (ElementType & 'symbol') | (ElementType & 'object') | (ElementType & 'ul') | (ElementType & 'slot') | (ElementType & 'style') | ... 174 more ... | (ElementType & FunctionComponent<...>) | - |
className | A string of all className you want applied to the component. | string | - |
flush | Remove some borders and rounded corners to render list group items edge-to-edge in a parent component (e.g., <CCard> ). | boolean | - |
layout | Specify a layout type. | 'horizontal' | 'horizontal-sm' | 'horizontal-md' | 'horizontal-lg' | 'horizontal-xl' | 'horizontal-xxl' | - |
CListGroupItem#
import { CListGroupItem } from '@coreui/react'// orimport CListGroupItem from '@coreui/react/src/components/list-group/CListGroupItem'
Property | Description | Type | Default |
---|---|---|---|
active | Toggle the active state for the component. | boolean | - |
as | Component used for the root node. Either a string to use a HTML element or a component. | (ElementType & 'symbol') | (ElementType & 'object') | (ElementType & 'li') | (ElementType & 'slot') | (ElementType & 'style') | ... 174 more ... | (ElementType & FunctionComponent<...>) | li |
className | A string of all className you want applied to the component. | string | - |
color | Sets the color context of the component to one of CoreUI’s themed colors. | 'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'info' | 'dark' | 'light' | string | - |
disabled | Toggle the disabled state for the component. | boolean | - |