Card
Cards are flexible and extensible content containers. They include options for headers and footers, a wide variety of content, contextual background colors, and powerful display options.
Bootstrap Reference
Quick Start
Visual Examples & Use Cases
1. Images & Structure
Cards commonly contain images at the top (img_top) or bottom (img_bottom).
Card Image Cap
Some quick example text to build on the card title.
2. Semantic Variants
Apply background colors with text-bg-{variant} classes by using the variant argument.
Code & Output
Success
Success Card
Error
Danger Card
Dark
Dark Card
3. Slot Class Customization 🛠️
FastStrap Cards have specialized "slots" for customization. You don't have to overwrite the base classes; just inject your own into specific parts.
| Slot Param | Targeting | Description |
|---|---|---|
header_cls |
.card-header |
Styles the header container. |
body_cls |
.card-body |
Styles the main content area. |
footer_cls |
.card-footer |
Styles the footer. |
title_cls |
.card-title |
Styles the H5 title. |
Parameter Reference
faststrap.components.display.card.Card(*children, title=None, subtitle=None, header=None, footer=None, img_top=None, img_bottom=None, img_overlay=False, header_cls=None, body_cls=None, footer_cls=None, title_cls=None, subtitle_cls=None, text_cls=None, **kwargs)
Bootstrap Card component for flexible content containers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*children
|
Any
|
Card body content |
()
|
title
|
str | None
|
Card title (styled with card-title) |
None
|
subtitle
|
str | None
|
Card subtitle (styled with card-subtitle) |
None
|
header
|
Any | None
|
Card header content (separate section above body) |
None
|
footer
|
Any | None
|
Card footer content (separate section below body) |
None
|
img_top
|
str | None
|
Image URL for top of card |
None
|
img_bottom
|
str | None
|
Image URL for bottom of card |
None
|
img_overlay
|
bool
|
Use image as background with overlay text |
False
|
**kwargs
|
Any
|
Additional HTML attributes (cls, id, hx-, data-, etc.) |
{}
|
Returns:
| Type | Description |
|---|---|
Div
|
FastHTML Div element with card structure |
Example
Basic card:
Card("Card content", title="Card Title")
With header and footer:
Card( ... "Main content", ... title="Title", ... header="Featured", ... footer="Last updated 3 mins ago" ... )
Source code in src/faststrap/components/display/card.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 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 | |