ListGroup
The ListGroup component creates flexible, versatile lists for displaying content, navigation, and custom interfaces. Perfect for sidebars, settings panels, and any structured content display.
Goal
Master creating list groups with various styles, understand Bootstrap list-group classes, and build organized content displays that enhance user navigation.
Bootstrap Reference
Quick Start
- First item
- Second item
- Third item
Visual Examples & Use Cases
1. Active and Disabled Items
ListGroup(
ListGroupItem("Active item", active=True),
ListGroupItem("Normal item"),
ListGroupItem("Disabled item", disabled=True)
)
2. With Links - Interactive Lists
ListGroup(
ListGroupItem("Dashboard", href="/dashboard", action=True),
ListGroupItem("Settings", href="/settings", action=True),
ListGroupItem("Profile", href="/profile", action=True, active=True)
)
3. Color Variants
ListGroup(
ListGroupItem("Success", variant="success"),
ListGroupItem("Danger", variant="danger"),
ListGroupItem("Warning", variant="warning"),
ListGroupItem("Info", variant="info")
)
4. With Badges
from faststrap import ListGroup, ListGroupItem, Badge
ListGroup(
ListGroupItem(
"Inbox",
badge=Badge("12", variant="primary"),
href="/inbox",
action=True
),
ListGroupItem(
"Drafts",
badge=Badge("3", variant="secondary"),
href="/drafts",
action=True
)
)
5. Flush Style - Edge-to-Edge
ListGroup(
ListGroupItem("Item 1"),
ListGroupItem("Item 2"),
ListGroupItem("Item 3"),
flush=True # ← Removes borders
)
6. Horizontal Lists
# Horizontal on all screens
ListGroup(
ListGroupItem("Left"),
ListGroupItem("Center"),
ListGroupItem("Right"),
horizontal=True
)
# Horizontal on medium screens and up
ListGroup(
ListGroupItem("Item 1"),
ListGroupItem("Item 2"),
horizontal="md"
)
Bootstrap CSS Classes Explained
| Class | Purpose |
|---|---|
.list-group |
Container for list items |
.list-group-item |
Individual list item |
.list-group-item-action |
Hover/focus styles for interactive items |
.list-group-item-{variant} |
Color variants (success, danger, etc.) |
.list-group-flush |
Removes borders for edge-to-edge |
.list-group-horizontal |
Horizontal layout |
.active |
Active/selected state |
.disabled |
Disabled state |
Common Recipes
Settings Menu
from faststrap import ListGroup, ListGroupItem, Icon
ListGroup(
ListGroupItem(
Icon("person"), " Profile",
href="/settings/profile",
action=True,
active=True
),
ListGroupItem(
Icon("bell"), " Notifications",
href="/settings/notifications",
action=True
),
ListGroupItem(
Icon("shield-lock"), " Privacy",
href="/settings/privacy",
action=True
),
flush=True
)
Parameter Reference
ListGroup
| Parameter | Type | Default | Description |
|---|---|---|---|
*children |
Any |
Required | ListGroupItem components |
flush |
bool |
False |
Remove borders |
horizontal |
bool \| str |
False |
Horizontal layout (True or breakpoint) |
numbered |
bool |
False |
Numbered list |
**kwargs |
Any |
- | Additional HTML attributes |
ListGroupItem
| Parameter | Type | Default | Description |
|---|---|---|---|
*children |
Any |
Required | Item content |
variant |
VariantType \| None |
None |
Color variant |
active |
bool |
False |
Active state |
disabled |
bool |
False |
Disabled state |
action |
bool |
False |
Enable hover/focus styles |
href |
str \| None |
None |
Make item a link |
badge |
Any |
None |
Badge to display |
**kwargs |
Any |
- | Additional HTML attributes |
faststrap.components.navigation.listgroup.ListGroup(*children, flush=False, horizontal=False, numbered=False, **kwargs)
Bootstrap ListGroup component.
A flexible component for displaying lists of content.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*children
|
Any
|
ListGroupItem components or other content |
()
|
flush
|
bool
|
Remove borders for edge-to-edge display in parent containers |
False
|
horizontal
|
bool | Literal['sm', 'md', 'lg', 'xl', 'xxl']
|
Display items horizontally. True for all breakpoints, or specify breakpoint (sm, md, lg, xl, xxl) |
False
|
numbered
|
bool
|
Display numbered list |
False
|
**kwargs
|
Any
|
Additional HTML attributes (cls, id, hx-, data-, etc.) |
{}
|
Returns:
| Type | Description |
|---|---|
Ul | Div
|
FastHTML Ul or Div element with list-group structure |
Example
Basic list:
ListGroup( ... ListGroupItem("Item 1"), ... ListGroupItem("Item 2"), ... ListGroupItem("Item 3"), ... )
With active and disabled items:
ListGroup( ... ListGroupItem("Active", active=True), ... ListGroupItem("Normal"), ... ListGroupItem("Disabled", disabled=True), ... )
Flush style:
ListGroup( ... ListGroupItem("Edge to edge"), ... flush=True ... )
Horizontal:
ListGroup( ... ListGroupItem("Left"), ... ListGroupItem("Center"), ... ListGroupItem("Right"), ... horizontal=True ... )
See Also
Bootstrap docs: https://getbootstrap.com/docs/5.3/components/list-group/
Source code in src/faststrap/components/navigation/listgroup.py
faststrap.components.navigation.listgroup.ListGroupItem(*children, variant=None, active=False, disabled=False, action=False, href=None, badge=None, **kwargs)
Bootstrap ListGroup Item component.
A single item within a ListGroup.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*children
|
Any
|
Item content |
()
|
variant
|
VariantType | None
|
Bootstrap color variant for background |
None
|
active
|
bool
|
Mark item as active/selected |
False
|
disabled
|
bool
|
Disable the item |
False
|
action
|
bool
|
Enable hover/focus styles (for interactive items) |
False
|
href
|
str | None
|
Make item a link (renders as ) |
None
|
badge
|
Any
|
Optional badge to display on right side |
None
|
**kwargs
|
Any
|
Additional HTML attributes |
{}
|
Returns:
| Type | Description |
|---|---|
Li | A | Button
|
FastHTML Li, A, or Button element |
Example
Basic item:
ListGroupItem("Simple item")
Active with variant:
ListGroupItem("Selected", variant="primary", active=True)
Link item:
ListGroupItem("Click me", href="/page", action=True)
With badge:
ListGroupItem("Messages", badge=Badge("5", variant="primary"))
See Also
Bootstrap docs: https://getbootstrap.com/docs/5.3/components/list-group/
Source code in src/faststrap/components/navigation/listgroup.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |