Menu


Sparkline


A small line beside a figure that shows how it moved: rising, falling, steady or spiky. The figure carries the meaning.

Customize the preview


Flags
View

Options


Sparkline options
ChoiceValuesDefaultWhat it does
areasmbk-sparkline--areaOn or offOff
The soft fill under the line.

Partssmbk-sparkline__plotsmbk-sparkline__svgsmbk-sparkline__areasmbk-sparkline__linesmbk-sparkline__dot

Examples


Usage

Under a figure and its change in words, which carry the meaning; the sparkline only shows the shape of the last 30 days.

Visits

12,480

Up 12% on the last 30 days

Rising

A figure going up: the line ends in a dot on the newest value.

Falling

A figure going down.

Steady

A figure that barely moves keeps to the middle of the band.

Spiky

Mostly level with a few peaks. The curve never swings past a value, so every peak is in the data.

Without the area

The line alone, without the soft fill under it.

Guidelines


Purpose

Shows at a glance how a figure has moved: rising, falling, steady or spiky. It is the smallest chart, a line with no axes, drawn beside the figure it belongs to, which carries the meaning. It differs from a line chart, which has axes, a legend and values a reader can read off.

When to use

  • Beside a figure on a card or in a table row, to show its trend over the last days or weeks.
  • Several figures side by side, each with its own sparkline on one shared scale.

When not to use

  • When the reader needs to read values off the line, compare series or see dates. Use a line chart.
  • When the figure has no history worth showing. Leave it out rather than draw a flat line.
  • As the only place a trend is told. Say it in words too, such as "up 12% on last week".

Usage rules

Do

  • Put the figure first and the sparkline beside or under it.
  • Give sparklines side by side one shared scale, so their slopes compare.
  • Keep the area for a single sparkline that stands on its own; side by side, the lines alone read cleaner.

Don't

  • Leave the sparkline to tell the trend alone.
  • Draw a sparkline from two or three values; a figure and its change in words say it better.

Revenue

$48,200

Up 6% on last month

Do

Put the figure first and say its change in words; the sparkline shows the shape.

Don't

A sparkline on its own leaves the reader to guess what moved and by how much.

Anatomy

  • The block, as wide as the space it is given and as tall as a small control.
  • The plot part, as big as the block, holding the svg and dot parts.
  • The svg part, holding the area part, a soft fill of the line's color down to the foot, shown with the area flag, and the line part, through the values from the oldest at the left to the newest at the right.
  • The dot part, on the last value, which stays round however wide the sparkline is.

Behavior

The wrapper draws the line from the values it is given, as a smooth curve that never swings past a value, scaled from the lowest to the highest value unless a shared scale is given. Values that are all the same draw a level line halfway up. The line keeps its width and the dot stays round as the sparkline stretches. The first time it comes into view the line is uncovered from left to right, and later changes to the values land at once. Under reduced motion, and in markup written by hand, it appears at once. Nothing takes focus.

Accessibility


What it does for you

  • The figure beside it carries the meaning, so the sparkline is hidden from screen readers unless it is given a summary, such as "Visits rising over 30 days", which it then carries as an image's name.
  • Nothing about it takes focus.
  • In high contrast mode the line and the dot take the text color and the area is left out.

What you must do

  • Say the trend in words beside the figure, so a reader who cannot see the line still has it.

How to test

  • With a screen reader, a sparkline with no summary is skipped, and one with a summary is read as an image by those words.
  • Tab through the page: focus never lands on the sparkline.
  • In a forced-color mode, the line and the dot show in the text color.

Source


The files the sparkline is made of. Its folder on GitHub (opens in a new tab) holds them with its wrapper and its document.

Stylesheet
sparkline.css
/* smbk-sparkline — Sparkline. Figma "Sparkline" 7580:152.
 * A small line in the series color, drawn from its values with no axes, ending in a dot on the last value;
 * with the area flag, a soft fill of the same color under it. It fills the width it is given and is as tall as
 * a small control. The SVG stretches to fit; the line keeps its width and the dot stays round, because the dot
 * is drawn outside the SVG. The plot holds the SVG and the dot, the same size as the block. The first time it
 * comes into view it is uncovered from left to right; nothing else moves. */

.smbk-sparkline {
  position: relative;
  display: block;
  width: 100%;
  min-width: 0;
  height: var(--smbk-size-32);
}

