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 |
|---|---|---|
label |
str |
Title of the metric (e.g. "Total Sales"). |
value |
str | int |
The main display number or value. |
icon |
str |
Bootstrap icon name. |
trend |
str |
Percentage or text indicating change (e.g. "+12%"). |
trend_label |
str |
Context for the trend (e.g. "since yesterday"). |
trend_variant |
str |
Color of trend text: success, danger, warning. |
variant |
str |
Color theme for the icon/label. |
faststrap.components.display.stat_card.StatCard(title, value, icon=None, trend=None, trend_type='neutral', variant=None, inverse=False, icon_bg=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 |
None
|
inverse
|
bool
|
Invert text colors (white text) |
False
|
icon_bg
|
str | None
|
Background color class for icon (e.g. "bg-primary-subtle") |
None
|
**kwargs
|
Any
|
Additional HTML attributes |
{}
|
Returns:
| Type | Description |
|---|---|
Div
|
Card component |
Example
StatCard("Revenue", "$50k", trend="+12%", trend_type="up")