How it works
A squarified layout keeps tiles close to square, so labels have room, and it is recomputed at the measured width. Each tile is a light tint of its branch colour with ink text and a hairline in the same hue, and a branch keeps its colour when you zoom into it. Large first-level tiles show faint inner lines of their children, so it is clear which tiles open. Hovering or focusing a tile fades the others, reveals a small zoom badge and shows a dark tip with the value and share. Opening a tile replays the next level growing out of that tile's exact box with Web Animations on transform only; the breadcrumb goes back up with a short settle.
Use it for
- Where the money, space or time goes in a hierarchy: spend by service, disk use by folder, hours by project and task.
Look elsewhere when
- Exact comparison between similar values: use a bar list.
- Negative values or values over time.
Usage
import { Treemap } from './Treemap.jsx'
export function SpendByService({ services }) {
return (
<Treemap
label="Cloud spend by service"
data={{
name: 'All services',
children: services.map((s, i) => ({
name: s.name,
tone: i + 1,
children: s.lines.map((l) => ({ name: l.name, value: l.cost })),
})),
}}
formatValue={(v) => `$${v.toLocaleString('en-US')}`}
/>
)
}Props
| Prop | Type | Default | What it does |
|---|---|---|---|
data | { name: string, value?: number, tone?: 1-8, children?: Node[] } | — | The root and its tree. Leaves carry value; a branch's size is the sum of its leaves. Top-level tone colours the whole branch. |
height / gap | number | 300 / 3 | Plot height and the space between tiles, in px. The width follows the container. |
depth | 1 | 2 | 2 | 2 draws faint lines inside large tiles showing how their children divide them. |
showValues | boolean | true | Value under the name on tiles large enough for two lines. |
formatValue / formatShare | (v) => string / (pct) => string | — | Formats for the value and the share of the current level. |
label / labels | string / { open(name), back } | 'Treemap' | Accessible name of each level and the wording for tiles that open and the breadcrumb. |
Accessibility
- Each level is a list with an accessible name; tiles that open are buttons named “Open name, value, share”, and leaf tiles are focusable images with the same information.
- Tab moves through tiles; Enter or Space opens one; the breadcrumb is a navigation landmark whose earlier levels are buttons and whose current level has aria-current.
- The hover tip is decorative; everything it shows is in the accessible names.
- Reduced motion skips the zoom and the tile entrance.
Motion
Zoom in: 520ms from the tile's box on the reveal curve. Zoom out: 360ms settle from 106%. Tiles: 420ms entrance with a 35ms stagger. Hover: 200ms.
Add it to your project
Pro members copy a prompt and their coding agent installs the source, the same way as the free components.
Treemap.jsxtreemap.csstokens.cssREADME.md
Both files install together. The stylesheet reads the design tokens in tokens.css and carries fallbacks, so it also works alone.



