Skip to content

Sparkline KPI Row

Sparkline KPI row with four stat tiles, change badges and SVG sparklines that redraw when a 7d, 30d or 90d range is picked, with keyboard and touch tooltips.

Also known as: kpi cards with sparklines, sparkline chart, dashboard metric tiles, mini line chart cards, ecommerce kpi dashboard

Sparkline KPI Row live demo

Open in new tab

Pure CSS code (HTML, CSS, JS)

A sparkline KPI row in plain HTML, CSS and JavaScript: four stat tiles for revenue, orders, conversion rate and refunds, each with a value, a change badge and a small SVG line chart. A 7d / 30d / 90d segmented control swaps the data with no chart library, so this KPI dashboard example fits e-commerce admins, sales reports and analytics pages.

How it works

The root section.skr holds a header with the range text and a fieldset.skr-seg of native radio buttons styled as a segmented control. Each li.skr-tile has a data-skr-metric key, a .skr-value, a .skr-badge and a .skr-plot with one SVG (.skr-area, .skr-avg, .skr-line) plus an HTML dot and tooltip.

All numbers live in two objects at the top of script.js. PERIODS holds one series per metric for each range (7 daily, 30 daily or 13 weekly points) and the previous period's total. METRICS says whether a metric is summed or averaged, how it is formatted and which direction is good. On load and on every range change the script computes totals, changes and SVG paths and fills a visually hidden table with every data point. Values use Intl.NumberFormat; dates are counted back from today and shown without a year.

Moving the pointer over a sparkline, tapping it or focusing it shows a tooltip with the date and value of the nearest point. The dashed .skr-avg line marks the previous period's average per day or week.

Customization

  • PERIODS in script.js: replace the arrays and previous totals with your own data; add a key such as '12m' and a matching radio input to get another range.
  • goodWhen in METRICS: set to 'down' for metrics where a fall is good (refunds, churn, bounce rate) so the badge and line turn green when they drop.
  • kind in METRICS: 'currency', 'number' or 'percent'; change the currency: 'USD' option of the money formatter for other currencies.
  • --skr-good and --skr-bad on .skr: the emerald and red used for badges, lines and areas.
  • --skr-plot-h on .skr: the height of every sparkline.

Use cases

  • E-commerce admin dashboards: revenue, orders, conversion and refunds at a glance.
  • SaaS analytics pages: MRR, sign-ups, trial conversion and churn with a range switch.
  • Weekly sales reports: the 90-day view shows weekly totals with a clear trend line.

Accessibility

The range switch is a real radio group inside a fieldset with a legend, so arrow keys move between 7d, 30d and 90d. Each .skr-plot is focusable: Left/Right (or Up/Down), Home and End move through the data points, Escape hides the tooltip, and a polite live region reads the metric, date and value. Range changes are announced too. Badges include hidden "favorable" or "unfavorable" text so the meaning does not rely on color, and a visually hidden table repeats every number.

Usage notes

Radio names are set per instance, so several rows can share a page; give each copy a unique heading id.

Sparkline KPI Row at a glance

Framework
Pure CSS
Code
HTML, CSS, JavaScript
JavaScript
Vanilla JavaScript, no jQuery
Dependencies
fonts.googleapis.com
Layout
Responsive, works on mobile
Category
Charts
License
Free for personal and commercial use

Questions about this template

Can I use the Sparkline KPI Row 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 fonts.googleapis.com 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):

  • <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap">
Sparkline KPI Row – free Pure CSS chart template
Sparkline KPI Row · free Pure CSS chart template

More Charts

Multi-Line Chart with Range Tabs – free Bootstrap 6 chart template

Multi-Line Chart with Range Tabs

SVG multi-line chart comparing organic, paid and email traffic, with 7 day, 30 day and 12 month tabs, legend toggles and a crosshair tooltip.

SVG Line Chart with Hover Points – free Pure CSS chart template

SVG Line Chart with Hover Points

Smooth SVG line chart of daily website visitors with a gradient area fill, axis labels, and a crosshair tooltip that follows the pointer or the arrow keys.

Horizontal Bar Chart Ranking – free Bootstrap 6 chart template

Horizontal Bar Chart Ranking

Horizontal bar chart ranking the top 8 products by revenue, units or returns; a select re-sorts the bars and announces the new order.

Donut Chart with Legend – free Pure CSS chart template

Donut Chart with Legend

SVG donut chart of traffic sources with the total in the centre and an interactive legend that highlights each segment and shows its share, value and percent.

Pie Chart with Percentage Legend – free Bootstrap 6 chart template

Pie Chart with Percentage Legend

Budget pie chart with a percentage legend table: SVG slices drawn from a data array, and clicking a slice or category row pulls the slice out.

Bar Chart with Axis and Tooltips – free Pure CSS chart template

Bar Chart with Axis and Tooltips

Monthly sales bar chart with a labelled value axis, gridlines, tooltips on hover, focus and tap, and a this year / last year toggle that animates the bars.