Activity heatmap
A count per day over weeks or a year, as squares shaded from none to most.
Anatomy
Mar Apr May … ← month labels, aria-hidden, in the row headers
Mon ■ ■ □ ■ ■ ■ □ ■ ■ ■ … ← weekday labels (Mon, Wed, Fri shown)
□ ■ ■ ■ □ ■ ■ ■ □ ■ …
Wed … ← each square: a day, heat-0 … heat-4
Less □ ▪ ▪ ■ ■ More ← legend, aria-hidden
| Part | Token | Why |
|---|---|---|
| Square | size-2.5, rounded-[2px], gap 0.75 | 10px squares on a 13px pitch: a year fits in about 700px. |
| Shade | heat-0 … heat-4 | One hue at five strengths; see The ramp. |
| Hue | tone or series, as --ds-heat on the root | The steps read one custom property, so one class picks the hue. |
| Labels, legend | text-meta fg-muted | |
| Scroll box | overflow-x-auto, focus ring |
Structure and reading order
It is a <table>. In the DOM each week is a row and each weekday a
column: Monday (or Sunday) first, then the weeks in time order. A screen reader
moving through the table reads the days in the order they happened, one week
at a time, and a cell's column header says its weekday. Transposing it the
other way, weekday rows, would read every Monday of the year, then every
Tuesday: true to the picture and useless as a sequence.
The picture people know has weeks as columns, so CSS turns the table: the
table is a grid that flows by column (grid-flow-col, seven rows plus a label
row), and the rows, thead and tbody are display: contents. Each week's
row header holds the month name; the column headers hold the weekday names.
WebKit drops a table's semantics once its display changes, so table, row,
columnheader, rowheader and cell are written out as roles.
Days outside the range are empty cells, so every week has seven.
Names
Every day carries its sentence twice: as visually hidden text in the cell, read
in place, and as the cell's (or link's) title, the native tooltip for a
pointer. "12 contributions on 3 March 2026", "1 contribution on …", "No
contributions on …". unit is the noun, pluralised by Laravel's
Str::plural, or given as [singular, plural] for a language that needs it.
Dates are translatedFormat in the app's locale.
The caption is visually hidden: the label, then the total, the range and the
busiest day, or summary. It also names the scroll region
(aria-labelledby).
The legend is aria-hidden. Every cell says its count; "Less, More" and five
unnamed squares would be noise.
Levels
levels as a number n (2 to 5, counting none) takes quantiles over the
non-zero counts: the threshold for level k is the count at position
⌊(k−1)/(n−1)·N⌋ in the sorted list, duplicates dropped. The shades spread over
the data whatever its scale, and a year with one huge day still uses the
middle shades. As a list, the values are the lowest counts of the levels above
none ([1, 5, 10, 20]): a fixed scale for pages that compare. Fewer than five
levels pick spread-out steps of the ramp ([0, 2, 4] for three), so "some" and
"a lot" stay far apart. Zero is always level 0.
The ramp
heat-0 … heat-4 are generated by build-tokens.mjs from tokens/chart.json:
each step mixes the hue (--ds-heat) with the surface in OKLab, and the last
step also with fg, so the top of the ramp moves away from the surface in
both themes. Step 0 is a faint fg tint, so an empty day is a visible square
and not a hole.
test-tokens.mjs checks every hue (the five tones and eight series) in both themes: each step further from the surface than the last, and adjacent steps at least 1.15:1 in contrast and 7 in ΔE (OKLab ×100). The tightest is warning in dark, 1.22:1 and ΔE 8.4 between 3 and 4 (series-4 in light was, at 1.19:1, until 2.0 darkened it to clear 3:1 on the card). These are step contrasts for telling shades apart, not text contrast: no information is in the shade alone.
Scrolling
The table never shrinks. Its box is overflow-x: auto with direction: rtl,
which puts the scroll origin at the right edge: on a narrow screen it opens
showing the most recent weeks, with no script. The table inside is
direction: ltr again, so it reads left to right, and margin-right: auto
keeps a table that fits on the left. The box is a focusable region named by
the caption, so a keyboard can scroll it.
Month labels give way when they would collide: the first week of each month is marked, and a mark less than three weeks before the next one, or before the end, is dropped.
Links
With href, a day with a count is a link to href with {date} replaced by
its Y-m-d. Empty days are not links: there is nothing there, and a year of
365 Tab stops would make the page unusable from the keyboard.
Accessibility
| Role | table (explicit), inside a region |
| Name | the caption: label and summary sentence |
| Cells | the day's sentence, in text |
| Key | Does |
|---|---|
| Tab | Into the scroll region, then to each linked day in time order |
| ← → | Scroll the region (browser) |
| Enter | Follow a linked day |
Focus: a visible ring on the region and on each link; nothing moves focus.
Do not
- Do not put counts in the shade alone. Each day says its number in words.
- Do not link empty days.
- Do not compute shades in the browser. Levels are PHP; the view is the whole state.
- Do not show negative values. The ramp runs one way.
From the package repo: edit this page on GitHub.