CSS Sparkline Stat Card

A dark dashboard metric card with a big number, change badge and an inline SVG sparkline with area fill.

  • dashboard
  • kpi
  • sparkline
  • chart
  • svg
  • analytics
  • dark
HTML
<article class="spark-stat">
  <p>Revenue</p>
  <strong>$84.2k</strong>
  <span class="spark-stat-delta">+8.1%</span>
  <svg viewBox="0 0 120 40" preserveAspectRatio="none" aria-hidden="true">
    <path class="spark-stat-area" d="M0 34 15 28 30 30 45 20 60 24 75 14 90 16 105 8 120 10V40H0Z"/>
    <path class="spark-stat-line" d="M0 34 15 28 30 30 45 20 60 24 75 14 90 16 105 8 120 10"/>
  </svg>
</article>
CSS
.spark-stat {
  --spark: #34d399;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  width: 220px;
  padding: 16px 18px 0;
  overflow: hidden;
  border: 1px solid #1e293b;
  border-radius: 16px;
  background: #111827;
  color: #f8fafc;
  font-family: system-ui, sans-serif;
}

.spark-stat p {
  grid-column: 1 / -1;
  margin: 0;
  color: #94a3b8;
  font-size: 13px;
}

.spark-stat strong {
  font-size: 28px;
  letter-spacing: -0.02em;
}

.spark-stat-delta {
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(52, 211, 153, 0.15);
  color: var(--spark);
  font-size: 12px;
  font-weight: 700;
}

.spark-stat svg {
  grid-column: 1 / -1;
  width: calc(100% + 36px);
  height: 48px;
  margin: 8px -18px 0;
}

.spark-stat-area {
  fill: var(--spark);
  opacity: 0.15;
}

.spark-stat-line {
  fill: none;
  stroke: var(--spark);
  stroke-width: 2;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

About this CSS Sparkline Stat Card

This CSS Sparkline Stat Card is 55 lines of pure CSS (0.9 KB) with no JavaScript and no dependencies. It uses CSS Grid and custom properties. It works in current versions of Chrome, Edge, Safari and Firefox. It works in any stack: plain HTML, React, Vue, Svelte, Astro, WordPress or Webflow.

CSS features used

Customize it

Change these custom properties to restyle the sparkline stat card without touching the rest of the CSS:

PropertyDefault
--spark#34d399

How to use this sparkline stat card

  1. Copy the HTML and paste it where you want the element to appear.
  2. Copy the CSS into your stylesheet, or inside a <style> tag.
  3. Keep the .spark-stat class name, or rename it in both places. Then tweak colors, sizes and timing to match your design.
  4. Using React or Next.js? Change class to className in the HTML. The CSS works as is, including in Tailwind projects (put it in your global stylesheet).

Building with an AI tool?

“Copy for AI” copies a short prompt for Cursor, Claude Code, Lovable, Bolt or v0. Your AI tool opens the Markdown version of this snippet and reads the HTML, CSS and setup notes there. If your tool can't open links, with the code instead. More ways to use copy CSS with AI.

Feedback