Navigation

v2.1.0
Data display

Sparkline

A trend as one fine line, small enough for a sentence, a row or a stat.

On this page

A sparkline is a trend drawn as one fine line, small enough to stand where its words already are: under a figure in a stat, in a column of a table, inside a sentence. It is an inline SVG that stretches to the room it is given while its line keeps a 1.5px stroke, in the ink of the text around it. A dot marks the latest value and stays round however far the drawing stretches. There is no script.

Sparkline

<div class="card max-w(320) mx-auto">  <div class="stat">    <p class="stat-label">Requests per day</p>    <div class="stat-row">      <p class="stat-value">61,240</p>      <p class="stat-delta stat-delta-up">        <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">          <path d="M13.6362 7.5189A0.4947 0.4947 0 0 0 13.5 7.5L2.4755 7.5006A0.5 0.5 0 0 0 2.4266 8.4946L2.5 8.5H13.5A0.4947 0.4947 0 0 0 13.6362 8.4811A0.7009 0.7009 0 0 0 13.6362 7.5189Z" fill="currentColor" stroke="none" fill-rule="evenodd" transform="rotate(-90 8 8)" /><path d="M8 4.5L13.2348 7.8313A0.2 0.2 0 0 1 13.2348 8.1687L8 11.5" transform="rotate(-90 8 8)" />        </svg>12.4%      </p>    </div>    <span class="sparkline" style="--sparkline-width: 100%; --sparkline-height: 2.5rem" aria-hidden="true">      <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none">        <path class="sparkline-area" d="M0 100 L7.69 90 L15.38 93.3 L23.08 76.7 L30.77 83.3 L38.46 66.7 L46.15 56.7 L53.85 63.3 L61.54 46.7 L69.23 30 L76.92 40 L84.62 20 L92.31 10 L100 0 V100 H0 Z" /><line class="sparkline-baseline" x1="0" y1="55.5" x2="100" y2="55.5" /><path class="sparkline-line" d="M0 100 L7.69 90 L15.38 93.3 L23.08 76.7 L30.77 83.3 L38.46 66.7 L46.15 56.7 L53.85 63.3 L61.54 46.7 L69.23 30 L76.92 40 L84.62 20 L92.31 10 L100 0" />      </svg><span class="sparkline-dot" style="--x: 100; --y: 0"></span>    </span>    <p class="stat-description">The last 14 days; the dotted line is their average</p>  </div></div>
import ArrowUpIcon from '@master/icons-react/native/16/soft/arrow-up'<div className="card max-w(320) mx-auto">  <div className="stat">    <p className="stat-label">Requests per day</p>    <div className="stat-row">      <p className="stat-value">61,240</p>      <p className="stat-delta stat-delta-up"><ArrowUpIcon className="icon" />12.4%</p>    </div>    <span className="sparkline" style={{ '--sparkline-width': '100%', '--sparkline-height': '2.5rem' } as React.CSSProperties} aria-hidden="true">      <svg className="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none">        <path className="sparkline-area" d="M0 100 L7.69 90 L15.38 93.3 L23.08 76.7 L30.77 83.3 L38.46 66.7 L46.15 56.7 L53.85 63.3 L61.54 46.7 L69.23 30 L76.92 40 L84.62 20 L92.31 10 L100 0 V100 H0 Z" /><line className="sparkline-baseline" x1="0" y1="55.5" x2="100" y2="55.5" /><path className="sparkline-line" d="M0 100 L7.69 90 L15.38 93.3 L23.08 76.7 L30.77 83.3 L38.46 66.7 L46.15 56.7 L53.85 63.3 L61.54 46.7 L69.23 30 L76.92 40 L84.62 20 L92.31 10 L100 0" />      </svg><span className="sparkline-dot" style={{ '--x': '100', '--y': '0' } as React.CSSProperties}></span>    </span>    <p className="stat-description">The last 14 days; the dotted line is their average</p>  </div></div>
<script>  import ArrowUpIcon from '@master/icons-svelte/native/16/soft/arrow-up'</script><div class="card max-w(320) mx-auto">  <div class="stat">    <p class="stat-label">Requests per day</p>    <div class="stat-row">      <p class="stat-value">61,240</p>      <p class="stat-delta stat-delta-up"><ArrowUpIcon class="icon" />12.4%</p>    </div>    <span class="sparkline" style="--sparkline-width: 100%; --sparkline-height: 2.5rem" aria-hidden="true">      <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none">        <path class="sparkline-area" d="M0 100 L7.69 90 L15.38 93.3 L23.08 76.7 L30.77 83.3 L38.46 66.7 L46.15 56.7 L53.85 63.3 L61.54 46.7 L69.23 30 L76.92 40 L84.62 20 L92.31 10 L100 0 V100 H0 Z" /><line class="sparkline-baseline" x1="0" y1="55.5" x2="100" y2="55.5" /><path class="sparkline-line" d="M0 100 L7.69 90 L15.38 93.3 L23.08 76.7 L30.77 83.3 L38.46 66.7 L46.15 56.7 L53.85 63.3 L61.54 46.7 L69.23 30 L76.92 40 L84.62 20 L92.31 10 L100 0" />      </svg><span class="sparkline-dot" style="--x: 100; --y: 0"></span>    </span>    <p class="stat-description">The last 14 days; the dotted line is their average</p>  </div></div>
<script setup>import ArrowUpIcon from '@master/icons-vue/native/16/soft/arrow-up'</script><template>  <div class="card max-w(320) mx-auto">    <div class="stat">      <p class="stat-label">Requests per day</p>      <div class="stat-row">        <p class="stat-value">61,240</p>        <p class="stat-delta stat-delta-up"><ArrowUpIcon class="icon" />12.4%</p>      </div>      <span class="sparkline" style="--sparkline-width: 100%; --sparkline-height: 2.5rem" aria-hidden="true">        <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none">          <path class="sparkline-area" d="M0 100 L7.69 90 L15.38 93.3 L23.08 76.7 L30.77 83.3 L38.46 66.7 L46.15 56.7 L53.85 63.3 L61.54 46.7 L69.23 30 L76.92 40 L84.62 20 L92.31 10 L100 0 V100 H0 Z" /><line class="sparkline-baseline" x1="0" y1="55.5" x2="100" y2="55.5" /><path class="sparkline-line" d="M0 100 L7.69 90 L15.38 93.3 L23.08 76.7 L30.77 83.3 L38.46 66.7 L46.15 56.7 L53.85 63.3 L61.54 46.7 L69.23 30 L76.92 40 L84.62 20 L92.31 10 L100 0" />        </svg><span class="sparkline-dot" style="--x: 100; --y: 0"></span>      </span>      <p class="stat-description">The last 14 days; the dotted line is their average</p>    </div>  </div></template>

