Stat Card
Stat cards are used on dashboards and reports to highlight key metrics. They typically include a title, a value, an optional icon, and a trend indicator (up/down).
Quick Start
Total Revenue
$45,231.89 +20.1%
v0.6.0 Metric Cards
FastStrap also ships specialized dashboard cards:
MetricCard("Revenue", "$128k", delta="+12%", delta_type="up")
TrendCard("Active Users", "9,842", sparkline="<svg></svg>", sparkline_safe=True)
KPICard(
"KPIs",
metrics=[("Retention", "84%", "+2%", "up"), ("Churn", "3.1%", "-0.4%", "down")],
)
MetricCard
MetricCard extends StatCard with a compact delta indicator.
TrendCard
TrendCard adds a sparkline slot. Use sparkline_safe=True only with trusted SVG or HTML.
KPICard
KPICard renders multiple metrics inside one card.
KPICard(
"KPIs",
metrics=[
("Retention", "84%", "+2%", "up"),
("Churn", "3.1%", "-0.4%", "down"),
],
)
Visual Examples & Use Cases
1. Negative Trends
Use trend_variant="danger" for decreases in metrics.
Active Users
1,234 -5%
from last month
2. Branding (Variants)
Apply color to the icon or card borders using the variant argument.
Parameter Reference
| FastStrap Param | Type | Description |
|---|---|---|
title |
str |
Title of the metric, such as "Total Sales". |
value |
str | int | float |
The main display number or value. |
icon |
Any | None |
Optional icon/component slot. |
trend |
str | None |
Percentage or text indicating change, such as "+12%". |
trend_type |
"up" | "down" | "neutral" |
Semantic trend color. |
delta |
str | int | float | None |
Alias for trend, useful when composing KPI-style APIs. |
delta_type |
"up" | "down" | "neutral" | None |
Alias for trend_type when using delta. |
variant |
str | None |
Bootstrap card background variant. |
inverse |
bool |
Use inverse text colors for dark variant cards. |
icon_bg |
str | None |
Bootstrap class for the icon background. |
StatCard also adds the faststrap-stat-card class so apps can theme metric cards consistently.
faststrap.components.display.stat_card.StatCard(title, value, icon=None, trend=None, trend_type='neutral', variant=UNSET, inverse=False, icon_bg=UNSET, delta=None, delta_type=None, **kwargs)
Bootstrap Statistic Card component.
Display a metric with optional icon and trend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str
|
Label for the statistic |
required |
value
|
str | int | float
|
The numeric or text value |
required |
icon
|
Any | None
|
Icon component to display |
None
|
trend
|
str | None
|
Trend text (e.g. "+5%") |
None
|
trend_type
|
Literal['up', 'down', 'neutral']
|
"up" (green), "down" (red), or "neutral" (muted) |
'neutral'
|
variant
|
VariantType | None
|
Card background variant |
UNSET
|
inverse
|
bool
|
Invert text colors (white text) |
False
|
icon_bg
|
str | None
|
Background color class for icon (e.g. "bg-primary-subtle") |
UNSET
|
delta
|
str | int | float | None
|
Alias for trend, useful for KPI-style APIs |
None
|
delta_type
|
Literal['up', 'down', 'neutral'] | None
|
Alias for trend_type when using delta |
None
|
**kwargs
|
Any
|
Additional HTML attributes |
{}
|
Returns:
| Type | Description |
|---|---|
Div
|
Card component |
Examples:
Source code in src/faststrap/components/display/stat_card.py
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 | |