Pricing comparison table
A full feature comparison for three plans with a sticky plan header, grouped rows that collapse, and a highlighted column that follows your pick.
"use client";
import { useState, type ReactElement } from "react";
import "./pricing-comparison.css";
type Cell = boolean | string;
const PLANS = [
{ id: "solo", name: "Solo", monthly: 0, note: "For side projects" },
{ id: "team", name: "Team", monthly: 24, note: "Most picked", hot: true },
{ id: "scale", name: "Scale", monthly: 79, note: "For whole companies" },
];
const GROUPS: { title: string; rows: [string, Cell, Cell, Cell][] }[] = [
{
title: "Projects",
rows: [
["Projects", "3", "Unlimited", "Unlimited"],
["Collaborators per project", "1", "10", "Unlimited"],
["Version history", "7 days", "90 days", "Forever"],
["Custom domains", false, true, true],
],
},
{
title: "Publishing",
rows: [
["Bandwidth", "10 GB", "200 GB", "2 TB"],
["Password-protected pages", false, true, true],
["Scheduled publishing", false, true, true],
["Staging environments", false, "1", "Unlimited"],
],
},
{
title: "Security and support",
rows: [
["Single sign-on (SSO)", false, false, true],
["Audit log", false, false, true],
["Support", "Community", "Email, 1 day", "Chat, 1 hour"],
],
},
];
const mark = (c: Cell): ReactElement =>
c === true ? (
<svg
viewBox="0 0 20 20"
className="gu-cmp__yes"
role="img"
aria-label="Included"
>
<path d="m5 10.5 3.2 3.2L15 6.5" />
</svg>
) : c === false ? (
<span className="gu-cmp__no" role="img" aria-label="Not included">
–
</span>
) : (
<span>{c}</span>
);
/**
* PricingComparison
* - A real <table> (good for screen readers) with a sticky <thead> inside its scroll parent.
* - Groups are <tbody> elements whose rows collapse with a button in the group header.
* - In containers under 640px a plan switcher shows one plan column at a time.
*/
export function PricingComparison({
theme = "light",
}: {
theme?: "light" | "dark";
}) {
const [yearly, setYearly] = useState(true);
const [focus, setFocus] = useState(1); // highlighted / phone-visible plan
const [closed, setClosed] = useState<Record<string, boolean>>({});
const price = (m: number) => (yearly ? Math.round(m * 0.8) : m);
return (
<section className="gu-cmp" data-theme={theme} data-focus={focus}>
<header className="gu-cmp__top">
<h2>Compare every plan</h2>
<div className="gu-cmp__bill" role="group" aria-label="Billing period">
<button
type="button"
aria-pressed={!yearly}
onClick={() => setYearly(false)}
>
Monthly
</button>
<button
type="button"
aria-pressed={yearly}
onClick={() => setYearly(true)}
>
Yearly <em>−20%</em>
</button>
</div>
</header>
<div className="gu-cmp__tabs" role="tablist" aria-label="Plan">
{PLANS.map((p, i) => (
<button
key={p.id}
role="tab"
aria-selected={focus === i}
onClick={() => setFocus(i)}
>
{p.name}
</button>
))}
</div>
<table>
<caption className="gu-sr">Features included in each plan</caption>
<thead>
<tr>
<td />
{PLANS.map((p, i) => (
<th
key={p.id}
scope="col"
data-col={i}
data-hot={p.hot ? "" : undefined}
onMouseEnter={() => setFocus(i)}
>
<span className="gu-cmp__note">{p.note}</span>
<strong>{p.name}</strong>
<span className="gu-cmp__price">
${price(p.monthly)}
<small>/ month</small>
</span>
<a href="#start" className="gu-cmp__cta">
{p.monthly ? `Start ${p.name}` : "Start free"}
</a>
</th>
))}
</tr>
</thead>
{GROUPS.map((g) => {
const isClosed = closed[g.title];
return (
<tbody key={g.title} data-closed={isClosed ? "" : undefined}>
<tr className="gu-cmp__group">
<th colSpan={4} scope="colgroup">
<button
type="button"
aria-expanded={!isClosed}
onClick={() =>
setClosed((c) => ({ ...c, [g.title]: !c[g.title] }))
}
>
{g.title}
<svg viewBox="0 0 16 16" aria-hidden="true">
<path d="m4 6 4 4 4-4" />
</svg>
</button>
</th>
</tr>
{g.rows.map(([label, ...cells]) => (
<tr key={label} className="gu-cmp__row">
<th scope="row">{label}</th>
{cells.map((c, i) => (
<td key={i} data-col={i}>
{mark(c)}
</td>
))}
</tr>
))}
</tbody>
);
})}
</table>
</section>
);
}
Paste this into ChatGPT, Claude, Cursor, v0, Lovable or Bolt. It describes the layout, motion, colors and accessibility and includes the code, so the AI can rebuild it in any framework.
# Build this UI piece: Pricing comparison table
You are a senior front-end engineer. Recreate the piece below in my project. If I don't say which framework I use, ask once, then build it in that framework (React, Vue, Svelte, Angular, Astro, plain HTML/CSS/JS or anything else). Keep the behavior, motion, colors, spacing and accessibility exactly as described. Keep the code clean and commented for beginners.
## What it is
A full pricing comparison table for three plans (Solo, Team, Scale) with a monthly/yearly switch, a sticky header row with prices and buttons, collapsible feature groups, and a highlighted column that follows the plan you hover. On phones it becomes plan tabs.
## Layout and look
- Section on Cream #f3eee3 (dark Ink), max 1100px. Huge title "Compare every plan" (clamp 32–64px, weight 900, tracking -0.045em) with a pill billing switch on the right ("Yearly −20%", the −20% in orange).
- Table: fixed layout, first column = feature labels (muted), then three plan columns.
- Header cells: small note ("Most picked" in orange for the hot plan), plan name, big price with "/ month", and a 44px pill button (orange for the hot plan, outlined for others). The header is sticky.
- Group rows: bold title button with a chevron. Feature rows: 14px padding, hairline bottom border; included = orange check, missing = faint dash, or text values.
- Highlighted column: 8% orange tint, rounded top on the header cell.
## Behavior and motion
1. Yearly = 80% of the monthly price.
2. Clicking a group header collapses its rows; the chevron rotates.
3. Hovering a plan header moves the highlight.
4. Container under 640px: show a segmented plan switcher and only that plan's column.
## Touch
Tabs instead of horizontal scrolling.
## Accessibility
- A real table with caption, th scope="col"/"row"/"colgroup", aria-expanded on group toggles, icons with "Included"/"Not included" labels.
- prefers-reduced-motion: no transitions.
## Props
theme. Edit PLANS and GROUPS.
## Reference implementation
The original is written in React with one plain CSS file. Dependencies: none (plain React and CSS). Translate it faithfully; do not add new libraries unless my framework needs them.
### PricingComparison.tsx
```tsx
"use client";
import { useState, type ReactElement } from "react";
import "./pricing-comparison.css";
type Cell = boolean | string;
const PLANS = [
{ id: "solo", name: "Solo", monthly: 0, note: "For side projects" },
{ id: "team", name: "Team", monthly: 24, note: "Most picked", hot: true },
{ id: "scale", name: "Scale", monthly: 79, note: "For whole companies" },
];
const GROUPS: { title: string; rows: [string, Cell, Cell, Cell][] }[] = [
{
title: "Projects",
rows: [
["Projects", "3", "Unlimited", "Unlimited"],
["Collaborators per project", "1", "10", "Unlimited"],
["Version history", "7 days", "90 days", "Forever"],
["Custom domains", false, true, true],
],
},
{
title: "Publishing",
rows: [
["Bandwidth", "10 GB", "200 GB", "2 TB"],
["Password-protected pages", false, true, true],
["Scheduled publishing", false, true, true],
["Staging environments", false, "1", "Unlimited"],
],
},
{
title: "Security and support",
rows: [
["Single sign-on (SSO)", false, false, true],
["Audit log", false, false, true],
["Support", "Community", "Email, 1 day", "Chat, 1 hour"],
],
},
];
const mark = (c: Cell): ReactElement =>
c === true ? (
<svg
viewBox="0 0 20 20"
className="gu-cmp__yes"
role="img"
aria-label="Included"
>
<path d="m5 10.5 3.2 3.2L15 6.5" />
</svg>
) : c === false ? (
<span className="gu-cmp__no" role="img" aria-label="Not included">
–
</span>
) : (
<span>{c}</span>
);
/**
* PricingComparison
* - A real <table> (good for screen readers) with a sticky <thead> inside its scroll parent.
* - Groups are <tbody> elements whose rows collapse with a button in the group header.
* - In containers under 640px a plan switcher shows one plan column at a time.
*/
export function PricingComparison({
theme = "light",
}: {
theme?: "light" | "dark";
}) {
const [yearly, setYearly] = useState(true);
const [focus, setFocus] = useState(1); // highlighted / phone-visible plan
const [closed, setClosed] = useState<Record<string, boolean>>({});
const price = (m: number) => (yearly ? Math.round(m * 0.8) : m);
return (
<section className="gu-cmp" data-theme={theme} data-focus={focus}>
<header className="gu-cmp__top">
<h2>Compare every plan</h2>
<div className="gu-cmp__bill" role="group" aria-label="Billing period">
<button
type="button"
aria-pressed={!yearly}
onClick={() => setYearly(false)}
>
Monthly
</button>
<button
type="button"
aria-pressed={yearly}
onClick={() => setYearly(true)}
>
Yearly <em>−20%</em>
</button>
</div>
</header>
<div className="gu-cmp__tabs" role="tablist" aria-label="Plan">
{PLANS.map((p, i) => (
<button
key={p.id}
role="tab"
aria-selected={focus === i}
onClick={() => setFocus(i)}
>
{p.name}
</button>
))}
</div>
<table>
<caption className="gu-sr">Features included in each plan</caption>
<thead>
<tr>
<td />
{PLANS.map((p, i) => (
<th
key={p.id}
scope="col"
data-col={i}
data-hot={p.hot ? "" : undefined}
onMouseEnter={() => setFocus(i)}
>
<span className="gu-cmp__note">{p.note}</span>
<strong>{p.name}</strong>
<span className="gu-cmp__price">
${price(p.monthly)}
<small>/ month</small>
</span>
<a href="#start" className="gu-cmp__cta">
{p.monthly ? `Start ${p.name}` : "Start free"}
</a>
</th>
))}
</tr>
</thead>
{GROUPS.map((g) => {
const isClosed = closed[g.title];
return (
<tbody key={g.title} data-closed={isClosed ? "" : undefined}>
<tr className="gu-cmp__group">
<th colSpan={4} scope="colgroup">
<button
type="button"
aria-expanded={!isClosed}
onClick={() =>
setClosed((c) => ({ ...c, [g.title]: !c[g.title] }))
}
>
{g.title}
<svg viewBox="0 0 16 16" aria-hidden="true">
<path d="m4 6 4 4 4-4" />
</svg>
</button>
</th>
</tr>
{g.rows.map(([label, ...cells]) => (
<tr key={label} className="gu-cmp__row">
<th scope="row">{label}</th>
{cells.map((c, i) => (
<td key={i} data-col={i}>
{mark(c)}
</td>
))}
</tr>
))}
</tbody>
);
})}
</table>
</section>
);
}
```
### pricing-comparison.css
```css
/* PricingComparison: change these colors to match your brand. */
.gu-cmp {
--bg: #f3eee3;
--card: #fbf8f2;
--text: #0e0e10;
--muted: #57534b;
--line: rgb(14 14 16 / 0.12);
--accent: #ff5a1f;
--hl: rgb(255 90 31 / 0.08);
--focus: #2b35ff;
container-type: inline-size;
padding: clamp(32px, 6%, 72px) clamp(16px, 4%, 48px);
background: var(--bg);
color: var(--text);
font-family: system-ui, sans-serif;
}
.gu-cmp[data-theme="dark"] {
--bg: #0e0e10;
--card: #18181b;
--text: #f3eee3;
--muted: #aea89c;
--line: rgb(243 238 227 / 0.12);
--hl: rgb(255 90 31 / 0.12);
--focus: #d7ff3a;
}
.gu-cmp__top {
display: flex;
flex-wrap: wrap;
align-items: end;
justify-content: space-between;
gap: 16px;
max-width: 1100px;
margin: 0 auto 28px;
}
.gu-cmp h2 {
margin: 0;
font-size: clamp(2rem, 6cqi, 4rem);
font-weight: 900;
letter-spacing: -0.045em;
line-height: 0.95;
}
.gu-cmp__bill {
display: inline-flex;
padding: 4px;
border: 1px solid var(--line);
border-radius: 999px;
}
.gu-cmp__bill button,
.gu-cmp__tabs button {
min-height: 40px;
padding: 0 16px;
border: 0;
border-radius: 999px;
background: none;
color: var(--muted);
font: inherit;
font-weight: 700;
cursor: pointer;
}
.gu-cmp__bill [aria-pressed="true"],
.gu-cmp__tabs [aria-selected="true"] {
background: var(--text);
color: var(--bg);
}
.gu-cmp__bill em {
font-style: normal;
color: var(--accent);
}
.gu-cmp :is(button, a):focus-visible {
outline: 3px solid var(--focus);
outline-offset: 2px;
}
.gu-cmp__tabs {
display: none;
}
.gu-cmp table {
width: 100%;
max-width: 1100px;
margin: 0 auto;
border-collapse: separate;
border-spacing: 0;
table-layout: fixed;
}
.gu-cmp thead th,
.gu-cmp thead td {
position: sticky;
top: 0;
z-index: 2;
background: var(--bg);
}
.gu-cmp thead th {
padding: 18px 16px;
border-bottom: 1px solid var(--line);
text-align: left;
vertical-align: top;
}
.gu-cmp thead th > * {
display: block;
}
.gu-cmp__note {
color: var(--muted);
font-size: 0.78rem;
font-weight: 700;
}
.gu-cmp thead strong {
margin-top: 2px;
font-size: 1.3rem;
font-weight: 900;
}
.gu-cmp__price {
margin: 6px 0 12px;
font-size: 2.2rem;
font-weight: 900;
letter-spacing: -0.04em;
font-variant-numeric: tabular-nums;
}
.gu-cmp__price small {
margin-left: 4px;
color: var(--muted);
font-size: 0.85rem;
font-weight: 600;
letter-spacing: 0;
}
.gu-cmp__cta {
display: grid !important;
place-items: center;
min-height: 44px;
border: 1.5px solid var(--text);
border-radius: 999px;
color: inherit;
font-weight: 800;
text-decoration: none;
transition:
background-color 0.2s,
color 0.2s;
}
.gu-cmp__cta:hover {
background: var(--text);
color: var(--bg);
}
.gu-cmp th[data-hot] .gu-cmp__cta {
border-color: var(--accent);
background: var(--accent);
color: #0e0e10;
}
.gu-cmp th[data-hot] .gu-cmp__note {
color: var(--accent);
}
.gu-cmp__group th {
padding: 28px 0 8px;
text-align: left;
}
.gu-cmp__group button {
display: inline-flex;
align-items: center;
gap: 8px;
min-height: 40px;
padding: 0;
border: 0;
background: none;
color: inherit;
font: inherit;
font-size: 1.05rem;
font-weight: 900;
cursor: pointer;
}
.gu-cmp__group svg {
width: 16px;
fill: none;
stroke: currentColor;
stroke-width: 2;
transition: transform 0.3s;
}
.gu-cmp tbody[data-closed] .gu-cmp__group svg {
transform: rotate(-90deg);
}
.gu-cmp tbody[data-closed] .gu-cmp__row {
display: none;
}
.gu-cmp__row th,
.gu-cmp__row td {
padding: 14px 16px;
border-bottom: 1px solid var(--line);
font-size: 0.92rem;
}
.gu-cmp__row th {
padding-left: 0;
color: var(--muted);
font-weight: 600;
text-align: left;
}
.gu-cmp__row td {
font-weight: 700;
transition: background-color 0.25s;
}
.gu-cmp__row:hover th {
color: var(--text);
}
.gu-cmp__yes {
width: 22px;
fill: none;
stroke: var(--accent);
stroke-width: 2.6;
stroke-linecap: round;
stroke-linejoin: round;
vertical-align: middle;
}
.gu-cmp__no {
color: var(--muted);
opacity: 0.6;
}
/* Highlighted column follows the hovered (or tapped) plan */
.gu-cmp[data-focus="0"] [data-col="0"],
.gu-cmp[data-focus="1"] [data-col="1"],
.gu-cmp[data-focus="2"] [data-col="2"] {
background: var(--hl);
}
.gu-cmp[data-focus="0"] thead [data-col="0"],
.gu-cmp[data-focus="1"] thead [data-col="1"],
.gu-cmp[data-focus="2"] thead [data-col="2"] {
background: color-mix(in srgb, var(--accent) 8%, var(--bg));
border-radius: 18px 18px 0 0;
}
/* Phone: show the label column plus the chosen plan only */
@container (max-width: 640px) {
.gu-cmp__tabs {
display: flex;
gap: 4px;
margin-bottom: 8px;
padding: 4px;
border: 1px solid var(--line);
border-radius: 999px;
}
.gu-cmp__tabs button {
flex: 1;
}
.gu-cmp [data-col] {
display: none;
}
.gu-cmp[data-focus="0"] [data-col="0"],
.gu-cmp[data-focus="1"] [data-col="1"],
.gu-cmp[data-focus="2"] [data-col="2"] {
display: table-cell;
background: none;
}
/* Auto layout lets the hidden plan columns collapse to nothing */
.gu-cmp table {
table-layout: auto;
}
.gu-cmp thead td {
width: 46%;
}
.gu-cmp__group th {
padding-top: 20px;
}
}
.gu-sr {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip-path: inset(50%);
}
@media (prefers-reduced-motion: reduce) {
.gu-cmp * {
transition: none !important;
}
}
```
You might also want
Next piece: Product card with quick viewPricing section
Templates, intermediate
Usage pricing calculator
Templates, intermediate
Big footer with signup
Templates, intermediate