#How the line is drawn

The drawing is an <svg class="sparkline-plot"> with viewBox="0 0 100 100" and preserveAspectRatio="none": a box 100 units wide and 100 tall that is stretched to the sparkline's size. Write the points once, in that box, and the line fits a sentence and a card alike.

  • Across, the first point is at 0 and the last at 100, evenly spaced: for 14 values, one every 100 / 13 units.
  • Down, 0 is the top and 100 the foot, as SVG counts. Map your lowest value to 100 and your highest to 0, or to a scale of your own when several sparklines are compared.

sparkline-line is a <path> (or a <polyline>) through the points. Its stroke does not stretch with the box (vector-effect: non-scaling-stroke), so it is 1.5px at any size, with round joins and ends.

A sparkline shows a shape, not values. Each one in the table below is drawn on its own scale, from its own lowest to its own highest value, so the lines say which way each project went and not which is larger: the figures beside them do that.

#The latest value

sparkline-dot is a small HTML dot, not an SVG circle: a circle in a stretched drawing would stretch into an oval. Place it by its middle with --x and --y on the same 100 by 100 scale, which are the last point's coordinates. A ring of the surface behind it cuts it out of the line, so the line ends at the dot instead of running into it. The sparkline keeps room for half the dot inside its own box, so the dot never crowds the word after it.

#Area and baseline

sparkline-area is a <path> through the same points, closed along the foot (V100 H0 Z): a tint of the line's ink that fades out downward. Put it before the line, so the line is drawn over it.

sparkline-baseline is a dotted hairline, a <line> from 0 to 100 at the height of an average, a target or last period's value. It is quieter than the line, and the words beside the sparkline say what it marks, as in the stat above.

#In a sentence

A sparkline is 4em wide and .75em tall, about the height of a capital, and its middle stands on the middle of the capitals beside it, so it sits in a line of text like a word. Its ink is the text's: on a page, in a card and on an ink surface alike.

