List groups are a flexible and powerful component for displaying a series of content. Modify and extend them to support just about any content within.
Basic Example
import ListGroup from 'react-bootstrap/ListGroup' ;
function DefaultExample ( ) {
return (
< ListGroup >
< ListGroup.Item > Cras justo odio </ ListGroup.Item >
< ListGroup.Item > Dapibus ac facilisis in </ ListGroup.Item >
< ListGroup.Item > Morbi leo risus </ ListGroup.Item >
< ListGroup.Item > Porta ac consectetur ac </ ListGroup.Item >
< ListGroup.Item > Vestibulum at eros </ ListGroup.Item >
</ ListGroup >
) ;
}
export default DefaultExample ;
Active items
Set the active
prop to indicate the list groups current active selection.
import ListGroup from 'react-bootstrap/ListGroup' ;
function ActiveExample ( ) {
return (
< ListGroup as = " ul " >
< ListGroup.Item as = " li " active >
Cras justo odio
</ ListGroup.Item >
< ListGroup.Item as = " li " > Dapibus ac facilisis in </ ListGroup.Item >
< ListGroup.Item as = " li " disabled >
Morbi leo risus
</ ListGroup.Item >
< ListGroup.Item as = " li " > Porta ac consectetur ac </ ListGroup.Item >
</ ListGroup >
) ;
}
export default ActiveExample ;
Disabled items
Set the disabled
prop to prevent actions on a <ListGroup.Item>
. For elements
that aren't naturally disable-able (like anchors) onClick
handlers are added
that call preventDefault
to mimick disabled behavior.
import ListGroup from 'react-bootstrap/ListGroup' ;
function DisabledExample ( ) {
return (
< ListGroup >
< ListGroup.Item disabled > Cras justo odio </ ListGroup.Item >
< ListGroup.Item > Dapibus ac facilisis in </ ListGroup.Item >
< ListGroup.Item > Morbi leo risus </ ListGroup.Item >
< ListGroup.Item > Porta ac consectetur ac </ ListGroup.Item >
</ ListGroup >
) ;
}
export default DisabledExample ;
Actionable items
Toggle the action
prop to create actionable list group
items, with disabled, hover and active styles. List item actions will render
a <button>
or <a>
(depending on the presence of an href
) by default but
can be overridden by setting the as
prop as usual.
List items actions
are distinct from plain items to ensure that click or tap
affordances aren't applied to non-interactive items.
import ListGroup from 'react-bootstrap/ListGroup' ;
function LinkedExample ( ) {
const alertClicked = ( ) => {
alert ( 'You clicked the third ListGroupItem' ) ;
} ;
return (
< ListGroup defaultActiveKey = " #link1 " >
< ListGroup.Item action href = " #link1 " >
Link 1
</ ListGroup.Item >
< ListGroup.Item action href = " #link2 " disabled >
Link 2
</ ListGroup.Item >
< ListGroup.Item action onClick = { alertClicked } >
This one is a button
</ ListGroup.Item >
</ ListGroup >
) ;
}
export default LinkedExample ;
Flush
Add the flush
variant to remove outer borders and rounded corners to render list group items
edge-to-edge in a parent container such as a Card
.
import ListGroup from 'react-bootstrap/ListGroup' ;
function FlushExample ( ) {
return (
< ListGroup variant = " flush " >
< ListGroup.Item > Cras justo odio </ ListGroup.Item >
< ListGroup.Item > Dapibus ac facilisis in </ ListGroup.Item >
< ListGroup.Item > Morbi leo risus </ ListGroup.Item >
< ListGroup.Item > Porta ac consectetur ac </ ListGroup.Item >
</ ListGroup >
) ;
}
export default FlushExample ;
Numbered
Add the numbered
prop to opt into numbered list group items. Numbers are generated via CSS
(as opposed to a <ol>
s default browser styling) for better placement inside list group items
and to allow for better customization.
import ListGroup from 'react-bootstrap/ListGroup' ;
function NumberedExample ( ) {
return (
< ListGroup as = " ol " numbered >
< ListGroup.Item as = " li " > Cras justo odio </ ListGroup.Item >
< ListGroup.Item as = " li " > Cras justo odio </ ListGroup.Item >
< ListGroup.Item as = " li " > Cras justo odio </ ListGroup.Item >
</ ListGroup >
) ;
}
export default NumberedExample ;
These work great with custom content as well.
import Badge from 'react-bootstrap/Badge' ;
import ListGroup from 'react-bootstrap/ListGroup' ;
function DefaultExample ( ) {
return (
< ListGroup as = " ol " numbered >
< ListGroup.Item
as = " li "
className = " d-flex justify-content-between align-items-start "
>
< div className = " ms-2 me-auto " >
< div className = " fw-bold " > Subheading </ div >
Cras justo odio
</ div >
< Badge bg = " primary " pill >
14
</ Badge >
</ ListGroup.Item >
< ListGroup.Item
as = " li "
className = " d-flex justify-content-between align-items-start "
>
< div className = " ms-2 me-auto " >
< div className = " fw-bold " > Subheading </ div >
Cras justo odio
</ div >
< Badge bg = " primary " pill >
14
</ Badge >
</ ListGroup.Item >
< ListGroup.Item
as = " li "
className = " d-flex justify-content-between align-items-start "
>
< div className = " ms-2 me-auto " >
< div className = " fw-bold " > Subheading </ div >
Cras justo odio
</ div >
< Badge bg = " primary " pill >
14
</ Badge >
</ ListGroup.Item >
</ ListGroup >
) ;
}
export default DefaultExample ;
Horizontal
Use the horizontal
prop to make the ListGroup render horizontally. Currently horizontal list groups cannot be combined with flush list groups.
import ListGroup from 'react-bootstrap/ListGroup' ;
function HorizontalExample ( ) {
return (
< ListGroup horizontal >
< ListGroup.Item > This </ ListGroup.Item >
< ListGroup.Item > ListGroup </ ListGroup.Item >
< ListGroup.Item > renders </ ListGroup.Item >
< ListGroup.Item > horizontally! </ ListGroup.Item >
</ ListGroup >
) ;
}
export default HorizontalExample ;
There are responsive variants to horizontal
: setting it to {sm|md|lg|xl|xxl}
makes the list group horizontal starting at that breakpoint’s min-width
.
import ListGroup from 'react-bootstrap/ListGroup' ;
function HorizontalResponsiveExample ( ) {
return (
< >
{ [ 'sm' , 'md' , 'lg' , 'xl' , 'xxl' ] . map ( ( breakpoint ) => (
< ListGroup key = { breakpoint } horizontal = { breakpoint } className = " my-2 " >
< ListGroup.Item > This ListGroup </ ListGroup.Item >
< ListGroup.Item > renders horizontally </ ListGroup.Item >
< ListGroup.Item > on { breakpoint } </ ListGroup.Item >
< ListGroup.Item > and above! </ ListGroup.Item >
</ ListGroup >
) ) }
</ >
) ;
}
export default HorizontalResponsiveExample ;
Contextual classes
Use contextual variants on <ListGroup.Item>
s to style them with a stateful background and color.
import ListGroup from 'react-bootstrap/ListGroup' ;
function StyleExample ( ) {
return (
< ListGroup >
< ListGroup.Item > No style </ ListGroup.Item >
< ListGroup.Item variant = " primary " > Primary </ ListGroup.Item >
< ListGroup.Item variant = " secondary " > Secondary </ ListGroup.Item >
< ListGroup.Item variant = " success " > Success </ ListGroup.Item >
< ListGroup.Item variant = " danger " > Danger </ ListGroup.Item >
< ListGroup.Item variant = " warning " > Warning </ ListGroup.Item >
< ListGroup.Item variant = " info " > Info </ ListGroup.Item >
< ListGroup.Item variant = " light " > Light </ ListGroup.Item >
< ListGroup.Item variant = " dark " > Dark </ ListGroup.Item >
</ ListGroup >
) ;
}
export default StyleExample ;
When paired with action
s, additional hover and active styles apply.
import ListGroup from 'react-bootstrap/ListGroup' ;
function StyleActionsExample ( ) {
return (
< ListGroup >
< ListGroup.Item > No style </ ListGroup.Item >
< ListGroup.Item variant = " primary " > Primary </ ListGroup.Item >
< ListGroup.Item action variant = " secondary " >
Secondary
</ ListGroup.Item >
< ListGroup.Item action variant = " success " >
Success
</ ListGroup.Item >
< ListGroup.Item action variant = " danger " >
Danger
</ ListGroup.Item >
< ListGroup.Item action variant = " warning " >
Warning
</ ListGroup.Item >
< ListGroup.Item action variant = " info " >
Info
</ ListGroup.Item >
< ListGroup.Item action variant = " light " >
Light
</ ListGroup.Item >
< ListGroup.Item action variant = " dark " >
Dark
</ ListGroup.Item >
</ ListGroup >
) ;
}
export default StyleActionsExample ;
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.
Tabbed Interfaces
You can also use the [Tab][tabs] components to create ARIA compliant tabbable
interfaces with the <ListGroup>
component. Swap out the <Nav>
component
for the list group and you are good to go.
import Col from 'react-bootstrap/Col' ;
import ListGroup from 'react-bootstrap/ListGroup' ;
import Row from 'react-bootstrap/Row' ;
import Tab from 'react-bootstrap/Tab' ;
function TabsExample ( ) {
return (
< Tab.Container id = " list-group-tabs-example " defaultActiveKey = " #link1 " >
< Row >
< Col sm = { 4 } >
< ListGroup >
< ListGroup.Item action href = " #link1 " >
Link 1
</ ListGroup.Item >
< ListGroup.Item action href = " #link2 " >
Link 2
</ ListGroup.Item >
</ ListGroup >
</ Col >
< Col sm = { 8 } >
< Tab.Content >
< Tab.Pane eventKey = " #link1 " > Tab pane content 1 </ Tab.Pane >
< Tab.Pane eventKey = " #link2 " > Tab pane content 2 </ Tab.Pane >
</ Tab.Content >
</ Col >
</ Row >
</ Tab.Container >
) ;
}
export default TabsExample ;
API
ListGroup
ListGroupItem