Charts (Data Viz)
Charts built in pure CSS and SVG - no library, no JavaScript for
the drawing itself. Data comes in through a single variable,
--val. Ready-made compilations:
examples.
1. One variable, everywhere
Every chart reads its value from --val - you set it
with an inline style, from a backend-side template. The
framework doesn't know your data; converting numbers
into percentages and angles is up to you, CSS just
draws it.
Why not a JS library
A pure-CSS chart renders in the same frame as the rest of the page - there's no flicker of "empty container first, chart loaded in by script later" (CLS). If a project needs interactive charts with tooltips and zoom, these classes make a good fallback for the loading time of that library, not a replacement for it.
2. Sparkline and radial bar
Sparkline
Bars in a row - a trend next to a number in a stat card. Each
bar is a separate element with its own --val as a
percentage of height.
<div class="r-chart-wrapper chart-micro">
<div class="chart-sparkline">
<div class="sparkline-bar" style="--val: 40%"></div>
<div class="sparkline-bar" style="--val: 65%"></div>
<div class="sparkline-bar" style="--val: 50%"></div>
<div class="sparkline-bar" style="--val: 90%"></div>
</div>
</div>
Radial bar
A ring filling up to a given percentage - a single KPI
indicator. A smooth fill animation requires registering the
variable with CSS Houdini (@property); without it
the browser can't animate a percentage value inside a gradient.
<div class="chart-radial" style="--val: 72%">
<span class="radial-value">72%</span>
</div>
| Class | Component | What it does |
|---|---|---|
.r-chart-wrapper |
Base |
A 200px-tall container. The
.chart-micro variant gives a fixed 80×40px
for cards and tables.
|
.chart-sparkline |
Sparkline | The row of bars. |
.sparkline-bar |
Sparkline |
A single bar. Height: --val
as a percentage.
|
.chart-radial |
Radial bar |
The ring. Fill level: --val
as a percentage.
|
.radial-value |
Radial bar | The number at the center of the ring. |
3. Heatmap and area chart
Heatmap
A grid of cells with variable color intensity - a
GitHub-style activity map. The number of columns is set with
grid-template-columns on the container;
.chart-heatmap doesn't force one.
<div class="chart-heatmap" style="grid-template-columns: repeat(7, 1fr)">
<div class="heatmap-cell" style="--val: 0.9"></div>
<div class="heatmap-cell" style="--val: 0.3"></div>
<div class="heatmap-cell" style="--val: 0.1"></div>
</div>
Here --val is a fraction, not a percentage
The only place in the whole chart family where
--val behaves differently: the cell takes it as
color opacity (rgba(…, var(--val))), so the
range is 0-1, not 0-100. Typing
90 instead of 0.9 produces a fully
saturated cell regardless of the actual value.
Area chart (SVG)
A curve with a fill underneath, drawn with an SVG path - the
data is <path> coordinates, not CSS. The
classes only add the left-to-right reveal animation and line style.
<svg class="chart-area" viewBox="0 0 300 100">
<defs>
<linearGradient id="areaGradient" x2="0" y2="1">
<stop offset="0%" stop-color="var(--primary)"></stop>
<stop offset="100%" stop-color="var(--primary)" stop-opacity="0"></stop>
</linearGradient>
</defs>
<path class="area-fill" d="M0,80 L50,60 L100,70 L300,20 L300,100 L0,100 Z"></path>
<path class="area-line" d="M0,80 L50,60 L100,70 L300,20"></path>
</svg>
| Class | Component | What it does |
|---|---|---|
.chart-heatmap |
Heatmap | The grid. You set the columns yourself. |
.heatmap-cell |
Heatmap |
A cell. --val is opacity 0-1, not a percentage.
|
.chart-area |
Area chart | SVG wrapper with the reveal animation. |
.area-fill |
Area chart | The fill below the curve. |
.area-line |
Area chart | The curve itself. |
4. Pie chart
A ring made of <circle> elements cut up with
stroke-dasharray. Every segment needs two numbers:
its own percentage share (--val) and its starting
point (--offset) - the sum of the shares of every
segment before it. Without that, they'd all
start in the same place and overlap.
<!-- viewBox 0 0 36 36 is REQUIRED - radius 15.9155 gives a circumference of 100,
so --val as a percentage works without any conversion -->
<svg viewBox="0 0 36 36" class="chart-pie">
<circle cx="18" cy="18" r="15.9155" class="pie-bg"></circle>
<!-- 45%, starts at 0 -->
<circle cx="18" cy="18" r="15.9155" class="pie-segment text-primary"
style="--val: 45; --offset: 0"></circle>
<!-- 30%, starts where the first one ended (45) -->
<circle cx="18" cy="18" r="15.9155" class="pie-segment text-success"
style="--val: 30; --offset: 45"></circle>
</svg>
| Class | What it does |
|---|---|
.chart-pie |
On the <svg>. Rotates the layout by
−90° so the first segment starts at the 12 o'clock position.
|
.pie-bg |
The gray background ring, visible under the segments. |
.pie-segment |
A segment. Takes its color from
currentColor - set it with a text class
(.text-primary), not a fill
attribute.
|
Ring thickness lives in code, not in a class
There's no "Pie" or "Donut" modifier - thickness is the
stroke-width on the circle in SCSS
(6 by default). A full circle instead of a ring requires
editing the framework source; it can't be set from the markup.
5. Funnels
Three shapes for the same idea - a shrinking width reflects the drop in numbers at each next stage. The choice depends on how much vertical space you have and how literal the funnel shape needs to be.
| Class | Layout | When |
|---|---|---|
.chart-funnel |
Vertical, rectangular bars | A narrow column, a dashboard. |
.chart-pipeline |
Horizontal, chevron arrows | CRM process stages: "Contact → Offer → Contract". |
.chart-funnel-true |
A trapezoid with a "stem" | A presentation slide, a report - the most literal funnel shape. |
<div class="chart-funnel">
<div class="funnel-stage" style="--val: 100%">Visits: 1000</div>
<div class="funnel-stage" style="--val: 60%">Cart: 600</div>
<div class="funnel-stage" style="--val: 25%">Purchase: 250</div>
</div>
<div class="chart-pipeline">
<div class="pipeline-stage is-active">Contact</div>
<div class="pipeline-stage">Offer</div>
<div class="pipeline-stage">Contract</div>
</div>
| Class | Variant | What it does |
|---|---|---|
.funnel-stage |
Vertical |
A bar. Width: --val as a percentage.
|
.pipeline-stage |
Horizontal |
An arrow segment. Color via
--stage-bg / --stage-text.
Current stage: .is-active.
|
.funnel-true-stage |
Trapezoid |
A funnel layer. Height: --val as a
proportion (flex), not a percentage.
|
.stage-label |
Trapezoid | The stage's name. |
.stage-value |
Trapezoid | The number next to the stage. |
6. Stat cards, empty states, navigation
Stat cards
<div class="stat-card">
<div class="stat-title">Revenue</div>
<div class="stat-value">$124,500</div>
<div class="stat-trend is-positive"><svg class="icon" aria-hidden="true"><use href="img/icons-sprite.svg#ph-trend-up"></use></svg> 12%</div>
</div>
Empty state
A placeholder for where the chart goes before there's any data - a filter with no results, a fresh account. Without it, an empty container looks like a loading failure.
<div class="empty-state">
<div class="empty-state-icon"><svg class="icon" aria-hidden="true"><use href="img/icons-sprite.svg#ph-chart-bar"></use></svg></div>
<p class="fw-bold m-0">No data for this period</p>
</div>
Range navigation
A segmented switch above the chart - "Q1 / Q2 / Q3". State is held by a hidden radio field, so switching works without a single line of JavaScript.
| Class | Component | What it does |
|---|---|---|
.stat-card |
Stat card | Wrapper. |
.stat-title |
Stat card | The metric's label. |
.stat-value |
Stat card | The large number. |
.stat-trend |
Stat card |
The change. .is-positive (green) or
.is-negative (red).
|
.empty-state |
Empty state | Wrapper with a dashed border. |
.empty-state-icon |
Empty state | A large icon or emoji. |
.chart-nav |
Navigation | The switch's wrapper. |
.chart-nav-item |
Navigation |
On a <label>. Contains a hidden
input[type="radio"] (shared
name) and a .nav-label.
|
7. Pitfalls
1
Wrong --offset math in a pie chart
Every segment needs the sum of the shares of
every segment before it, not its own
position in the order. The third segment with shares
45/30/25 has --offset: 75
(45+30), not --offset: 2. The bug shows up
as overlapping segments - exactly as if
--offset hadn't been set at all.
2
Changing the pie chart's viewBox
viewBox="0 0 36 36" and
r="15.9155" aren't arbitrary - a radius of
15.9155 gives a circle circumference of exactly 100.
That's what makes --val: 45 in
stroke-dasharray mean exactly 45% of the
circumference, with no conversion needed. Changing one
number without the other breaks that relationship and the
segments stop matching the intended percentages.
3
--val as a percentage where it's actually a fraction
In the heatmap, --val is directly the color
opacity (0-1), not a percentage like everywhere else in
this component family. Typing --val: 70
instead of --val: 0.7 doesn't throw an error
- it just makes every such cell come out fully saturated,
regardless of the actual difference between values.
4
Segment color via fill instead of a text class
.pie-segment takes its color from
currentColor, i.e. the element's text color.
A fill="…" attribute written directly on the
<circle> does nothing - you need to add
a class like .text-primary instead.
5
A known exception to the GPU rule: .funnel-stage
The vertical funnel animates the --val change
via a transition on width - a property the
rest of the framework deliberately avoids, since it forces
a layout recalculation (see
Animations, section 1).
In practice it applies to a single element that rarely
changes and never in response to scrolling, so the cost
is negligible - but if you're building a funnel with
dozens of bars animating at once, consider switching to
.chart-funnel-true or your own animation via
transform: scaleX().