In a sentence

<p class="m(0) max-w(440) mx-auto fg-text-body">  Requests rose all fortnight <span class="sparkline" aria-hidden="true">    <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none">      <path class="sparkline-line" d="M0 100 L7.69 90 L15.38 93.3 L23.08 76.7 L30.77 83.3 L38.46 66.7 L46.15 56.7 L53.85 63.3 L61.54 46.7 L69.23 30 L76.92 40 L84.62 20 L92.31 10 L100 0" />    </svg><span class="sparkline-dot" style="--x: 100; --y: 0"></span>  </span> to 61,000 a day, while latency fell <span class="sparkline" aria-hidden="true">    <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none">      <path class="sparkline-line" d="M0 0 L7.69 11.1 L15.38 3.7 L23.08 20.4 L30.77 25.9 L38.46 22.2 L46.15 42.6 L53.85 55.6 L61.54 50 L69.23 66.7 L76.92 75.9 L84.62 72.2 L92.31 85.2 L100 100" />    </svg>  </span> to 128 ms.</p>
<p className="m(0) max-w(440) mx-auto fg-text-body">  Requests rose all fortnight <span className="sparkline" aria-hidden="true">    <svg className="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none">      <path className="sparkline-line" d="M0 100 L7.69 90 L15.38 93.3 L23.08 76.7 L30.77 83.3 L38.46 66.7 L46.15 56.7 L53.85 63.3 L61.54 46.7 L69.23 30 L76.92 40 L84.62 20 L92.31 10 L100 0" />    </svg><span className="sparkline-dot" style={{ '--x': '100', '--y': '0' } as React.CSSProperties}></span>  </span> to 61,000 a day, while latency fell <span className="sparkline" aria-hidden="true">    <svg className="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none">      <path className="sparkline-line" d="M0 0 L7.69 11.1 L15.38 3.7 L23.08 20.4 L30.77 25.9 L38.46 22.2 L46.15 42.6 L53.85 55.6 L61.54 50 L69.23 66.7 L76.92 75.9 L84.62 72.2 L92.31 85.2 L100 100" />    </svg>  </span> to 128 ms.</p>
<p class="m(0) max-w(440) mx-auto fg-text-body">  Requests rose all fortnight <span class="sparkline" aria-hidden="true">    <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none">      <path class="sparkline-line" d="M0 100 L7.69 90 L15.38 93.3 L23.08 76.7 L30.77 83.3 L38.46 66.7 L46.15 56.7 L53.85 63.3 L61.54 46.7 L69.23 30 L76.92 40 L84.62 20 L92.31 10 L100 0" />    </svg><span class="sparkline-dot" style="--x: 100; --y: 0"></span>  </span> to 61,000 a day, while latency fell <span class="sparkline" aria-hidden="true">    <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none">      <path class="sparkline-line" d="M0 0 L7.69 11.1 L15.38 3.7 L23.08 20.4 L30.77 25.9 L38.46 22.2 L46.15 42.6 L53.85 55.6 L61.54 50 L69.23 66.7 L76.92 75.9 L84.62 72.2 L92.31 85.2 L100 100" />    </svg>  </span> to 128 ms.</p>
<template>  <p class="m(0) max-w(440) mx-auto fg-text-body">    Requests rose all fortnight <span class="sparkline" aria-hidden="true">      <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none">        <path class="sparkline-line" d="M0 100 L7.69 90 L15.38 93.3 L23.08 76.7 L30.77 83.3 L38.46 66.7 L46.15 56.7 L53.85 63.3 L61.54 46.7 L69.23 30 L76.92 40 L84.62 20 L92.31 10 L100 0" />      </svg><span class="sparkline-dot" style="--x: 100; --y: 0"></span>    </span> to 61,000 a day, while latency fell <span class="sparkline" aria-hidden="true">      <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none">        <path class="sparkline-line" d="M0 0 L7.69 11.1 L15.38 3.7 L23.08 20.4 L30.77 25.9 L38.46 22.2 L46.15 42.6 L53.85 55.6 L61.54 50 L69.23 66.7 L76.92 75.9 L84.62 72.2 L92.31 85.2 L100 100" />      </svg>    </span> to 128 ms.  </p></template>

#In a table

Set --sparkline-width and --sparkline-height on the sparkline, or once on a container such as the table, and every sparkline inside takes that size. A sparkline that sizes itself to a card, as in the stat above, takes --sparkline-width: 100%.

