Charts in HTML and CSS

Every chart on this page is a table, list or meter with a stylesheet. No JavaScript chart libraries here. This page's scripts are just for some page Interactivity, but not for the charts themselves.

The approach

This page shows techniques for building charts in just HTML and CSS. There is no library, nothing to download. Follow the guidelines, and implement the patterns to turn semantic elements into visuals.

  1. Start with the element that already means the right thing. A <table> for one or more series, <meter> for a value against a limit, a list for a sequence, <data> for machine readable numbers. Without the stylesheet every chart is still a readable table or list, and screen readers get real rows, headers and names.
  2. Give CSS the numbers as custom properties. CSS can't parse text, so each value appears twice, once for people and once for layout: <td style="--v:2480">2,480</td>. Showing that number with attr() in content: wouldn't be accessible, as it only works for pseudo-elements. A little duplication here is fine. When an element already holds the number in an attribute, like <meter value>, CSS can read it with a typed attr(value number) instead.
  3. Draw with what CSS already has. Backgrounds get sized by a value to make bars, color-mix() can be used for heatmaps, conic-gradient() can makes slices, and pseudo-elements turned with atan2() can make line segments. sibling-index() and sibling-count() handle colours and positions without numbering anything by hand.
  4. Scale in calc(). (value - min) / (max - min) gives a fraction from 0 to 1. The author sets --min and --max on the chart, because CSS can't search siblings for the largest value.
  5. Interact with selectors. Use selectors like :hover to show tooltips on rows, :has() to react to interactions elsewhere, checkboxes can be used in the the legend to hide series data.

Choosing a chart

  • A value against a limit: meter.
  • A headline value against a limit, dashboard style: gauge.
  • One series of values: column chart.
  • Several series per category: bar chart.
  • The spread of values in each category: box plot.
  • Values across two dimensions: heatmap.
  • Parts of a whole: donut.
  • A headline number with its trend: stat tile and sparkline.
  • Values over time, one or more series: line chart, with the area variant for a single series.
  • Two measures for each item, and how they relate: scatter plot.
  • Values at places: map, a scatter plot over land.

Colours on this page come from openswatch (@import "https://unpkg.com/openswatch@0.1.0"). This is a good default if you don't know what theme to pick but use whatever colour tokens your site already has!

The charts run from simplest to most involved, each next to notes on how it's built, so you can copy the parts you need.

Meters

A value against a limit, with semantic colour.

Capacity

Usage against what the fleet has.

How it works

<meter> already exists in the browser and does all the heavy lifting. It stores the value, the limit and which end is good. optimum=, low=, and high= attributes can split the range into three regions, and the browser will work it out for you.

<label>Connections<small>8,420 of 10,000</small>
  <meter value="8420" max="10000" low="8000" high="9500" optimum="0"></meter>
</label>

Wrapping the meter in its <label> makes the visible figures part of its accessible name. Turn off the native look with appearance: none, then use CSS to paint each region. Chromium and Firefox use different pseudo-elements (for now), so be careful - define each in its own rule to avoid browsers dropping the rule. :is() can't be used - it doesn't support pseudos. One day these will be standardised...

meter {
  appearance: none;
  background: var(--track);
}
meter::-webkit-meter-bar { background: var(--track) }
meter::-webkit-meter-optimum-value { background: var(--ok) }
meter::-webkit-meter-suboptimum-value { background: var(--warn) }
meter::-webkit-meter-even-less-good-value { background: var(--danger) }
meter::-moz-meter-bar { background: var(--ok) }
meter:-moz-meter-sub-optimum::-moz-meter-bar { background: var(--warn) }
meter:-moz-meter-sub-sub-optimum::-moz-meter-bar { background: var(--danger) }

The value can't pass max, so the danger region has to start below it; here high is 95% of the limit.

Gauges

A headline value against a limit, drawn as an arc with its thresholds marked around the outside.

Fleet health

Current usage against each limit.

How it works

Still a <meter>, with the same attributes as above, so without CSS it falls back to a bar. Typed attr() reads the value, limit and thresholds straight from the markup, so no additional custom properties needed. This CSS treats a missing threshold as max, so a bare meter is all green; min is taken to be 0.

<label class="gauge">CPU
  <meter value="59" max="100" low="70" high="90" optimum="0"></meter>
  <span>59%</span>
</label>
.gauge meter {
  --v: clamp(0, attr(value number, 0), var(--max));
  --max: attr(max number, 1);
  --low: attr(low number, var(--max));
  --high: attr(high number, var(--max));
}

The meter's own bar is hidden, instead CSS paints two 240° conic-gradient() layers. The value layer is clipped to the content-box, which padding and border-radius: 50% shrink to a smaller circle. The threshold layer fills the border-box underneath. One radial mask then keeps only the thick inner ring and the thin outer one.

