Overview
A metric goes inside a card. It holds a large value, a trend row and a small line chart. The trend row shows the change and its comparison period, such as “+24% vs last week”.
Pick another component when:
- the value has no comparison period: a statistic card, a centered card with
nds-card-number - the chart is the focus, or it has more than one series: Chart
Markup
Variants
| Group | Option | Markup | On element | Use |
|---|---|---|---|---|
| Structure | Positive (default) | — | — | A trend that is good news. data-status="positive" on the card uses the success colors, and the icons are nds-hgi-trade-up |
| Structure | Negative (hint: A trend that is bad news) | canon #metric-negative |
— | A trend that is bad news. data-status="negative" on the card uses the error colors, and the icons are nds-hgi-trade-down |
| Layout | Compact (default) | — | — | The chart sits beside the value and takes half the row, with the trend under the value. Below 400px of metric width, the chart moves under the value, so a narrow card always stacks. Use it for a row of several metrics |
| Layout | Full (hint: The chart sits below the value, full width) | .nds-full |
.nds-card-metric |
The chart always sits below the value, across the full width. Use it for one metric that leads a section |
| Arrow | Arrow (hint: A plain arrow instead of the trade icon) | .nds-arrow |
.nds-card-metric-trend |
Shows a plain arrow in the trend row. Keep the icon’s class: .nds-arrow changes what the icon shows. The arrow follows the status, not the sign: positive points up, negative points down |
| Stroke | Stroke (default) | .nds-stroke |
.nds-card |
A 1px border on the card |
| Shadow | Shadow | .nds-shadow |
.nds-card |
An elevation shadow on the card. It combines with the stroke |
Built-in Features
-
Trend Status Theming
One
data-statuson the card colors the trend, the chart line and the header featured icon together. -
Inline Sparkline
The metric removes the chart's 200px minimum height, so a short chart fits in the card.
-
Always-LTR Sparklines
The chart reads from oldest to newest, left to right, on an RTL page too.
-
Dashboard Header
In a metric card, the title is smaller, the featured icon is SM, the buttons are MD (a corner button stays SM), and a divider sits above the actions. A menu button goes in the header's
.nds-card-corner, as in any card. -
Card Composition
A metric card is a normal card. Its classes, such as
nds-stroke,nds-shadowandnds-color, still set the border, shadow and color. -
Custom Colors
--metric-trend-colorand--metric-chart-colorreplace the status colors on one metric.
Best Practices
- Use metrics on dashboard pages, where people scan several values and their trends.
- Put a row of metrics in a grid. Set
--max-colon the grid to limit how many share a row. - Pick the status by meaning, not by the sign of the change. A falling bounce rate is
positive. - Write the sign in the change:
+24%,-32%. The trend icon is hidden from screen readers, so the text must carry the direction. - Keep the value short:
50%,SAR 1.2M,8,420. A long value wraps and pushes the chart down. - Give the chart at least 15 to 20 points. A short series does not show a clear trend.
- List the chart data from oldest to newest.
- Add an action, such as View Report, that opens the data behind the value.
- Give every icon-only button a name for screen readers: an
aria-label, or the hidden.nds-labelof a More button.
API
Classes
| Class | Inside | Effect |
|---|---|---|
nds-card-metric |
.nds-card-content |
Holds the value and the chart. The card around it gets the smaller title and the divider above the actions |
nds-card-metric-info |
.nds-card-metric |
Holds the value and the trend row |
nds-card-metric-value |
.nds-card-metric-info |
The large value. Its size scales with the screen |
nds-card-metric-trend |
.nds-card-metric-info |
The trend row: an icon, the change in <strong>, and the comparison period |
nds-card-metric-text |
.nds-card-metric-trend |
The comparison period, such as “vs last week” |
nds-card-metric-chart |
.nds-card-metric |
Holds the .nds-chart and keeps it left to right |
Data Attributes
| Attribute | Element | Effect |
|---|---|---|
data-status="positive" |
.nds-card |
Success colors on the trend, the chart and the featured icon. With .nds-arrow, the arrow points up |
data-status="negative" |
.nds-card |
Error colors on the same parts. With .nds-arrow, the arrow points down |
CSS Custom Properties
Set these on .nds-card-metric. There they win over the colors of data-status.
| Property | Default | Controls |
|---|---|---|
--metric-trend-color |
var(--text-default) |
Color of the trend icon and the change |
--metric-chart-color |
var(--colors-primary-600) |
Color of the chart line and its area |
Tokens
It reads these shared tokens. A change to one also changes other components: see Tokens.
Source: the var() reads in _sass/components/_metric.scss.
| Token | Preview | Value |
|---|---|---|
--background-successRead by --featuredicon-dark-bg | var(--colors-green-600) | |
--background-errorRead by --featuredicon-dark-bg | var(--colors-red-600) | |
--text-defaultRead by --metric-trend-color | var(--colors-base-black)Dark mode var(--colors-neutral-200) | |
--text-displayRead by color | var(--colors-neutral-800)Dark mode var(--colors-neutral-100) | |
--text-secondary-paragraphRead by color | var(--colors-neutral-500)Dark mode var(--colors-neutral-400) | |
--text-successRead by --metric-trend-color | var(--colors-green-700)Dark mode var(--colors-green-400) | |
--text-errorRead by --metric-trend-color | var(--colors-red-700)Dark mode var(--colors-red-400) | |
--border-successRead by --metric-chart-color | var(--colors-green-700)Dark mode var(--colors-green-500) | |
--border-errorRead by --metric-chart-color | var(--colors-red-700)Dark mode var(--colors-red-500) | |
--divider-colorRead by border-block-start | var(--colors-alpha-black-10)Dark mode var(--colors-alpha-white-10) | |
--featuredicons-icon-successRead by --featuredicon-color | var(--icon-success)Dark mode var(--colors-green-400) | |
--featuredicons-icon-errorRead by --featuredicon-color | var(--icon-error)Dark mode var(--colors-red-400) | |
--featuredicons-background-error-lightRead by --featuredicon-bg | var(--background-error-light)Dark mode var(--colors-red-alpha-10) | |
--featuredicons-background-success-lightRead by --featuredicon-bg | var(--background-success-light)Dark mode var(--colors-green-alpha-10) |
JavaScript
Metric has no script. The sparkline is a Chart, and its data-chart-* attributes are documented there.