In a table

<div class="sheet overflow-hidden max-w(480) mx-auto">  <table class="table table-compact" style="--sparkline-width: 5rem; --sparkline-height: 1rem">    <thead>      <tr class="table-row">        <th class="table-heading" scope="col">Project</th>        <th class="table-heading" scope="col">Last 14 days</th>        <th class="table-heading table-numeric" scope="col">Today</th>      </tr>    </thead>    <tbody>      <tr class="table-row">        <th class="table-cell table-primary" scope="row">Atlas</th>        <td class="table-cell">          <span class="sparkline" role="img" aria-label="Rising steadily">            <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none">              <path class="sparkline-line" d="M0 100 L7.69 90 L15.38 93.3 L23.08 76.7 L30.77 83.3 L38.46 66.7 L46.15 56.7 L53.85 63.3 L61.54 46.7 L69.23 30 L76.92 40 L84.62 20 L92.31 10 L100 0" />            </svg><span class="sparkline-dot" style="--x: 100; --y: 0"></span>          </span>        </td>        <td class="table-cell table-numeric">61,240</td>      </tr>      <tr class="table-row">        <th class="table-cell table-primary" scope="row">Borealis</th>        <td class="table-cell">          <span class="sparkline" role="img" aria-label="Falling">            <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none">              <path class="sparkline-line" d="M0 5.9 L7.69 17.6 L15.38 0 L23.08 23.5 L30.77 35.3 L38.46 29.4 L46.15 52.9 L53.85 41.2 L61.54 70.6 L69.23 58.8 L76.92 82.4 L84.62 76.5 L92.31 94.1 L100 100" />            </svg><span class="sparkline-dot" style="--x: 100; --y: 100"></span>          </span>        </td>        <td class="table-cell table-numeric">36,018</td>      </tr>      <tr class="table-row">        <th class="table-cell table-primary" scope="row">Cirrus</th>        <td class="table-cell">          <span class="sparkline" role="img" aria-label="Rising slowly">            <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none">              <path class="sparkline-line" d="M0 100 L7.69 79.2 L15.38 91.7 L23.08 58.3 L30.77 66.7 L38.46 45.8 L46.15 54.2 L53.85 33.3 L61.54 41.7 L69.23 20.8 L76.92 29.2 L84.62 12.5 L92.31 16.7 L100 0" />            </svg><span class="sparkline-dot" style="--x: 100; --y: 0"></span>          </span>        </td>        <td class="table-cell table-numeric">16,420</td>      </tr>    </tbody>  </table></div>
<div className="sheet overflow-hidden max-w(480) mx-auto">  <table className="table table-compact" style={{ '--sparkline-width': '5rem', '--sparkline-height': '1rem' } as React.CSSProperties}>    <thead>      <tr className="table-row">        <th className="table-heading" scope="col">Project</th>        <th className="table-heading" scope="col">Last 14 days</th>        <th className="table-heading table-numeric" scope="col">Today</th>      </tr>    </thead>    <tbody>      <tr className="table-row">        <th className="table-cell table-primary" scope="row">Atlas</th>        <td className="table-cell">          <span className="sparkline" role="img" aria-label="Rising steadily">            <svg className="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none">              <path className="sparkline-line" d="M0 100 L7.69 90 L15.38 93.3 L23.08 76.7 L30.77 83.3 L38.46 66.7 L46.15 56.7 L53.85 63.3 L61.54 46.7 L69.23 30 L76.92 40 L84.62 20 L92.31 10 L100 0" />            </svg><span className="sparkline-dot" style={{ '--x': '100', '--y': '0' } as React.CSSProperties}></span>          </span>        </td>        <td className="table-cell table-numeric">61,240</td>      </tr>      <tr className="table-row">        <th className="table-cell table-primary" scope="row">Borealis</th>        <td className="table-cell">          <span className="sparkline" role="img" aria-label="Falling">            <svg className="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none">              <path className="sparkline-line" d="M0 5.9 L7.69 17.6 L15.38 0 L23.08 23.5 L30.77 35.3 L38.46 29.4 L46.15 52.9 L53.85 41.2 L61.54 70.6 L69.23 58.8 L76.92 82.4 L84.62 76.5 L92.31 94.1 L100 100" />            </svg><span className="sparkline-dot" style={{ '--x': '100', '--y': '100' } as React.CSSProperties}></span>          </span>        </td>        <td className="table-cell table-numeric">36,018</td>      </tr>      <tr className="table-row">        <th className="table-cell table-primary" scope="row">Cirrus</th>        <td className="table-cell">          <span className="sparkline" role="img" aria-label="Rising slowly">            <svg className="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none">              <path className="sparkline-line" d="M0 100 L7.69 79.2 L15.38 91.7 L23.08 58.3 L30.77 66.7 L38.46 45.8 L46.15 54.2 L53.85 33.3 L61.54 41.7 L69.23 20.8 L76.92 29.2 L84.62 12.5 L92.31 16.7 L100 0" />            </svg><span className="sparkline-dot" style={{ '--x': '100', '--y': '0' } as React.CSSProperties}></span>          </span>        </td>        <td className="table-cell table-numeric">16,420</td>      </tr>    </tbody>  </table></div>
<div class="sheet overflow-hidden max-w(480) mx-auto">  <table class="table table-compact" style="--sparkline-width: 5rem; --sparkline-height: 1rem">    <thead>      <tr class="table-row">        <th class="table-heading" scope="col">Project</th>        <th class="table-heading" scope="col">Last 14 days</th>        <th class="table-heading table-numeric" scope="col">Today</th>      </tr>    </thead>    <tbody>      <tr class="table-row">        <th class="table-cell table-primary" scope="row">Atlas</th>        <td class="table-cell">          <span class="sparkline" role="img" aria-label="Rising steadily">            <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none">              <path class="sparkline-line" d="M0 100 L7.69 90 L15.38 93.3 L23.08 76.7 L30.77 83.3 L38.46 66.7 L46.15 56.7 L53.85 63.3 L61.54 46.7 L69.23 30 L76.92 40 L84.62 20 L92.31 10 L100 0" />            </svg><span class="sparkline-dot" style="--x: 100; --y: 0"></span>          </span>        </td>        <td class="table-cell table-numeric">61,240</td>      </tr>      <tr class="table-row">        <th class="table-cell table-primary" scope="row">Borealis</th>        <td class="table-cell">          <span class="sparkline" role="img" aria-label="Falling">            <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none">              <path class="sparkline-line" d="M0 5.9 L7.69 17.6 L15.38 0 L23.08 23.5 L30.77 35.3 L38.46 29.4 L46.15 52.9 L53.85 41.2 L61.54 70.6 L69.23 58.8 L76.92 82.4 L84.62 76.5 L92.31 94.1 L100 100" />            </svg><span class="sparkline-dot" style="--x: 100; --y: 100"></span>          </span>        </td>        <td class="table-cell table-numeric">36,018</td>      </tr>      <tr class="table-row">        <th class="table-cell table-primary" scope="row">Cirrus</th>        <td class="table-cell">          <span class="sparkline" role="img" aria-label="Rising slowly">            <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none">              <path class="sparkline-line" d="M0 100 L7.69 79.2 L15.38 91.7 L23.08 58.3 L30.77 66.7 L38.46 45.8 L46.15 54.2 L53.85 33.3 L61.54 41.7 L69.23 20.8 L76.92 29.2 L84.62 12.5 L92.31 16.7 L100 0" />            </svg><span class="sparkline-dot" style="--x: 100; --y: 0"></span>          </span>        </td>        <td class="table-cell table-numeric">16,420</td>      </tr>    </tbody>  </table></div>
<template>  <div class="sheet overflow-hidden max-w(480) mx-auto">    <table class="table table-compact" style="--sparkline-width: 5rem; --sparkline-height: 1rem">      <thead>        <tr class="table-row">          <th class="table-heading" scope="col">Project</th>          <th class="table-heading" scope="col">Last 14 days</th>          <th class="table-heading table-numeric" scope="col">Today</th>        </tr>      </thead>      <tbody>        <tr class="table-row">          <th class="table-cell table-primary" scope="row">Atlas</th>          <td class="table-cell">            <span class="sparkline" role="img" aria-label="Rising steadily">              <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none">                <path class="sparkline-line" d="M0 100 L7.69 90 L15.38 93.3 L23.08 76.7 L30.77 83.3 L38.46 66.7 L46.15 56.7 L53.85 63.3 L61.54 46.7 L69.23 30 L76.92 40 L84.62 20 L92.31 10 L100 0" />              </svg><span class="sparkline-dot" style="--x: 100; --y: 0"></span>            </span>          </td>          <td class="table-cell table-numeric">61,240</td>        </tr>        <tr class="table-row">          <th class="table-cell table-primary" scope="row">Borealis</th>          <td class="table-cell">            <span class="sparkline" role="img" aria-label="Falling">              <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none">                <path class="sparkline-line" d="M0 5.9 L7.69 17.6 L15.38 0 L23.08 23.5 L30.77 35.3 L38.46 29.4 L46.15 52.9 L53.85 41.2 L61.54 70.6 L69.23 58.8 L76.92 82.4 L84.62 76.5 L92.31 94.1 L100 100" />              </svg><span class="sparkline-dot" style="--x: 100; --y: 100"></span>            </span>          </td>          <td class="table-cell table-numeric">36,018</td>        </tr>        <tr class="table-row">          <th class="table-cell table-primary" scope="row">Cirrus</th>          <td class="table-cell">            <span class="sparkline" role="img" aria-label="Rising slowly">              <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none">                <path class="sparkline-line" d="M0 100 L7.69 79.2 L15.38 91.7 L23.08 58.3 L30.77 66.7 L38.46 45.8 L46.15 54.2 L53.85 33.3 L61.54 41.7 L69.23 20.8 L76.92 29.2 L84.62 12.5 L92.31 16.7 L100 0" />              </svg><span class="sparkline-dot" style="--x: 100; --y: 0"></span>            </span>          </td>          <td class="table-cell table-numeric">16,420</td>        </tr>      </tbody>    </table>  </div></template>