.gauge meter {
  box-sizing: border-box;
  padding: calc(var(--size) * .05);
  border-radius: 50%;
  background:
    conic-gradient(from -120deg, var(--c) calc(var(--v) / var(--max) * 240deg), var(--track) 0 240deg, transparent 0) content-box,
    conic-gradient(from -120deg, var(--ok) calc(var(--low) / var(--max) * 240deg), var(--warn) 0 calc(var(--high) / var(--max) * 240deg), var(--danger) 0 240deg, transparent 0) border-box;
  mask: radial-gradient(closest-side, transparent 64%, #000 calc(64% + 1px) 86%, transparent calc(86% + 1px) 92%, #000 calc(92% + 1px));
}
.gauge meter::-webkit-meter-bar { visibility: hidden }
.gauge meter::-moz-meter-bar { visibility: hidden }

Chromium only exposes the meter's region through its pseudo-elements, which can't colour the arc. So CSS is needed: sign(value - threshold) is 1 above the threshold and 0 or -1 at or below it. That assumes lower is better (a low optimum, as here), which matches the regions the meter itself uses. This can be scaled to a percentage and floored at 0%, which lets color-mix() toggle between two colours. Two nested mixes give the three regions.

--c: color-mix(in srgb, var(--danger) max(0%, sign(var(--v) - var(--high)) * 100%),
       color-mix(in srgb, var(--warn) max(0%, sign(var(--v) - var(--low)) * 100%), var(--ok)));

The arc's open bottom ends a quarter of the way up the box, so the row holding it is only 85% as tall, leaving a little room under the arc. This can be accounted for:

.gauge { grid-template-rows: auto calc(var(--size) * .85) }

Typed attr() outside content is new. Gauge rules sit inside @supports (width: attr(x px)), so browsers without it get the plain meter bar with the number under it.

Column chart

One series of values, each drawn as a column. Hover a column for its value.

Latency distributionRequests per 25 ms bucket, last hour.
From (ms)Requests
0120
25840
502,310
753,120
1002,480
1251,520
150830
175410
200220
225130
25070
27540
300+60

How it works

It's a <table>! Each row is one column. Cells hold the values as text (for people), that has to be duplicated as a custom property for layout; attr() won't work here as the <td> needs text content to remain accessible, so some duplication is necessary:

<tr><th>75<td style="--v:3120">3,120

The cell fills the plot height, the bar is a background (linear-gradient) sized using the value property, and bottom padding lifts the text (shown on hover) onto the top of the bar.

.cols tr { flex: 1; min-width: 0; position: relative }
.cols td {
  --bar: calc(var(--v) / var(--max) * var(--h));
  height: 100%;
  padding-bottom: calc(var(--bar) + .2rem);
  background: linear-gradient(var(--s2) 0 0) bottom / calc(100% - 3px) var(--bar) no-repeat;
  font-size: 0;
}
.cols tbody:has(tr:hover) tr:not(:hover) td { opacity: .4 }
.cols tr:hover td { font-size: .8rem; font-weight: bold }

The gap between columns is painted inside the background (calc(100% - 3px)). A real gap would end up with hover state underneath the columns, so the dimming flickers on and off as the pointer crosses it. Instead cheat with linear-gradient transparency.

min-width: 0 stops the value that appears on hover from widening its column and causing layout shifts.

Gridlines are one background tile a quarter of the plot high. Using a repeating gradient with 25% stops would land on fractional pixels, so won't be rendered correctly in all browsers.

Axis labels sit on each column's left edge. The <th> spans the column and centres its text in a zero-width grid track (grid-template-columns: 0; justify-items: center).

Bar chart

Several series side by side. Hover a row for its values; click a legend entry to hide a series, hover one to isolate it.

Response time by regionMean response time per endpoint, in milliseconds. Shorter is better.
Endpoint
/1.79 ms618.91 ms38.92 ms2.8 ms
/login4.64 ms686.19 ms42.18 ms11.61 ms
/help2.43 ms655.67 ms38.02 ms4.03 ms
/checkout11.31 ms1,043.49 ms48.18 ms23.76 ms
/cart14.53 ms1,101.01 ms50.47 ms26.8 ms
/account6.33 ms755.06 ms43.17 ms8.41 ms
/orders1,017.48 ms48.34 ms25.44 ms
/settings3.1 ms676.97 ms39.86 ms5.1 ms
/products4.43 ms781.78 ms40.99 ms7.7 ms
/product/:id5.99 ms783.45 ms40.86 ms10.29 ms
/static2.77 ms640.76 ms37.47 ms3.53 ms
/api/graphql33.94 ms1,347.23 ms66.52 ms78.07 ms
/feed2.53 ms670.37 ms38.88 ms4.53 ms
/health1.44 ms570.56 ms37.38 ms2.32 ms
/api/users1.66 ms611.04 ms37.39 ms2.79 ms
/reports/export226.06 ms3,202.03 ms1,445.99 ms265.22 ms
/api/items3.28 ms713.34 ms39.4 ms5.51 ms

How it works

Another <table>; this one has one row per endpoint, one column per region. The column headers double as the legend, and each header also contains a checkbox for the legend:

<thead><tr><th>Endpoint<th id="eu-west"><label><input type="checkbox" checked>eu-west</label>...</thead>
<tbody>
  <tr><th>/login<td headers="eu-west" style="--v:4.64">4.64 ms<td headers="us-east" ...>

Each row is a two-column grid, with the header spanning every bar. Each cell is a bar, (using the background property - as wide as its value). Left padding of the same width menas the hover label sits where the bar ends. min() keeps long labels inside the plot. attr(headers) pulls out the name for the label, and the same attribute ties the cell to its column header for assistive tech.

.bars { --bar: .85rem; --plot: calc(100cqw - 11rem) }
.bars tbody tr { display: grid; grid-template-columns: 11rem 1fr }
.bars tbody th { grid-row: span 16; align-self: center }
.bars td {
  --w: calc(var(--v, 0) / var(--max) * var(--plot));
  padding-left: min(var(--w) + .3rem, var(--plot) - 11rem);
  background: linear-gradient(var(--c) 0 0) 0 50% / var(--w) calc(100% - 3px) no-repeat;
}
.bars td::before { content: attr(headers) " " }

Series colours come from each cell's position, so headers and cells in a column always match. --c is registered with @property so it is computed on the cell itself; sibling-index() would be re-evaluated wherever --c is used. --n can stay unregistered because it is only used inside --c, on the same cell.

@property --c { syntax: "<color>"; inherits: true; initial-value: currentColor }
:is(.chart thead th, .chart td, .donut li) {
  --n: calc(var(--hue) + sibling-index() * 360 / sibling-count());
  --c: light-dark(oklch(var(--color-lightness-8) var(--color-chroma-8) var(--n)), oklch(var(--color-lightness-6) var(--color-chroma-6) var(--n)));
}

The legend toggles and highlights are shared with the line charts and covered there. The x-axis labels are counters separated by tabs, with tab-size set to a fifth of the plot so each label starts on a gridline.

.bars::after {
  content: counter(x0) "\9" counter(x1) "\9" counter(x2) "\9" counter(x3) "\9" counter(x4) "\9" counter(x5);
  counter-reset: x0 0 x1 calc(var(--max) / 5) x2 calc(var(--max) * 2 / 5) x3 calc(var(--max) * 3 / 5) x4 calc(var(--max) * 4 / 5) x5 var(--max);
  white-space: pre;
  tab-size: calc(var(--plot) / 5);
}

Box plot

The spread of values in each category. Hover a row for its percentiles.

Response time by endpointLast 24 hours. Whiskers run from p5 to p95, the box from p25 to p75, and the line marks the median.
Endpointp5p25medianp75p95
/18 ms32 ms45 ms70 ms140 ms
/login40 ms65 ms90 ms130 ms260 ms
/search60 ms120 ms210 ms340 ms720 ms
/checkout90 ms160 ms230 ms310 ms520 ms
/api/orders25 ms50 ms75 ms120 ms300 ms
/api/users12 ms20 ms28 ms40 ms85 ms
/reports150 ms280 ms420 ms610 ms940 ms
/upload80 ms200 ms360 ms520 ms880 ms

How it works

A box runs from p25 to p75, so one element needs both numbers. CSS can't read a neighbouring cell, so the row carries all five as custom properties; while the cells hold well formatted text.

<tr style="--p5:60;--p25:120;--p50:210;--p75:340;--p95:720"><th>/search<td headers="p5">60 ms<td headers="p25">120 ms...

The row is the same grid as the bar chart, but it makes use of ::before to fill the plot column.Each of the marks is cheated with a linear-gradient layer, offset to its value and sized to the span. --scale calculates how the values become lengths.

.box tbody tr { --scale: calc(var(--plot) / var(--max)) }
.box tbody tr::before {
  content: ""; grid-area: 1 / 2; height: 1.25rem;
  background:
    /* median */ linear-gradient(var(--s2) 0 0) calc(var(--p50) * var(--scale) - 1.5px) 0 / 3px 100%,
    /* box */ linear-gradient(color-mix(in srgb, var(--s2) 35%, var(--card)) 0 0) calc(var(--p25) * var(--scale)) 0 / calc((var(--p75) - var(--p25)) * var(--scale)) 100%,
    /* caps */ linear-gradient(90deg, var(--s2) 2px, transparent 0 calc(100% - 2px), var(--s2) 0) calc(var(--p5) * var(--scale)) 50% / calc((var(--p95) - var(--p5)) * var(--scale)) 50%,
    /* whisker */ linear-gradient(var(--s2) 0 0) calc(var(--p5) * var(--scale)) 50% / calc((var(--p95) - var(--p5)) * var(--scale)) 2px;
  background-repeat: no-repeat;
}

Tooltips are powered by the cells. They are positioned under the median and stacked with sibling-index(). min() stops the tooltip running off the end of the plot, and on the last three rows it opens upwards. The label in each line is its headers attribute. You could use anchor positioning here, but a couple of calc()s is likely simpler.

.box tbody td {
  position: absolute;
  top: calc(100% + (sibling-index() - 2) * 1.4rem);
  left: calc(11rem + min(var(--p50) * var(--scale), var(--plot) - 8rem));
  width: 8rem;
}
.box tbody tr:nth-last-child(-n+3) td { top: auto; bottom: calc(100% + (sibling-count() - sibling-index()) * 1.4rem) }
.box tbody td::before { content: attr(headers) }

Heatmap

A grid of values shown as colour. Hover a cell for its value.

Requests by hourThousands of requests, last week, UTC.
000102030405060708091011121314151617181920212223
Mon878789915193446659412310510310087635254302211
Tue7789891114233045681011101111159572675744352013
Wed97978101015193657761061061251159876686147361712
Thu899881091520314580851031141248476636052381911
Fri899788101523324572921141341189779654753372213
Sat333434461014203038484656453126232014106
Sun4433445691824304443545848372623191796

How it works

One row per day, one cell per hour. display: contents on the row groups and rows puts every cell in one grid on the table, which keeps the columns square and aligned.

.heat { display: grid; grid-template-columns: 3rem repeat(24, minmax(0, 1fr)) }
.heat :is(thead, tbody, tr) { display: contents }
.heat tbody td {
  aspect-ratio: 1;
  min-height: 0;
  background: color-mix(in oklab, var(--hot) calc(var(--v) / var(--max) * 100%), var(--cold));
}
.heat tr:has(td:hover) th { color: var(--text); font-weight: bold }

color-mix() takes a percentage, so the value goes straight in. The label column has a fixed width because the day label turns bold on hover, and an auto track would grow and shift every cell. min-height: 0 lets the hover value overflow a small cell instead of stretching its row. The scale is the table's ::after, a gradient between the same two colours, with text-align-last: justify pushing "0" and the maximum to either end.

Donut

Parts of a whole. Hover a slice or its legend entry.

Traffic by regionShare of requests, last 24 hours.
  • Europe 38%
  • North America 31%
  • Asia 18%
  • South America 8%
  • Oceania 5%

How it works

A list, one item per slice. CSS can't add up earlier siblings, so each item states where its slice starts and ends, in percent, which makes this less trivial to implement in markup.

<li style="--from:38;--to:69">North America <data value="31">31%</data>

Every slice is a full-size circle drawn behind the legend: a conic-gradient() coloured only between its two angles, with a radial mask for the hole.

.donut li::before {
  --f: calc(var(--from) * 3.6deg);
  --t: calc(var(--to) * 3.6deg);
  --s: calc((var(--t) - var(--f)) / 4);
  background: conic-gradient(var(--c) calc(var(--f) + .6deg) calc(var(--t) - .6deg), transparent 0);
  mask: radial-gradient(closest-side, transparent 58%, #000 calc(58% + 1px));
}

By using gradients, hit testing still works so transparent parts still trigger hover, and there's no flickering as the user moves their pointer. clip-path trims each one to a polygon from the centre through five points on its arc, placed with sin() and cos(). The 71% radius reaches the corners of the box, so the polygon covers the arc while each step is 90° or less.

clip-path: polygon(50% 50%,
  calc(50% + 71% * sin(var(--f) + var(--s) * 0)) calc(50% - 71% * cos(var(--f) + var(--s) * 0)),
  calc(50% + 71% * sin(var(--f) + var(--s) * 1)) calc(50% - 71% * cos(var(--f) + var(--s) * 1)),
  /* ...the same for * 2, * 3 and * 4 */);

The slice is the item's own pseudo-element, so hovering the slice and hovering its legend entry are the same thing.

Stat tiles and sparklines

A headline number, with a coloured subtitle showing its movement compared to the last period, and its recent history as a sparkline. Hover the sparkline for each sample.

Requests per second

1,350

vs 30 s ago

  1. 1,310 req/s
  2. 1,342 req/s
  3. 1,330 req/s
  4. 1,385 req/s
  5. 1,371 req/s
  6. 1,420 req/s
  7. 1,452 req/s
  8. 1,440 req/s
  9. 1,498 req/s
  10. 1,510 req/s
  11. 1,495 req/s
  12. 1,530 req/s
  13. 1,502 req/s
  14. 1,488 req/s
  15. 1,515 req/s
  16. 1,470 req/s
  17. 1,462 req/s
  18. 1,420 req/s
  19. 1,377 req/s
  20. 1,350 req/s

Error rate (%)

0.35

vs 30 s ago

  1. 0.31%
  2. 0.33%
  3. 0.32%
  4. 0.34%
  5. 0.31%
  6. 0.36%
  7. 0.52%
  8. 0.33%
  9. 0.31%
  10. 0.34%
  11. 0.32%
  12. 0.49%
  13. 0.47%
  14. 0.48%
  15. 0.31%
  16. 0.33%
  17. 0.32%
  18. 0.34%
  19. 0.38%
  20. 0.35%

p95 latency (ms)

197

vs 30 s ago

  1. 150 ms
  2. 152 ms
  3. 149 ms
  4. 160 ms
  5. 155 ms
  6. 175 ms
  7. 153 ms
  8. 152 ms
  9. 158 ms
  10. 170 ms
  11. 165 ms
  12. 180 ms
  13. 185 ms
  14. 172 ms
  15. 160 ms
  16. 154 ms
  17. 162 ms
  18. 158 ms
  19. 171 ms
  20. 197 ms

Healthy services

11

vs 30 s ago

  1. 12
  2. 12
  3. 12
  4. 12
  5. 8
  6. 12
  7. 12
  8. 12
  9. 8
  10. 8
  11. 8
  12. 12
  13. 12
  14. 12
  15. 11
  16. 11

How it works

The current and previous values, and whether higher is better, are custom properties. CSS works out the percentage change.

<article class="card stat" style="--value:197;--previous:171;--better:-1">
  <h3>p95 latency (ms)</h3>
  <data value="197">197</data>
  <p>vs 30 s ago</p>
@counter-style sign { system: fixed -1; symbols: "\2212" "\B1" "+" }
.stat { --pct: round((var(--value) / var(--previous) - 1) * 100) }
.stat p { color: color-mix(in srgb, var(--ok) clamp(0%, (sign(var(--pct) * var(--better)) + 1) * 100%, 100%), var(--danger)) }
.stat p::before { counter-reset: s sign(var(--pct)) p abs(var(--pct)); content: counter(s, sign) counter(p) "% " }

sign(pct * better) is 1 for good news, 0 for no change and -1 for bad. As a percentage it can pick a colour using color-mix(). Counters are the only way to print a computed number, but they only print integers and never a "+", so a second counter style with system: fixed -1 maps -1, 0 and 1 to "−", "±" and "+" to get the sign.

The sparkline is created from the ordered list, one item per sample. Each item needs its own value and the previous one as CSS, because CSS can't read a sibling's custom properties.

<ol class="spark" style="--min:145;--max:200" aria-label="Last 20 samples">
  <li style="--b:150"><data value="150">150 ms</data>
  <li style="--a:150;--b:152"><data value="152">152 ms</data>

--y0 and --y1 scale both ends of the item's segment into a range. Each item is a size container, so its pseudo elements can use cqw and cqh. The segment back to the previous point is a 2px bar as long as the hypotenuse, turned by atan2(), so its thickness stays consistent no matter how steep.

.spark li {
  --y0: calc((var(--a, var(--b)) - var(--min)) / (var(--max) - var(--min)));
  --y1: calc((var(--b) - var(--min)) / (var(--max) - var(--min)));
  width: calc(100% / (sibling-count() - 1));
  container-type: size;
}
.spark li:first-child { margin-left: calc(-50% / (sibling-count() - 1)) }
.spark li::before {
  left: calc(-50cqw - 1px);
  bottom: calc(var(--y0) * 100% - 1px);
  height: 2px;
  transform-origin: 1px 50%;
  width: calc(hypot(100cqw, (var(--y1) - var(--y0)) * 100cqh) + 2px);
  rotate: atan2((var(--y0) - var(--y1)) * 100cqh, 100cqw);
}

Points sit at the centre of each item, and the first item is pulled left by half a step. That makes every item's hoverable by its nearest point and keeps the line edge to edge. The segment is 2px longer than the gap so the round ends overlap at each join.

Line and area charts

Values over time. Hover anywhere in a plot for every value at that point; click a legend entry to hide a series, hover one to isolate it.

TrafficRequests per second, the last 30 seconds.
Time
23:37:161,340 req/s
23:37:171,360 req/s
23:37:181,395 req/s
23:37:191,370 req/s
23:37:201,430 req/s
23:37:211,425 req/s
23:37:221,460 req/s
23:37:231,450 req/s
23:37:241,445 req/s
23:37:251,480 req/s
23:37:261,490 req/s
23:37:271,500 req/s
23:37:281,505 req/s
23:37:291,510 req/s
23:37:301,495 req/s
23:37:311,530 req/s
23:37:321,545 req/s
23:37:331,540 req/s
23:37:341,535 req/s
23:37:351,520 req/s
23:37:361,525 req/s
23:37:371,560 req/s
23:37:381,555 req/s
23:37:391,525 req/s
23:37:401,510 req/s
23:37:411,500 req/s
23:37:421,465 req/s
23:37:431,475 req/s
23:37:441,440 req/s
23:37:451,425 req/s
23:37:461,340 req/s
Latency trendsDaily median latency per endpoint, in microseconds. Under the 13 ms target is good.
Date
8 Jun2,104 µs10,047 µs3,360 µs21,930 µs24,520 µs8,165 µs21,460 µs4,366 µs7,127 µs8,944 µs3,139 µs4,020 µs1,599 µs2,110 µs5,211 µs
2 Jul1,818 µs8,668 µs2,944 µs18,925 µs21,821 µs7,389 µs18,756 µs3,953 µs5,620 µs7,561 µs2,573 µs3,384 µs1,323 µs1,772 µs4,412 µs
6 Jul2,081 µs9,534 µs3,361 µs21,909 µs25,681 µs8,820 µs22,105 µs4,339 µs6,899 µs8,742 µs2,816 µs3,880 µs1,432 µs1,937 µs4,848 µs
9 Jul2,236 µs10,300 µs3,621 µs23,623 µs27,158 µs9,485 µs24,984 µs4,681 µs6,705 µs9,510 µs3,076 µs4,235 µs1,621 µs2,302 µs5,306 µs
12 Jul2,346 µs11,073 µs3,757 µs24,672 µs27,317 µs9,601 µs24,199 µs4,801 µs7,843 µs10,021 µs3,272 µs4,400 µs1,609 µs2,194 µs5,588 µs
16 Jul2,215 µs10,525 µs3,542 µs24,409 µs26,985 µs9,336 µs23,593 µs4,451 µs7,229 µs9,379 µs3,104 µs4,179 µs1,519 µs2,073 µs5,157 µs
19 Jul2,577 µs11,830 µs3,998 µs27,305 µs29,552 µs10,687 µs25,980 µs4,918 µs8,040 µs10,597 µs3,438 µs4,473 µs1,696 µs2,302 µs5,656 µs
22 Jul2,126 µs10,493 µs3,479 µs25,314 µs27,911 µs9,476 µs24,250 µs4,484 µs7,394 µs9,859 µs2,944 µs4,073 µs1,476 µs2,007 µs5,202 µs
1 Aug2,259 µs8,759 µs3,474 µs21,295 µs23,988 µs7,970 µs20,662 µs4,311 µs6,913 µs8,845 µs2,772 µs4,026 µs1,820 µs2,299 µs4,892 µs
4 Aug1,751 µs6,555 µs2,709 µs16,031 µs18,715 µs5,859 µs15,337 µs3,255 µs5,200 µs6,579 µs2,177 µs3,379 µs1,465 µs1,946 µs3,819 µs
7 Aug1,676 µs6,019 µs2,479 µs14,373 µs16,001 µs5,270 µs13,792 µs3,099 µs4,692 µs5,964 µs2,054 µs2,839 µs1,339 µs1,751 µs3,433 µs
11 Aug2,148 µs7,695 µs3,260 µs18,112 µs20,571 µs6,994 µs17,780 µs4,040 µs6,227 µs8,006 µs2,661 µs3,797 µs1,786 µs2,323 µs4,566 µs
14 Aug2,456 µs9,430 µs3,716 µs22,616 µs26,294 µs8,502 µs21,818 µs4,585 µs7,316 µs10,093 µs3,102 µs4,336 µs1,890 µs2,420 µs5,259 µs
17 Aug2,263 µs8,204 µs3,482 µs19,854 µs22,682 µs7,517 µs19,188 µs4,448 µs7,013 µs9,316 µs2,838 µs4,142 µs1,919 µs2,490 µs5,655 µs
21 Aug2,000 µs7,670 µs3,063 µs17,513 µs19,660 µs6,702 µs17,095 µs3,732 µs5,784 µs7,389 µs2,460 µs3,526 µs1,652 µs2,149 µs4,320 µs
28 Aug2,453 µs11,103 µs3,812 µs24,773 µs27,682 µs8,686 µs23,750 µs4,772 µs7,404 µs9,994 µs3,151 µs4,285 µs1,984 µs2,485 µs5,463 µs
1 Sep2,385 µs10,806 µs3,709 µs25,317 µs28,275 µs9,257 µs24,461 µs4,718 µs7,414 µs10,434 µs3,111 µs4,244 µs1,784 µs2,342 µs5,402 µs
4 Sep2,856 µs12,168 µs4,404 µs28,058 µs31,485 µs10,060 µs27,496 µs5,369 µs8,529 µs12,065 µs3,470 µs4,998 µs2,462 µs2,866 µs6,969 µs
7 Sep2,637 µs11,608 µs4,090 µs27,332 µs30,648 µs9,529 µs26,192 µs5,022 µs8,035 µs11,284 µs3,213 µs4,631 µs2,128 µs2,667 µs5,721 µs
11 Sep2,186 µs9,344 µs3,328 µs21,112 µs23,675 µs7,520 µs20,574 µs4,107 µs6,374 µs8,885 µs2,658 µs3,791 µs1,717 µs2,186 µs4,642 µs
14 Sep2,659 µs11,570 µs4,279 µs27,100 µs30,112 µs9,428 µs25,523 µs5,007 µs8,239 µs11,229 µs3,218 µs4,604 µs2,037 µs2,586 µs5,738 µs
17 Sep2,647 µs11,710 µs4,068 µs27,753 µs30,840 µs9,593 µs26,421 µs5,008 µs8,065 µs11,283 µs3,183 µs4,582 µs2,023 µs2,611 µs5,832 µs
21 Sep2,648 µs12,079 µs4,109 µs28,158 µs31,627 µs9,743 µs27,799 µs5,115 µs8,202 µs11,611 µs3,270 µs4,679 µs2,077 µs2,601 µs5,891 µs
29 Sep2,607 µs11,972 µs4,085 µs27,329 µs30,893 µs9,389 µs26,974 µs5,034 µs8,138 µs11,285 µs3,166 µs4,594 µs2,038 µs2,572 µs5,728 µs
2 Oct2,759 µs12,109 µs4,189 µs27,846 µs31,056 µs9,744 µs27,131 µs5,271 µs8,389 µs11,594 µs3,299 µs4,841 µs2,122 µs2,717 µs5,925 µs
6 Oct2,467 µs11,204 µs3,864 µs27,413 µs30,965 µs9,467 µs26,913 µs4,898 µs7,952 µs11,347 µs2,963 µs4,439 µs1,893 µs2,425 µs5,582 µs
9 Oct2,243 µs9,419 µs3,374 µs21,458 µs24,318 µs7,603 µs21,193 µs4,241 µs6,584 µs9,037 µs2,650 µs3,823 µs1,733 µs2,221 µs4,772 µs
12 Oct2,201 µs9,432 µs3,301 µs20,951 µs23,740 µs7,457 µs20,718 µs4,115 µs6,406 µs8,905 µs2,638 µs3,758 µs1,720 µs2,160 µs4,572 µs
16 Oct1,872 µs7,768 µs2,721 µs15,214 µs17,114 µs5,648 µs15,098 µs3,322 µs4,949 µs6,921 µs2,151 µs3,075 µs1,548 µs1,886 µs3,683 µs
19 Oct2,878 µs11,486 µs3,972 µs23,582 µs27,276 µs8,130 µs23,879 µs5,526 µs7,543 µs10,391 µs3,369 µs4,470 µs2,218 µs2,738 µs5,457 µs
Latency trends, slowest endpointsKept apart so they don't flatten the chart above, in microseconds.
Date
8 Jun35,860 µs220,239 µs
2 Jul31,727 µs204,357 µs
6 Jul34,347 µs250,229 µs
9 Jul35,600 µs260,152 µs
12 Jul37,186 µs270,318 µs
16 Jul36,653 µs265,300 µs
19 Jul38,304 µs295,947 µs
22 Jul35,495 µs264,110 µs
1 Aug30,103 µs246,142 µs
4 Aug25,340 µs186,475 µs
7 Aug21,085 µs158,555 µs
11 Aug26,168 µs231,531 µs
14 Aug33,615 µs274,640 µs
17 Aug26,529 µs245,249 µs
21 Aug29,845 µs194,296 µs
28 Aug40,684 µs278,337 µs
1 Sep36,540 µs268,693 µs
4 Sep40,223 µs328,838 µs
7 Sep41,231 µs323,773 µs
11 Sep31,964 µs259,024 µs
14 Sep41,151 µs315,710 µs
17 Sep40,765 µs318,033 µs
21 Sep42,156 µs330,351 µs
29 Sep40,706 µs318,559 µs
2 Oct41,931 µs327,210 µs
6 Oct39,888 µs291,724 µs
9 Oct31,743 µs259,686 µs
12 Oct31,221 µs262,855 µs
16 Oct22,845 µs191,122 µs
19 Oct78,530 µs264,003 µs

How it works

Rows are x values, where each row is one date (or second) and each column is a series. Tooltips come from the row markup, :hover applies the crosshair (a dotted line using linear-gradient), a marker on the series and shows the tooltip. Every row is a full-height strip centred on the date. Hovering anywhere in the plot should pick the nearest date.

<thead><tr><th>Date<th id="/"><label><input type="checkbox" checked>/</label>...</thead>
<tbody>
  <tr><th>8 Jun<td headers="/" style="--b:2104">2,104 µs<td headers="/login" ...>
  <tr><th>2 Jul<td headers="/" style="--a:2104;--b:1818">1,818 µs ...

Lines. Each cell draws the segment back to its previous value, as in the sparkline. Here the segment is a 12px strip with the 2px line across its middle, at z-index: -1 so the hovered row's tooltip covers it. On hover, a dot at the end of each strip marks the value.

.lines tbody tr { --step: calc(100cqw / (sibling-count() - 1)); width: var(--step); position: relative }
.lines td::before {
  z-index: -1;
  left: calc(50% - var(--dx) - 1px);
  bottom: calc(var(--y0) * var(--h) - 6px);
  height: 12px;
  width: calc(hypot(var(--dx), (var(--y1) - var(--y0)) * var(--h)) + 8px);
  rotate: atan2((var(--y0) - var(--y1)) * var(--h), var(--dx));
  background: var(--line);
}

When hovered, the row becomes a grid for the toolip. Cells are normally zero-size, but when hovered move into a max-content column beside the crosshair. Every line is as wide as the longest. attr(headers) gives a name to each line. Over the last 12 rows the columns swap so the tooltip opens to the left (again, anchor position could be used here, but calc() is simple enough). pointer-events: none stops the tooltip catching the pointer where it overlaps the legend.

.lines tbody tr:hover { display: grid; grid-template-columns: calc(50% + 12px) max-content; align-content: start }
.lines td::after { content: attr(headers) ":"; order: -1; font-weight: normal }
.lines tbody tr:nth-last-child(-n+12):hover { grid-template-columns: max-content calc(50% + 12px); justify-content: end }

The legend uses the checkboxes in the column headers hide series, and hovering a header dims the others. CSS can't select "the cells in the same column as that header", so this is a fixed block of selectors, one per column, written once for up to 16 series. It never changes with the data, but it can be a chore to write.

.chart:has(thead th:nth-child(2) input:not(:checked)) td:nth-child(2),
.chart:has(thead th:nth-child(3) input:not(:checked)) td:nth-child(3),
/* ...up to nth-child(17) */ { display: none }
.chart:has(thead th:nth-child(2):hover) td:not(:nth-child(2)),
/* ...up to nth-child(17) */ { opacity: .15 }

The dashed threshold line isn't represented in data. Instead it's driven by --threshold, --threshold-label and --threshold-color on the table, and tbody::after is where it lives. Adding area to the class fills under the first series, one clip-path: polygon() per row. The y-axis labels are five counters computed from --min and --max.

<table class="chart lines area" style="--min:0;--max:2000;--hue:var(--color-green-base);--threshold:1800;--threshold-label:'Capacity';--threshold-color:var(--s2)">

Scatter plot

Two measures for each item, to see how they relate. Hover a point for its values.

Page weight and load timeTransfer size against largest contentful paint (p75), last 7 days.
PageTransfer size (KB)LCP (ms)
/420 KB1,180 ms
/pricing610 KB1,420 ms
/docs380 KB960 ms
/docs/api520 KB1,310 ms
/blog890 KB1,880 ms
/blog/launch1,640 KB3,120 ms
/about300 KB870 ms
/careers740 KB1,650 ms
/login210 KB640 ms
/signup260 KB790 ms
/dashboard1,380 KB2,450 ms
/settings450 KB1,240 ms
/search680 KB2,210 ms
/status150 KB520 ms
/changelog560 KB1,150 ms
/integrations1,120 KB2,280 ms
/customers1,820 KB3,540 ms
/contact240 KB1,960 ms
/legal180 KB560 ms
/security330 KB1,050 ms

How it works

Rows in the table become points, with a header and a cell for each measure. --x and --y values denote where it goes in the plot, the text content provides the formatted label. The table sets the range of each axis.

<table class="scatter" style="--x-min:0;--x-max:2000;--min:0;--max:4000">
  ...
  <tr style="--x:1640;--y:3120"><th>/blog/launch<td>1,640 KB<td>3,120 ms

Each value becomes a fraction of its axis, and the fractions become left and bottom percentages. The row is a small box centred on its point with translate. The dot drawn as a radial-gradient, giving it a hit area bigger than the painted dot.

.scatter tbody tr {
  --px: calc((var(--x) - var(--x-min)) / (var(--x-max) - var(--x-min)));
  --py: calc((var(--y) - var(--min)) / (var(--max) - var(--min)));
  position: absolute; left: calc(var(--px) * 100%); bottom: calc(var(--py) * 100%);
  width: var(--s); height: var(--s); translate: -50% 50%; border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--dot) 70%, transparent) var(--r), transparent calc(var(--r) + .5px));
}

