Basic Usage
At minimum, a Metric needs alabel and a value. The label names the statistic, and the value is the headline number that catches the eye. Values can be strings or raw numbers — strings are displayed as-is, so you have full control over formatting.
When the value comes from state, use reactive expressions with pipes to format it at display time. Here the raw number 42000000 becomes $42M by dividing, rounding, and wrapping in literal $ and M characters — no Python formatting needed.
Description
Add adescription for extra context below the headline number. This is the right place for time ranges, data sources, percentile qualifiers, or any caveat that helps readers interpret the number correctly. Without it, a value like “142ms” could mean anything — with it, the reader knows exactly what they’re looking at.
Trend Indicator
Pass adelta to show a change indicator alongside the value. Metric automatically infers the trend direction and color from the delta’s sign: positive deltas get a green up arrow, negative deltas get a red down arrow.
Inverted Sentiment
The auto-inference assumes “up is good, down is bad,” which works for most metrics but breaks for things like response time, error rates, or costs — anything where going up is bad news. Override the automatic coloring by settingtrend_sentiment explicitly. The arrow still points in the direction the number moved, but the color reflects whether that movement is good or bad.
Here response time increased by 18ms. Without the override, a positive delta would get a green arrow. Setting trend_sentiment="negative" makes it red, correctly signaling that slower is worse.
KPI Row
The classic dashboard header: a row of Metric cards spanning the top of a page. Wrap each Metric in a Card for visual separation and use a Grid to give every card equal width. This pattern scales naturally — add or remove cards and the grid reflows without manual width calculations.Dashboard Layout
Metrics work as the top row of a dashboard, with a chart below for detail. Usemin_column_width on the Grid so the metric cards reflow naturally at any container width.
With Sparklines
Place a Sparkline as a sibling to CardContent inside the Card. Usepb-0 gap-0 on the Card to eliminate spacing below the metric, so the sparkline bleeds flush to the bottom edge.
API Reference
Metric Parameters
The metric name displayed above the value (e.g.
"Revenue", "Active Users").The headline number. Strings are displayed as-is, so pre-format with currency symbols, commas, or units as needed.
Optional text below the value for additional context like time ranges or data sources.
Change indicator shown next to the value (e.g.
"+23.4%", "-15", "+$2.3M"). When present, an arrow icon and sentiment color are automatically inferred from the sign.Arrow direction:
"up", "down", or "neutral". Inferred from delta when omitted — positive deltas point up, negative point down.Color control:
"positive" (green), "negative" (red), or "neutral" (muted). Inferred from trend when omitted — up is positive, down is negative. Override this for inverted metrics where down is good (e.g. costs decreasing).Additional Tailwind CSS classes.
Protocol Reference
Metric