#Status inks

sparkline-success, sparkline-warning and sparkline-danger draw the line and its dot in a status ink. Up is not always good: more errors is a rising line in the danger ink. Use them only where the words beside the sparkline say the same thing, so the ink is never the only sign.

Status inks

<p class="m(0) max-w(440) mx-auto fg-text-body">  After the fix, errors fell by half <span class="sparkline sparkline-success" aria-hidden="true">    <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none">      <path class="sparkline-line" d="M0 9.1 L7.69 0 L15.38 15.2 L23.08 6.1 L30.77 21.2 L38.46 39.4 L46.15 60.6 L53.85 72.7 L61.54 78.8 L69.23 87.9 L76.92 81.8 L84.62 90.9 L92.31 97 L100 100" />    </svg><span class="sparkline-dot" style="--x: 100; --y: 100"></span>  </span> to 18 an hour. Checkout got slower <span class="sparkline sparkline-danger" aria-hidden="true">    <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none">      <path class="sparkline-line" d="M0 91.7 L7.69 100 L15.38 83.3 L23.08 91.7 L30.77 75 L38.46 83.3 L46.15 66.7 L53.85 58.3 L61.54 66.7 L69.23 41.7 L76.92 33.3 L84.62 25 L92.31 16.7 L100 0" />    </svg><span class="sparkline-dot" style="--x: 100; --y: 0"></span>  </span> and now takes 3.2 seconds.</p>
<p className="m(0) max-w(440) mx-auto fg-text-body">  After the fix, errors fell by half <span className="sparkline sparkline-success" aria-hidden="true">    <svg className="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none">      <path className="sparkline-line" d="M0 9.1 L7.69 0 L15.38 15.2 L23.08 6.1 L30.77 21.2 L38.46 39.4 L46.15 60.6 L53.85 72.7 L61.54 78.8 L69.23 87.9 L76.92 81.8 L84.62 90.9 L92.31 97 L100 100" />    </svg><span className="sparkline-dot" style={{ '--x': '100', '--y': '100' } as React.CSSProperties}></span>  </span> to 18 an hour. Checkout got slower <span className="sparkline sparkline-danger" aria-hidden="true">    <svg className="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none">      <path className="sparkline-line" d="M0 91.7 L7.69 100 L15.38 83.3 L23.08 91.7 L30.77 75 L38.46 83.3 L46.15 66.7 L53.85 58.3 L61.54 66.7 L69.23 41.7 L76.92 33.3 L84.62 25 L92.31 16.7 L100 0" />    </svg><span className="sparkline-dot" style={{ '--x': '100', '--y': '0' } as React.CSSProperties}></span>  </span> and now takes 3.2 seconds.</p>
<p class="m(0) max-w(440) mx-auto fg-text-body">  After the fix, errors fell by half <span class="sparkline sparkline-success" aria-hidden="true">    <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none">      <path class="sparkline-line" d="M0 9.1 L7.69 0 L15.38 15.2 L23.08 6.1 L30.77 21.2 L38.46 39.4 L46.15 60.6 L53.85 72.7 L61.54 78.8 L69.23 87.9 L76.92 81.8 L84.62 90.9 L92.31 97 L100 100" />    </svg><span class="sparkline-dot" style="--x: 100; --y: 100"></span>  </span> to 18 an hour. Checkout got slower <span class="sparkline sparkline-danger" aria-hidden="true">    <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none">      <path class="sparkline-line" d="M0 91.7 L7.69 100 L15.38 83.3 L23.08 91.7 L30.77 75 L38.46 83.3 L46.15 66.7 L53.85 58.3 L61.54 66.7 L69.23 41.7 L76.92 33.3 L84.62 25 L92.31 16.7 L100 0" />    </svg><span class="sparkline-dot" style="--x: 100; --y: 0"></span>  </span> and now takes 3.2 seconds.</p>
<template>  <p class="m(0) max-w(440) mx-auto fg-text-body">    After the fix, errors fell by half <span class="sparkline sparkline-success" aria-hidden="true">      <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none">        <path class="sparkline-line" d="M0 9.1 L7.69 0 L15.38 15.2 L23.08 6.1 L30.77 21.2 L38.46 39.4 L46.15 60.6 L53.85 72.7 L61.54 78.8 L69.23 87.9 L76.92 81.8 L84.62 90.9 L92.31 97 L100 100" />      </svg><span class="sparkline-dot" style="--x: 100; --y: 100"></span>    </span> to 18 an hour. Checkout got slower <span class="sparkline sparkline-danger" aria-hidden="true">      <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none">        <path class="sparkline-line" d="M0 91.7 L7.69 100 L15.38 83.3 L23.08 91.7 L30.77 75 L38.46 83.3 L46.15 66.7 L53.85 58.3 L61.54 66.7 L69.23 41.7 L76.92 33.3 L84.62 25 L92.31 16.7 L100 0" />      </svg><span class="sparkline-dot" style="--x: 100; --y: 0"></span>    </span> and now takes 3.2 seconds.  </p></template>