The rows are positioned against tbody, which needs an explicit display: block. Without it Safari doesn't treat the position: relative row group as the containing block.

.scatter tbody { display: block; position: relative }

The tooltips are driven by the cell data, just like the other table charts. A one-column max-content grid lays out the cells so they line up at the width of the longest. To keep the tooltip inside the plot, round() turns --px into 0 or 1 to pick a side of the point, and the tooltip slides up or down with --py.

.scatter tbody tr { --side: round(var(--px), 1); display: grid; grid-template-columns: max-content }
.scatter tbody tr > * {
  translate:
    calc(var(--s) / 2 + var(--gap) - var(--side) * (100% + 2 * var(--gap)))
    calc(var(--s) / 2 - (1 - var(--py)) * sibling-count() * 100%);
}

Axes get drawn counters just like the line and column charts above. The x-axis labels are counters separated by tabs, with tab-size set to a quarter of the plot, as in the bar chart above. The plot width is rounded down to a multiple of 4px so the vertical gridlines land on whole pixels. The column headers become the axis titles, and the dashed crosshair on hover is the row's ::before, with a dashed border.

.scatter tbody { --w: round(down, 100cqw - 2rem, 4px); width: var(--w) }
.scatter tbody::after { content: counter(x0) "\9" counter(x1) ...; white-space: pre; tab-size: calc(var(--w) / 4) }

