Sparkline
Sparklines display inline data trends as compact, visual charts.
-
Pro Components -
Responsive Layout Tools -
Ever-Growing Pattern Library -
Unlimited Hosted Projects -
Pre-Built Pro Themes -
Pro Theme Builder -
Pro Color Tools -
Official Figma Design Kit -
WA Pro Perpetual License -
Actual Human™ Support
Sparklines are small, word-sized graphics designed to fit within text or table cells. They show data trends at a glance without requiring dedicated chart space.
Always include a descriptive label attribute for accessibility. The label won't be visible but will be announced by screen readers.
Examples
Basic Usage
Provide numeric data as space-separated values. At least two values are required to generate the sparkline.
Server response times
Appearance
Use the appearance attribute to control how the sparkline fills. The default is solid which shows a filled area under the line. You can also choose gradient for a faded fill or line for stroke only.
Trend Colors
Apply semantic coloring with the trend attribute to visually indicate the nature of the data.
Curve Types
Control how data points connect with the curve attribute. Use linear (default), natural, or step.
Sizing
Sparklines default to height: 1em and aspect-ratio: 4/1 so they fit naturally within text. Override these with CSS for larger displays.
Custom Colors
Override the default colors using CSS custom properties.
In Tables
Sparklines work well in data tables to visualize trends alongside other metrics.
| Metric | Trend | Change |
|---|---|---|
| Page Views |
|
|
| Bounce Rate |
|
|
| Avg. Session |
|
Importing
If you're using the autoloader or a hosted project, components load on demand — no manual import needed. To cherry-pick a component manually, use one of the following snippets.
Import this component directly from the CDN:
import 'https://ka-f.webawesome.com/[email protected]/components/sparkline/sparkline.js';
After installing Web Awesome via npm, import this component:
import '@awesome.me/webawesome/dist/components/sparkline/sparkline.js';
If you're self-hosting Web Awesome, import this component from your server:
import './webawesome/dist/components/sparkline/sparkline.js';
To import this component for React 18 or below, use the following code:
import WaSparkline from '@awesome.me/webawesome/dist/react/sparkline/index.js';
Attributes & Properties
Learn more about attributes and properties.
| Name | Description | Reflects | |
|---|---|---|---|
appearanceappearance |
The visual fill style of the sparkline.
Type
'gradient' | 'line' | 'solid'
Default
'solid'
|
|
|
curvecurve |
The type of curve used to connect data points.
Type
'linear' | 'natural' | 'step'
Default
'linear'
|
|
|
datadata |
Space-separated numeric values to visualize (e.g., "10 20 40 25 35").
Type
string
Default
''
|
||
labellabel |
An accessible label describing the sparkline for screen readers.
Type
string
Default
''
|
||
trendtrend |
A trend to indicate, which will affect the sparkline's default color.
Type
'positive' | 'negative' | 'neutral'
|
|
CSS custom properties
Learn more about CSS custom properties.
| Name | Description |
|---|---|
--fill-color |
The fill color for the area under the line.
|
--line-color |
The color of the sparkline stroke.
|
--line-width |
The width of the sparkline stroke.
|
CSS parts
Learn more about CSS parts.
| Name | Description | CSS selector |
|---|---|---|
base |
The SVG container element. |
::part(base)
|
fill |
The filled area under the line (visible with gradient or solid appearance). |
::part(fill)
|
line |
The sparkline stroke path. |
::part(line)
|