#Accessibility

  • When the trend is not said in words beside it, give the sparkline role="img" and an aria-label that says it: "Rising from 31,000 to 61,000 a day". The drawing inside is then a single image.
  • When the words or the figures beside it already say the trend, as in a sentence or a stat, hide it with aria-hidden="true", so it is not read twice.
  • In forced colors the line and the dot take the text color and the area is left out.

#Without a mask on SVG

The area fades out with a CSS mask on the SVG shape. A browser that cannot mask an SVG shape draws the area as an even tint of the same ink.

#Classes

ClassDescription
sparklineThe box the drawing stretches to: 4em wide and .75em tall, standing on the middle of a capital. Give it role="img" and an aria-label that names the trend, or aria-hidden="true" when the numbers stand beside it
sparkline-successThe success ink, for a trend that went well; the words beside it say so tooApply with sparkline
sparkline-warningThe warning ink, for a trend to watch; the words beside it say so tooApply with sparkline
sparkline-dangerThe danger ink, for a trend that went badly; the words beside it say so tooApply with sparkline
sparkline-plotThe drawing: an SVG with viewBox="0 0 100 100" and preserveAspectRatio="none", stretched to the sparkline's box. Strokes may stand past its edge
sparkline-lineThe trend: a 1.5px line in the ink of the text around it, with round joins and ends, that keeps its width however the drawing stretches
sparkline-areaThe area under the line: the same points closed along the foot, as a tint of the ink that fades out downward. Put it before the line
sparkline-baselineA dotted hairline for a baseline, an average or a target, quieter than the line
sparkline-dotThe latest value: a 5px dot placed by --x and --y, a perfect circle however the drawing stretches, cut out of the line by a ring of the surface behind it