Map

Values at places. Hover a city for its sessions.

Sessions by cityLast 7 days. The area of each dot shows its sessions.
CitySessions
New York1,210 sessions
San Francisco980 sessions
Taipei893 sessions
London467 sessions
Seattle412 sessions
Chicago388 sessions
Toronto353 sessions
Bengaluru310 sessions
Austin296 sessions
Tokyo274 sessions
Sydney254 sessions
Lisbon241 sessions
Singapore208 sessions
Berlin206 sessions
Paris205 sessions
São Paulo188 sessions
Amsterdam162 sessions
Vancouver141 sessions
Seoul132 sessions
Dublin121 sessions
Mexico City96 sessions
Stockholm88 sessions
Buenos Aires74 sessions
Dubai70 sessions
Auckland66 sessions
Lagos63 sessions
Cape Town57 sessions
Nairobi41 sessions

How it works

A map is just a scatter plot with fixed points, longitude and latitude are both linear, so the scatter plot CSS places cities with an "equirectangular projection", good enough to point out countries and such. --x maps to longitude and --y to latitude. Longitude always spans the full 360 degrees, but latitude can be ranged to 84 north and 58 south, if you don't want to show the whole world. (Just remember to keep New Zealand)!

<table class="scatter map" style="--min:-58;--max:84;--v-max:1210">
  ...
  <tr style="--x:-0.13;--y:51.51;--v:467"><th>London<td>467 sessions

