How it works
The table draws its own card (surface, large radius, card shadow, no border) with an optional title row, and has no lines at all. The first column lists features (optionally grouped, with a small hint), then one column per plan: an accent badge, a radio ring with the name, and the price. The selected plan stands on a tinted panel with an accent hairline and a soft accent shadow below, reaching a little past the table, so the column reads as lifted; a fainter neutral panel follows the pointer or keyboard focus over the other plans. Both panels sit under transparent cells, are placed from measured column offsets and slide with transform. Included is a check in a small round chip that turns accent in the chosen plan; not included is a short dash. Choosing uses hidden native radios, so arrow keys, a single Tab stop and “n of m” come from the browser. “Differences only” removes identical rows and slides the rest into place with FLIP.
Use it for
- Two to four plans side by side for a user to pick from: subscription tiers, storage plans, support levels.
- Going feature by feature to see what each plan has; the column highlight helps follow one plan top to bottom.
- A comparison that ends in a choice: the selected plan can be the form value, followed by a “Get started” button.
Look elsewhere when
- More than four plans, or columns too narrow on a phone: use one card per plan and swipe between them.
- A single plan that only lists benefits: use a plain list.
- Comparing data records rather than plans, such as two orders: use a regular table or side-by-side detail cards.
- Dozens of features: group them and turn on differences only by default.
Usage
import { useState } from 'react'
import { CompareTable } from './CompareTable.jsx'
const plans = [
{ key: 'starter', name: 'Starter', price: '$0' },
{ key: 'team', name: 'Team', price: '$12', unit: '/seat', badge: 'Popular' },
{ key: 'pro', name: 'Pro', price: '$29', unit: '/seat' },
]
const groups = [
{
rows: [
{ key: 'members', label: 'Members', values: { starter: '3', team: '25', pro: 'Unlimited' } },
{ key: 'storage', label: 'Storage', values: { starter: '5 GB', team: '100 GB', pro: '1 TB' } },
{ key: 'domain', label: 'Custom domain', values: { starter: false, team: true, pro: true } },
{ key: 'backups', label: 'Daily backups', values: { starter: true, team: true, pro: true } },
],
},
]
export function PlanPicker() {
const [plan, setPlan] = useState('team')
const [diffOnly, setDiffOnly] = useState(false)
return (
<CompareTable
title="Compare plans"
actions={
<button type="button" aria-pressed={diffOnly} onClick={() => setDiffOnly((v) => !v)}>
Differences only
</button>
}
plans={plans}
groups={groups}
value={plan}
onChange={setPlan}
diffOnly={diffOnly}
featureTitle="Per month"
/>
)
}Props
| Prop | Type | Default | What it does |
|---|---|---|---|
plans | { key, name, price?, unit?, badge? }[] | — | The plans to compare, one column each: key (also the field name in each row's values), name, price (such as “$12” or “Free”), unit (small text after the price, such as “/seat”) and badge (accent tag above the name, such as “Popular”). |
groups | { title?, rows: { key, label, hint?, values }[] }[] | — | Features in groups; title is a full-width group heading. For no grouping, give one group without a title. values are keyed by plan key: true shows a check, false a dash, text and numbers as they are. |
value | string | null | — | Controlled: key of the selected plan, null for none. Omit it to let the component keep it. |
defaultValue | string | null | null | Initially selected plan when uncontrolled. |
onChange | (planKey) => void | — | Called when the selected plan changes. |
diffOnly | boolean | false | Differences only: hides rows whose values are identical (===) in every plan. |
featureTitle | string | 'Features' | Header of the first column. |
featureWidth | number | string | '32%' | Width of the first column: a number is px, a percentage also works. Plan columns share the rest equally. |
emptyText | ReactNode | — | Text when no row is left. By default “The plans do not differ on these features” in differences-only mode, otherwise “No data”. |
title | ReactNode | — | Card title shown in the title row. A string title also names the table for screen readers when label is not given. |
subtitle | ReactNode | — | Muted qualifier after the title, such as a period ("This week"). |
icon | ReactNode | — | Icon before the title, drawn in a tinted 32px rounded square. Decorative (aria-hidden). |
actions | ReactNode | — | Controls at the right end of the title row (buttons, a switch, a menu). |
label | string | — | Table name for screen readers (the <caption>). Defaults to title when title is a string. |
labels | object | — | Replaces built-in text (supported, unsupported, hidden, noneShared, shownAll, noDifferences, noData). Shallow-merged over the English defaults. |
...rest | HTMLAttributes | — | Other attributes go to the root <div>. |
Accessibility
- Plan choice is a native radio group: one Tab stop, arrow keys switch and select, and the name, price, badge and “n of m” are announced.
- The radio ring shows a focus ring and the faint panel follows keyboard focus; both panels are decorative (aria-hidden).
- Checks and dashes are read as “Included” and “Not included”, and selection is not colour alone: the ring fills and shows a check.
- A real <table>: plans are <th scope="col">, features <th scope="row">, and label (or a string title) becomes the <caption>.
- Toggling differences only announces how many rows were hidden through aria-live.
- Reduced motion moves the panels without sliding and rows jump into place; on touch screens rows are at least 44px and plan headers are fully clickable.
Motion
Panels change column with translateX over 360ms ease-out and fade in over 160ms on first appearance. The radio check scales in over 240ms with a spring; check chips change colour over 240ms; rows reorder with translateY over 360ms ease-in-out.
Add it to your project
Pro members copy a prompt and their coding agent installs the source, the same way as the free components.
CompareTable.jsxcompare-table.csstokens.cssREADME.md
Both files install together. The stylesheet reads the design tokens in tokens.css and carries fallbacks, so it also works alone.





