Skip to content

Stat Cards with Trend

Tailwind CSS KPI stat cards with change percentage pills and animated SVG sparklines generated from a data attribute.

Also known as: kpi cards, dashboard stat cards, metric cards, analytics stat widgets, statistics cards with sparkline

Stat Cards with Trend live demo

Open in new tab

Tailwind CSS code (HTML, CSS, JS)

A row of KPI stat cards built with Tailwind CSS, each with an icon, a large value, a change percentage pill and a mini sparkline drawn as inline SVG. It fits analytics dashboards, admin home screens, SaaS billing pages and weekly report emails rendered on the web.

How it works

The root is .tsc-root. The cards are li elements marked data-tsc-card inside a responsive grid: one column on phones, two from sm and four from lg. Each card holds a heading with a tinted icon, a change pill (green bg-emerald-50 for good news, red bg-rose-50 for bad), the value in tabular-nums so digits line up, a comparison line and an empty .tsc-spark box.

The sparkline data lives in markup: .tsc-spark carries data-tsc-points, a comma-separated list of numbers, and data-tsc-label, a short description. On DOMContentLoaded the script reads the points, scales them between the minimum and maximum, and builds an SVG with a viewBox of 120 by 40 and preserveAspectRatio="none", so it stretches to any card width. It draws a line path with vector-effect="non-scaling-stroke" (the stroke stays 2px), an area path filled with a vertical linearGradient (unique id per card), and an HTML .tsc-dot positioned on the latest value. Every color uses currentColor, so the text color class on .tsc-spark controls the whole chart.

style.css sizes the SVG to its box, draws a halo around .tsc-dot and lifts the card on hover, widening the halo at the same time. Without JavaScript the cards still show every number; only the chart is missing.

Customization

  • data-tsc-points on .tsc-spark: paste your own series, e.g. "5,8,6,9,12"; any length of two or more works.
  • text-emerald-500 on .tsc-spark: change to any text color to recolor the line, area and dot together.
  • h-14 on .tsc-spark: make the chart taller (h-20) or flatter (h-10).
  • WIDTH, HEIGHT and PAD in script.js: adjust the internal aspect and the padding above the highest value.
  • 'stop-opacity': '0.28' in script.js: strengthen or remove the area fill under the line.
  • Swap the pill classes between bg-emerald-50 text-emerald-700 and bg-rose-50 text-rose-700 based on whether a change is good or bad, as the churn card shows, where falling is green.
  • sm:grid-cols-2 lg:grid-cols-4 on the list: show three cards per row with lg:grid-cols-3.

Use cases

  • Analytics dashboards: show visitors or revenue with a change percentage pill and mini chart
  • Admin home screens: a row of KPI cards summarizes key numbers at the top
  • SaaS billing pages: display usage and spending values with a sparkline from a data attribute
  • Weekly reports: present trends in compact cards with an icon and large value

Accessibility

Cards are list items with real h3 headings. Arrows and icons are aria-hidden; the pill includes sr-only text such as "Increased by" or "Improved, down by", so the direction is never conveyed by color alone. Each sparkline has role="img" and a generated aria-label that states the first, latest, lowest and highest values. The hover lift and halo transitions are disabled under prefers-reduced-motion: reduce, and all text meets WCAG AA contrast on white.

Usage notes

Several .tsc-root sections can share a page. To show live data, fill data-tsc-points on the server or after a fetch() call; drawSparkline in script.js clears the box before drawing, so you can expose it and call it again whenever the numbers change.

Stat Cards with Trend at a glance

Framework
Tailwind CSS
Code
HTML, CSS, JavaScript
JavaScript
Vanilla JavaScript, no jQuery
Dependencies
Tailwind CSS
Layout
Responsive, works on mobile
Category
Stat Cards
License
Free for personal and commercial use

Questions about this template

Can I use the Stat Cards with Trend code for free?

Yes. You can copy or download the code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my website?

Load Tailwind CSS from a CDN (the links are under Requirements). Paste the HTML where the component should appear, add the CSS to your stylesheet and load the JavaScript before the closing </body> tag. Download HTML gives you a complete page with everything already linked.

Does it need jQuery or a JavaScript framework?

No. The script is plain vanilla JavaScript, so it works without jQuery, React or Vue. You can still use the markup inside those frameworks.

Does it work on mobile?

Yes. The layout adapts to small screens. Use the Mobile and Tablet buttons above the live demo to check it at phone and tablet width.

Requirements

Add these to your page (already included in the download):

  • <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>

The Tailwind browser build is for prototyping. In production, compile Tailwind with its CLI or your bundler.

Stat Cards with Trend – free Tailwind CSS stat card template
Stat Cards with Trend · free Tailwind CSS stat card template

More Stat Cards

Stat Card with Sparkline – free Pure CSS stat card template

Stat Card with Sparkline

Pure CSS KPI cards with a big value, colored trend badge, low/high range and an inline SVG sparkline that redraws itself on hover.

KPI Cards with Progress – free Bootstrap 5 stat card template

KPI Cards with Progress

Dark Bootstrap 5 KPI cards with trend badges, goal progress bars and a Month, Quarter and Year switch for admin and sales dashboards.