Area shows the value, and a third value, --v, sets each dot's radius, so you can represent geographical distribution. Using sqrt() to make the dot's area makes it easier to encode values, so a city with four times the count looks four times as big rather than sixteen. Rows are sorted largest first, so small dots sit on top of big ones and can still be hovered, and border-radius keeps each hit area round where neighbours crowd.

.map tbody tr { --r: calc(10px * sqrt(var(--v) / var(--v-max))) }

Land is the only image. CSS can't draw coastlines, so the land is a mask, a 160 by 80 grid of land cells, as a 2.7 KB SVG data URI. A radial-gradient tile paints one dot per cell. The layer covers the whole world, so it is moved up and clipped to the latitudes on show.

.map { --x-min: -180; --x-max: 180 }
.map tbody { aspect-ratio: calc(360 / (var(--max) - var(--min))) }
.map tbody::before {
  inset: calc((var(--max) - 90) / (var(--max) - var(--min)) * 100%) 0 auto; aspect-ratio: 2;
  background: radial-gradient(closest-side, var(--neutral-5) 70%, transparent 85%) 0 0 / calc(100% / 160) calc(100% / 80);
  mask: var(--world) 0 0 / 100% 100%;
  clip-path: inset(calc((90 - var(--max)) / 180 * 100%) 0 calc((90 + var(--min)) / 180 * 100%));
}

Use as an agent skill

This page doubles as a skill for coding agents, with every technique next to a working chart. Give your agent this prompt and it will download the page and build charts like these.

Install the html-graphs skill from the URL of this page. Download the page and follow its "Use as an agent skill" section.

For agents installing this skill

  1. Save this page, unchanged, as html-graphs/reference.html in your skills directory.
  2. Create html-graphs/SKILL.md with exactly the content below.
  3. When you later build a chart, the skill sends you back here.
---
name: html-graphs
description: Use when building charts, graphs, sparklines, meters, heatmaps or dashboards for the web. Builds them from semantic HTML and CSS, without a chart library or SVG.
---

Before building a chart, read reference.html in this directory in full and follow it. Start from "The approach" and "Choosing a chart", then copy the patterns of the matching chart.