# Comparison table

> Plans side by side, with a column that glides to the plan under your pointer and prices that roll.

Comparison tables are where people decide, and most are a wall of ticks. Here the recommended plan sits in a hairline column that runs the height of the table. Move across the table and the column glides to the plan under the pointer with a little give, then settles back when you leave, so the eye always has one plan to read down. Monthly/Yearly is thrown to the choice and every price rolls. Each section folds open and shut to its height, and the plan headers stay in view while the features scroll by. On a phone it shows one plan at a time: a switch is thrown to the plan and its column slides in from the side you went.

## Install

```bash
npx shadcn@latest add https://hairlineui.com/r/comparison-table.json
```

Needs React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

- npm: none
- Hairline UI components it needs (the CLI installs them too): `pricing-toggle`, `number-roll`
- Docs and live preview: https://hairlineui.com/ui/comparison-table
- Registry item (source): https://hairlineui.com/r/comparison-table.json

## Usage

```tsx
import { ComparisonTable } from "@/components/comparison-table";

<ComparisonTable
  yearlyBadge="Save 20%"
  plans={[
    { id: "free", name: "Free", price: 0, cta: { label: "Start free", href: "/signup" } },
    { id: "pro", name: "Pro", price: { monthly: 24, yearly: 19 }, featured: true, badge: "Popular", cta: { label: "Start a trial", href: "/signup?plan=pro" } },
  ]}
  groups={[
    { title: "Usage", rows: [{ label: "Projects", values: { free: "3", pro: "Unlimited" } }] },
    { title: "Security", rows: [{ label: "Single sign-on", values: { free: false, pro: true } }] },
  ]}
/>
```

## Under a fixed navbar

Pass the navbar’s height so the plan headers stick just below it.

```tsx
import { ComparisonTable } from "@/components/comparison-table";
import { plans, groups } from "@/lib/plans";

export function Compare() {
  return (
    <section id="compare" className="mx-auto max-w-5xl px-6 py-24">
      <h2 className="mb-10 text-4xl font-medium tracking-[-0.03em]">Compare plans</h2>
      <ComparisonTable plans={plans} groups={groups} yearlyBadge="Save 20%" stickyTop={64} />
    </section>
  );
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `plans` | `ComparisonPlan[]` | – | id, name, price (a number, { monthly, yearly }, or null for Custom), and any of description, featured, badge, cta { label, href, onClick }. |
| `groups` | `ComparisonGroup[]` | – | Sections of rows: { title, rows: [{ label, hint?, values: { [planId]: true \| false \| text } }], collapsed? }. |
| `yearlyBadge` | `string` | – | Shows the Monthly/Yearly switch with this badge, e.g. "Save 20%". |
| `currency` | `string` | `"USD"` | For the prices. |
| `stickyTop` | `number` | `0` | How far from the top the plan headers stick. |

## States

- **rest**: The featured plan’s column is outlined and tinted from its header to the foot of the table.
- **point**: The column glides to the plan under the pointer (520ms, slight overshoot) and back to the featured plan when the pointer leaves. Touch doesn’t move it.
- **billing**: Prices roll to the new period; plans without a yearly price stay put.
- **groups**: A section’s rows fold to nothing over 460ms as their contents fade; the chevron turns.
- **phone**: Below 640px, a plan switch replaces the columns: its thumb is thrown to the plan and the column slides in 8px from the side you went.

## What it handles

Comparison tables are where people decide, and most are a wall of ticks. This keeps one plan in view as people read down, and handles billing periods, sections and phones.

- **One plan to read down**: The recommended plan sits in an outlined column the full height of the table, and it glides to the plan under the pointer.
- **Monthly or yearly**: The prices roll to the new period. Plans without a yearly price stay as they are.
- **Sections that fold**: Each group of features folds open and shut, so a long table stays scannable.
- **Headers that stay in view**: The plan headers stick under your navbar while the features scroll by.
- **One plan at a time on phones**: Below 640px a plan switch replaces the columns, and the chosen plan slides in.
- **A real table**: Plans are column headers and features are row headers, and ticks read as “Included” or “Not included”.

## Replaces

a pricing table layout, sticky plan headers, a monthly and yearly switch, collapsible sections, a mobile plan switcher

## Where it fits

- **Pricing pages**: Plans side by side with the features that separate them.
- **Billing and upgrade screens**: Show what the next plan adds, inside the product.
- **Editions and licences**: Compare editions of a product, a template or a self-hosted tool.
- **Feature matrices**: Docs pages that compare options row by row.

## Notes

- A real table to assistive tech: column headers for plans, row headers for features, and ticks read as "Included" or "Not included".
- Section headers are buttons with aria-expanded; folded rows are inert.
- The gliding column is decoration only and follows a mouse or pen, not touch.
- Installs Pricing toggle (and with it Number roll). With reduced motion the column jumps and nothing slides.

License: MIT (https://hairlineui.com/license#components)