#Custom properties

PropertyDefaultDescription
--sparkline-widthWidth of the sparkline; 4em unless set. It may be set on a container, such as a table, to size every sparkline in it
--sparkline-heightHeight of the sparkline; .75em unless set, about the height of a capital. It may be set on a container too
--sparkline-stroke1.5pxWidth of the line
--sparkline-dot5pxSize of the dot at the latest value
--xWhere the dot stands across, from 0 to 100: the x of the last point in the drawingSet on sparkline-dot
--yWhere the dot stands down, from 0 at the top to 100 at the foot: the y of the last point in the drawingSet on sparkline-dot

#Source

@master/ui/components/sparkline.css
/* * Sparkline: a trend as one fine line, small enough for a sentence, a row or a stat. * It is an inline SVG drawn in a box 100 units wide and 100 tall that stretches to the sparkline's size * (preserveAspectRatio="none"), so the points are written once and the line fits whatever room it is given. * The line keeps a 1.5px stroke however far the box stretches (vector-effect: non-scaling-stroke), with round * joins and ends, in the ink of the text around it: a sparkline in a sentence, in a card and on an ink surface * needs no variant. Under it an optional area fades out downward, and an optional hairline marks a baseline * or a target. The latest value is a dot of HTML placed by --x and --y on the same 100 by 100 scale, since a * circle drawn in the SVG would stretch with it; a ring of the surface behind it cuts it out of the line. * It is 4em wide and .75em tall, about the height of a capital, and its middle stands on the middle of the * capitals beside it, so it sits in a line of text like a word; set its size on it, or on a container such as * a table, to stand in a stat or the rows of a column. It is not interactive and has no states. The status * inks are for a trend whose words say the same thing beside it. * The area fades with a mask; a browser that cannot mask an SVG shape shows it as an even tint. */@layer components.ui {  .sparkline {    --sparkline-stroke: 1.5px;    --sparkline-dot: 5px;    position: relative;    display: inline-block;    flex: none;    box-sizing: border-box;    /* Read with a fallback, so a table or a list can size every sparkline it holds at once. */    width: var(--sparkline-width, 4em);    height: var(--sparkline-height, .75em);    margin: 0;    /* Its middle stands on the middle of a capital (.355em in Geist), whatever its height. */    vertical-align: calc(.355em - var(--sparkline-height, .75em) / 2);    /* A dot at the end needs half its width beside the line, inside the sparkline's own box. */    &:has(.sparkline-dot) {      padding-right: calc(var(--sparkline-dot) / 2);    }    &.sparkline-success {      color: var(--color-success);    }    &.sparkline-warning {      color: var(--color-warning);    }    &.sparkline-danger {      color: var(--color-danger);    }    @media (forced-colors: active) {      color: CanvasText;    }  }  /* The drawing. Strokes may stand half their width past its edge, so nothing at the top or bottom is cut. */  .sparkline-plot {    display: block;    width: 100%;    height: 100%;    overflow: visible;    fill: none;  }  .sparkline-line {    fill: none;    stroke: currentColor;    stroke-width: var(--sparkline-stroke);    stroke-linecap: round;    stroke-linejoin: round;    vector-effect: non-scaling-stroke;  }  /* The area under the line: a tint of its ink that fades out toward the foot. */  .sparkline-area {    fill: color-mix(in oklab, currentColor 16%, transparent);    stroke: none;    mask-image: linear-gradient(to bottom, black, transparent);    @media (forced-colors: active) {      fill: none;    }  }  /* A baseline or a target: a dotted hairline, quieter than the line. */  .sparkline-baseline {    fill: none;    stroke: color-mix(in oklab, currentColor 32%, transparent);    stroke-width: 1px;    stroke-dasharray: 1 2;    vector-effect: non-scaling-stroke;    /* A tint of the forced text color would be an author color: the hairline is the system's gray, as a chart's grid is. */    @media (forced-colors: active) {      stroke: GrayText;    }  }  /* The latest value: a round dot by its middle at --x and --y, cut out of the line by a ring of the surface. */  .sparkline-dot {    position: absolute;    top: calc(var(--y, 50) * 1%);    left: calc((100% - var(--sparkline-dot) / 2) * var(--x, 100) / 100);    width: var(--sparkline-dot);    height: var(--sparkline-dot);    margin: calc(var(--sparkline-dot) / -2) 0 0 calc(var(--sparkline-dot) / -2);    border-radius: 999px;    corner-shape: round;    background: currentColor;    box-shadow: 0 0 0 1.5px var(--surface-color, var(--color-surface-base));    pointer-events: none;    @media (forced-colors: active) {      forced-color-adjust: none;      background: CanvasText;      box-shadow: none;    }  }}