/* The plot is the block's own box again, so its entrance clip never clips the block: Chromium's intersection
   observer counts a clip on the element it watches, and a block clipped to nothing never came into view. */
.smbk-sparkline__plot {
  position: relative;
  display: block;
  height: 100%;
}

.smbk-sparkline__svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.smbk-sparkline__line {
  fill: none;
  stroke: var(--smbk-color-data-series);
  stroke-width: var(--smbk-border-width-emphasis);
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.smbk-sparkline__area {
  fill: var(--smbk-color-data-series);
  fill-opacity: var(--smbk-opacity-ghost);
  stroke: none;
}

/* The end dot sits on the last value, centred on it, half past the right edge as Figma draws it. */
.smbk-sparkline__dot {
  position: absolute;
  width: var(--smbk-size-6);
  height: var(--smbk-size-6);
  border-radius: var(--smbk-radius-full);
  background: var(--smbk-color-data-series);
  translate: -50% -50%;
}

/* ---- motion: the entrance ----
   The wrapper marks the sparkline `data-entrance` the first time it comes into view (simbolik/components/entrance.ts):
   waiting while it is out of view, hidden; playing once it is seen, the line, its area and the end dot uncovered
   from left to right with the chart entrance purpose, as one edge moving across. The clip is on the plot, never on
   the block, which the entrance watches. The edges run a little past the sparkline, so the dot half past its end
   is never cut once uncovered. Without the mark (markup written by hand,
   the rendered pictures, after the entrance) it is simply drawn, and under reduced motion nothing moves. Only the
   clip changes, so nothing shifts. */

@media screen and (prefers-reduced-motion: no-preference) {
  .smbk-sparkline[data-entrance="waiting"] .smbk-sparkline__plot {
    clip-path: inset(-50% calc(100% + var(--smbk-size-6)) -50% calc(-1 * var(--smbk-size-6)));
  }

  .smbk-sparkline:is([data-entrance="load"], [data-entrance="playing"]) .smbk-sparkline__plot {
    animation: smbk-sparkline-reveal var(--smbk-motion-chart-entrance-reveal-duration) var(--smbk-motion-chart-entrance-easing) backwards;
  }
}

@keyframes smbk-sparkline-reveal {
  from {
    clip-path: inset(-50% calc(100% + var(--smbk-size-6)) -50% calc(-1 * var(--smbk-size-6)));
  }

  to {
    clip-path: inset(-50% calc(-1 * var(--smbk-size-6)) -50% calc(-1 * var(--smbk-size-6)));
  }
}

/* ---- high contrast (forced colors) ---- */
/* The browser would drop the line's color; the line and the dot take the text color instead, and the area goes. */

@media (forced-colors: active) {
  .smbk-sparkline__line {
    stroke: CanvasText;
  }

  .smbk-sparkline__area {
    display: none;
  }

  .smbk-sparkline__dot {
    forced-color-adjust: none;
    background: CanvasText;
  }
}
Tokens it reads
Sparkline tokens
Token and CSSValuePreviewFoundation
size.32--smbk-size-3232pxSize
color.data.series--smbk-color-data-serieslight: default: #3b5ce3 · cockpit: #0a85a1dark: default: #7fa0ff · cockpit: #34a2bfchanges with themeColor
border-width.emphasis--smbk-border-width-emphasis2pxBorder width
opacity.ghost--smbk-opacity-ghost0.1Opacity
size.6--smbk-size-66pxSize
radius.full--smbk-radius-full9999pxRadius
motion.chart-entrance.reveal-duration--smbk-motion-chart-entrance-reveal-duration1000msMotion
motion.chart-entrance.easing--smbk-motion-chart-entrance-easingcubic-bezier(0, 0.7, 0.5, 1)Motion
Manifest
sparkline.manifest.json
{
  "name": "sparkline",
  "block": "smbk-sparkline",
  "summary": "A small line beside a figure that shows how it moved: rising, falling, steady or spiky. The figure carries the meaning.",
  "adapt": "css",
  "axes": {},
  "flags": {
    "area": {
      "description": "The soft fill under the line."
    }
  },
  "parts": [
    "plot",
    "svg",
    "area",
    "line",
    "dot"
  ],
  "figmaNodeId": "7580:152"
}