Comparison Table with Sticky Header
Native feature matrix grouped under named sections, with plan names, prices and actions pinned on top and feature names pinned at the start while it scrolls. The default full plan comparison.
How it differs. Baseline of the family: a static grouped matrix whose plan header and feature column stay pinned on both axes, with included counts per section and in total for every plan.
Install
pnpm dlx shadcn@latest add @hazine/pricing-comparison-sticky-headerAdds 2 files, 1 shadcn primitive (button), 1 Hazine item (@hazine/heading), and 1 package (lucide-react).
First time? Add the registry to components.json
{
"registries": {
"@hazine": "https://api.hazine.dev/r/{name}.json"
}
}Needed once per project. Items resolve each other through the @hazine namespace.
components/blocks/pricing-comparison-sticky-header.tsx, 444 lines
import * as React from "react"
import { Check, Minus, Table2 } from "lucide-react"
import { cn } from "@/lib/utils"
import { Button } from "@/components/ui/button"
import { Heading, nextHeadingLevel, type HeadingLevel } from "@/components/hazine/heading"
import { PricingComparisonStickyHeaderScrollFrame } from "./pricing-comparison-sticky-header.scroll-frame"
export interface ComparisonPlan {
id: string
name: string
/** Amount per unit in the block currency. Omit for a quoted plan. */
price?: number
/** Shown in place of a figure when the plan has no price. */
priceLabel?: string
/** Set small beside the price, for example "/editor/mo". */
unit?: string
action: { label: string; href: string }
/** Lifts the column, fills its action and adds the featured label. */
featured?: boolean
}
/** true and false render a mark with hidden text. A string is shown as written and, unless empty, counts as included. */
export type ComparisonValue = boolean | string
export interface ComparisonFeature {
id: string
name: string
/** One short line under the name. */
hint?: string
/** Keyed by plan id. A plan that is missing counts as not included. */
values: Record<string, ComparisonValue>
}
export interface ComparisonSection {
id: string
title: string
features: ComparisonFeature[]
}
export interface PricingComparisonStickyHeaderProps
extends Omit<React.ComponentProps<"section">, "title"> {
title?: string
/** Follows the computed plan and feature count in the intro sentence. */
description?: string
headingLevel?: HeadingLevel
plans?: ComparisonPlan[]
sections?: ComparisonSection[]
/** Billing terms, set in the corner cell beside the prices. */
priceNote?: string
/** Text of the chip on a featured plan. */
featuredLabel?: string
/** ISO 4217 code. */
currency?: string
locale?: string
/** CSS length from the top of the page at which the header pins: the height of a fixed site header. */
stickyOffset?: string
contactHref?: string
}
const DEFAULT_PLANS: ComparisonPlan[] = [
{
id: "starter",
name: "Starter",
price: 0,
unit: "/editor/mo",
action: { label: "Start free", href: "/signup?plan=starter" },
},
{
id: "team",
name: "Team",
price: 9,
unit: "/editor/mo",
action: { label: "Try Team", href: "/signup?plan=team" },
featured: true,
},
{
id: "business",
name: "Business",
price: 18,
unit: "/editor/mo",
action: { label: "Try Business", href: "/signup?plan=business" },
},
]
const DEFAULT_SECTIONS: ComparisonSection[] = [
{
id: "collaboration",
title: "Collaboration",
features: [
{ id: "editors", name: "Editors", values: { starter: "Up to 3", team: "Up to 50", business: "Unlimited" } },
{
id: "guest-access",
name: "Guest access",
hint: "People outside your workspace",
values: { starter: false, team: "10 guests", business: "Unlimited" },
},
{ id: "history", name: "Version history", values: { starter: "7 days", team: "90 days", business: "Unlimited" } },
{ id: "review-flow", name: "Review and approval flow", values: { starter: false, team: true, business: true } },
],
},
{
id: "security",
title: "Security",
features: [
{ id: "two-factor", name: "Two-factor sign-in", values: { starter: true, team: true, business: true } },
{ id: "saml-sso", name: "SAML single sign-on", values: { starter: false, team: false, business: true } },
{
id: "audit-log",
name: "Audit log",
hint: "Sign-in and permission events",
values: { starter: false, team: "30 days", business: "1 year" },
},
{ id: "residency", name: "Data residency in the EU or US", values: { starter: false, team: false, business: true } },
],
},
{
id: "support",
title: "Support",
features: [
{ id: "help-centre", name: "Help centre and community forum", values: { starter: true, team: true, business: true } },
{
id: "email-support",
name: "Email support",
hint: "Time to a first reply",
values: { starter: false, team: "1 business day", business: "4 hours" },
},
{
id: "uptime",
name: "Uptime commitment",
hint: "Measured monthly, with service credits",
values: { starter: false, team: "99.9%", business: "99.95%" },
},
{ id: "onboarding", name: "Onboarding session", values: { starter: false, team: false, business: true } },
],
},
]
// Pinned cells are opaque so rows do not show through them while scrolling.
const pinnedColumn =
"sticky start-0 z-10 border-e border-border bg-background text-start"
const linkClass =
"inline-flex min-h-6 items-center rounded-sm font-medium text-foreground underline underline-offset-4 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-foreground"
function plural(count: number, noun: string) {
return count === 1 ? `1 ${noun}` : `${count} ${noun}s`
}
function countIncluded(features: ComparisonFeature[], planId: string) {
return features.filter((feature) => Boolean(feature.values[planId])).length
}
/** The raised surface for a featured cell that must also stay opaque. */
function Band() {
return <span aria-hidden="true" className="absolute inset-0 bg-muted/50" />
}
function ValueMark({ value }: { value: ComparisonValue | undefined }) {
if (typeof value === "string" && value !== "") {
return <span className="tabular-nums">{value}</span>
}
return (
<span className="flex h-5 items-center">
{value === true ? (
<Check aria-hidden="true" className="size-4" />
) : (
<Minus aria-hidden="true" className="size-4 text-muted-foreground" />
)}
<span className="sr-only">
{value === true ? "Included" : "Not included"}
</span>
</span>
)
}
export function PricingComparisonStickyHeader({
title = "Compare plans",
description = "Marks show what a plan includes, and limits are written out in full.",
headingLevel = 2,
plans = DEFAULT_PLANS,
sections = DEFAULT_SECTIONS,
priceNote = "Per editor, billed yearly. Readers are free on every plan.",
featuredLabel = "Recommended",
currency = "USD",
locale = "en-US",
stickyOffset = "0px",
contactHref = "/contact",
className,
style,
...props
}: PricingComparisonStickyHeaderProps) {
const titleId = React.useId()
const captionId = React.useId()
const subLevel = nextHeadingLevel(headingLevel)
const features = sections.flatMap((section) => section.features)
const empty = plans.length === 0 || features.length === 0
// Decimals drop only when every price is whole, so the header row never
// mixes "$9" with "$7.50".
const allWhole = plans.every(
(plan) => plan.price === undefined || Number.isInteger(plan.price)
)
const money = new Intl.NumberFormat(locale, {
style: "currency",
currency,
minimumFractionDigits: allWhole ? 0 : 2,
maximumFractionDigits: allWhole ? 0 : 2,
})
const planNames = new Intl.ListFormat(locale, {
style: "long",
type: "conjunction",
}).format(plans.map((plan) => plan.name))
const summary = `${plural(plans.length, "plan")}, ${plural(features.length, "feature")}.`
const featureShare = 28
const planWidth = { inlineSize: `${(100 - featureShare) / plans.length}%` }
return (
<section
data-slot="pricing-comparison-sticky-header"
aria-labelledby={titleId}
className={cn("@container bg-background py-12 text-foreground", className)}
style={
{ "--comparison-sticky-top": stickyOffset, ...style } as React.CSSProperties
}
{...props}
>
<div className="mx-auto w-full max-w-6xl px-4 @3xl:px-6">
<Heading
level={headingLevel}
id={titleId}
className="text-2xl font-semibold tracking-tight text-balance @3xl:text-4xl"
>
{title}
</Heading>
{empty ? (
<div className="mt-10 flex flex-col items-center rounded-xl border border-dashed border-border px-6 py-16 text-center">
<span
aria-hidden="true"
className="flex size-9 items-center justify-center rounded-md border border-border bg-background"
>
<Table2 className="size-5" strokeWidth={1.5} />
</span>
<Heading level={subLevel} className="mt-4 text-lg font-semibold">
No plans to compare yet
</Heading>
<p className="mt-1 max-w-[40ch] text-sm text-muted-foreground">
Each plan appears here as a column, with its price and every
feature it includes, once plans are published.
</p>
<Button asChild variant="outline" className="mt-6">
<a href={contactHref}>Contact sales</a>
</Button>
</div>
) : (
<>
<p className="mt-4 max-w-prose text-base text-muted-foreground">
<span className="font-medium text-foreground tabular-nums">
{summary}
</span>{" "}
{description}
</p>
<PricingComparisonStickyHeaderScrollFrame
labelledBy={captionId}
className="mt-10"
>
<table className="w-full border-separate border-spacing-0 text-sm">
<caption id={captionId} className="sr-only">
{title}: {planNames}. {plural(features.length, "feature")} in{" "}
{plural(sections.length, "section")}.
</caption>
<thead
data-slot="pricing-comparison-sticky-header-plans"
className="sticky top-0 z-20 group-data-[pin=page]:top-(--comparison-sticky-top)"
>
<tr>
<td
rowSpan={2}
style={{ inlineSize: `${featureShare}%` }}
className={cn(
pinnedColumn,
"min-w-32 border-b p-4 align-bottom text-xs text-muted-foreground"
)}
>
{priceNote}
</td>
{plans.map((plan) => (
<th
key={plan.id}
scope="col"
style={planWidth}
className="relative min-w-36 bg-background px-4 pt-4 text-start align-top font-normal"
>
{plan.featured && <Band />}
<div className="relative flex flex-wrap items-center gap-x-2 gap-y-1">
<span className="text-sm font-semibold">
{plan.name}
</span>
{plan.featured && (
<span className="rounded-md border border-foreground/50 px-1.5 py-0.5 text-xs font-medium">
{featuredLabel}
</span>
)}
</div>
</th>
))}
</tr>
<tr>
{plans.map((plan) => (
<td
key={plan.id}
className="relative border-b border-border bg-background px-4 pt-1 pb-4 align-bottom"
>
{plan.featured && <Band />}
<div className="relative">
<p className="flex flex-wrap items-baseline gap-x-1">
<span className="text-lg font-semibold tabular-nums">
{plan.price === undefined
? (plan.priceLabel ?? "Custom")
: money.format(plan.price)}
</span>
{plan.unit && (
<span className="text-xs text-muted-foreground">
{plan.unit}
</span>
)}
</p>
<Button
asChild
variant={plan.featured ? "default" : "outline"}
className="mt-3 w-full"
>
<a href={plan.action.href}>{plan.action.label}</a>
</Button>
</div>
</td>
))}
</tr>
</thead>
{sections.map((section) => (
<tbody
key={section.id}
data-slot="pricing-comparison-sticky-header-section"
>
<tr>
<th
scope="rowgroup"
className={cn(
pinnedColumn,
"border-b px-4 pt-8 pb-2 align-bottom font-mono text-xs font-medium tracking-wider text-muted-foreground uppercase"
)}
>
{section.title}
</th>
{plans.map((plan) => (
<td
key={plan.id}
className={cn(
"border-b border-border px-4 pt-8 pb-2 align-bottom text-xs text-muted-foreground tabular-nums",
plan.featured && "bg-muted/50"
)}
>
{countIncluded(section.features, plan.id)} of{" "}
{section.features.length}
<span className="sr-only"> included</span>
</td>
))}
</tr>
{section.features.map((feature) => (
<tr key={feature.id}>
<th
scope="row"
className={cn(
pinnedColumn,
"border-b px-4 py-3 align-top font-normal"
)}
>
{feature.name}
{feature.hint && (
<span className="mt-0.5 block text-xs text-muted-foreground">
{feature.hint}
</span>
)}
</th>
{plans.map((plan) => (
<td
key={plan.id}
className={cn(
"border-b border-border px-4 py-3 align-top",
plan.featured && "bg-muted/50"
)}
>
<ValueMark value={feature.values[plan.id]} />
</td>
))}
</tr>
))}
</tbody>
))}
<tfoot>
<tr>
<th
scope="row"
className={cn(pinnedColumn, "p-4 align-baseline font-semibold")}
>
Included in total
</th>
{plans.map((plan) => (
<td
key={plan.id}
className={cn(
"p-4 align-baseline",
plan.featured && "bg-muted/50"
)}
>
<span className="font-semibold tabular-nums">
{countIncluded(features, plan.id)} of {features.length}
</span>{" "}
<span className="text-xs text-muted-foreground">
features
</span>
</td>
))}
</tr>
</tfoot>
</table>
</PricingComparisonStickyHeaderScrollFrame>
<p className="mt-4 text-sm text-muted-foreground">
Volume pricing, invoiced billing and security reviews go through
our sales team.{" "}
<a href={contactHref} className={linkClass}>
Contact sales
</a>
</p>
</>
)}
</div>
</section>
)
}
components/blocks/pricing-comparison-sticky-header.scroll-frame.tsx, 69 lines
"use client"
import * as React from "react"
import { cn } from "@/lib/utils"
export interface PricingComparisonStickyHeaderScrollFrameProps
extends Omit<React.ComponentProps<"div">, "role" | "tabIndex"> {
/** Id of the element that names the frame while it is a scroll region. */
labelledBy: string
}
type Pin = "frame" | "page"
/**
* Holds the table and decides where its header pins. While the table is wider
* than the frame, the frame scrolls on both axes and is a focusable region.
* Once every column fits, the frame stops scrolling and the header pins to
* the page instead.
*/
export function PricingComparisonStickyHeaderScrollFrame({
labelledBy,
className,
...props
}: PricingComparisonStickyHeaderScrollFrameProps) {
const frame = React.useRef<HTMLDivElement>(null)
// "frame" is also what the server renders, so the table is fully usable
// before hydration and without scripts.
const [pin, setPin] = React.useState<Pin>("frame")
React.useEffect(() => {
const node = frame.current
const content = node?.firstElementChild
if (!node || !(content instanceof HTMLElement)) return
// The table is as wide as the frame unless its columns cannot shrink any
// further, so comparing the two works in both modes.
const observer = new ResizeObserver(() => {
setPin(content.offsetWidth > node.clientWidth ? "frame" : "page")
})
observer.observe(node)
observer.observe(content)
return () => observer.disconnect()
}, [])
// A scroll region needs a name and a tab stop so the keyboard can scroll
// it. Once nothing scrolls, both go away and the frame is a plain wrapper.
// Spread, not written as attributes: the lint rule against tabIndex on a
// plain element has no exception for scroll regions, which need one.
const region =
pin === "frame"
? { role: "region", "aria-labelledby": labelledBy, tabIndex: 0 }
: {}
return (
<div
{...props}
{...region}
ref={frame}
data-slot="pricing-comparison-sticky-header-frame"
data-pin={pin}
// relative keeps the visually hidden cell text inside the scroll area,
// so it cannot widen the page.
className={cn(
"group relative isolate max-h-svh overflow-auto overscroll-x-contain rounded-xl border border-border focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-foreground data-[pin=page]:max-h-none data-[pin=page]:overflow-clip",
className
)}
/>
)
}
The demo in the preview, 210 lines
import {
PricingComparisonStickyHeader,
type ComparisonPlan,
type ComparisonSection,
type ComparisonValue,
} from "@/components/blocks/pricing-comparison-sticky-header"
export default function PricingComparisonStickyHeaderDemo() {
return <PricingComparisonStickyHeader headingLevel={1} />
}
const FREIGHT_PLANS: ComparisonPlan[] = [
{
id: "essentials",
name: "Shipper Essentials",
price: 49,
unit: "/user/mo",
action: { label: "Start with Essentials", href: "/signup?plan=essentials" },
},
{
id: "regional",
name: "Regional Forwarder",
price: 149.5,
unit: "/user/mo",
action: { label: "Try Regional", href: "/signup?plan=regional" },
},
{
id: "global",
name: "Global Forwarder with Customs Desk",
price: 399,
unit: "/user/mo",
action: { label: "Try Global", href: "/signup?plan=global" },
featured: true,
},
{
id: "network",
name: "Carrier Network",
price: 1250,
unit: "/user/mo",
action: { label: "Try Carrier Network", href: "/signup?plan=network" },
},
{
id: "tower",
name: "Control Tower",
priceLabel: "Quoted",
unit: "per contract",
action: { label: "Request a quote", href: "/contact?plan=tower" },
},
]
type Row = [name: string, ...values: ComparisonValue[]]
// One row per feature: the name, then a value for each freight plan in order.
function freightSection(title: string, rows: Row[]): ComparisonSection {
const slug = title.toLowerCase().replaceAll(" ", "-")
return {
id: slug,
title,
features: rows.map(([name, ...values], index) => ({
id: `${slug}-${index}`,
name,
values: Object.fromEntries(
FREIGHT_PLANS.map((plan, column) => [plan.id, values[column] ?? false])
),
})),
}
}
const FREIGHT_SECTIONS: ComparisonSection[] = [
freightSection("Tracking", [
["Shipments tracked each month", "500", "5,000", "50,000", "250,000", "Unlimited, fair use above 1,000,000 shipments a month"],
["Ocean container milestones", true, true, true, true, true],
["Air waybill milestones", false, true, true, true, true],
["Road telematics from carrier trackers and driver phones", false, "2 providers", "12 providers", "Unlimited", "Unlimited"],
["Predicted arrival times", false, false, true, true, true],
["Temperature and shock sensor readings", false, false, "Add-on", true, true],
]),
freightSection("Documents and customs", [
["Bill of lading storage", "1 year", "3 years", "7 years", "7 years", "10 years"],
["Commercial invoice extraction", false, "200 pages", "5,000 pages", "25,000 pages", "Unlimited"],
["Customs declaration filing in the EU and the United Kingdom", false, false, true, true, true],
["Dangerous goods checks", false, false, true, true, true],
["Certificate of origin requests", false, true, true, true, true],
["Broker handover pack", false, false, false, true, true],
]),
freightSection("Collaboration", [
["Shared shipment timeline", true, true, true, true, true],
["Customer portal", false, "1 portal", "10 portals", "Unlimited", "Unlimited"],
["Carrier and haulier guest accounts", "5", "50", "500", "Unlimited", "Unlimited"],
["Exception tasks with owners and due dates", false, true, true, true, true],
["Saved views", "3", "25", "Unlimited", "Unlimited", "Unlimited"],
["Scheduled email reports", false, "Weekly", "Daily", "Hourly", "Hourly"],
]),
freightSection("Integrations", [
["Spreadsheet import and export", true, true, true, true, true],
["Public API", false, "10,000 calls a day", "250,000 calls a day", "2,000,000 calls a day", "By contract"],
["Webhooks", false, true, true, true, true],
["ERP and warehouse connectors", false, false, "3 connectors", "12 connectors", "Unlimited"],
["EDI messages", false, false, false, true, true],
["Dedicated integration engineer", false, false, false, false, true],
]),
freightSection("Security", [
["Two-factor sign-in", true, true, true, true, true],
["SAML single sign-on", false, false, true, true, true],
["Role based permissions", "3 roles", "8 roles", "Custom roles", "Custom roles", "Custom roles"],
["Audit log", false, "30 days", "1 year", "3 years", "7 years"],
["Data residency", false, false, "EU", "EU or US", "EU, US or Singapore"],
["Customer managed encryption keys", false, false, false, false, true],
]),
freightSection("Support", [
["Help centre", true, true, true, true, true],
["Email support", "2 business days", "1 business day", "4 hours", "1 hour", "30 minutes"],
["Phone support", false, false, "Business hours", "Around the clock", "Around the clock"],
["Uptime commitment", false, "99.5%", "99.9%", "99.95%", "99.99%"],
["Onboarding", "Self serve", "2 sessions", "6 sessions", "Dedicated lead", "Dedicated team on site"],
["Quarterly service review", false, false, false, true, true],
]),
]
const NOTES_PLANS: ComparisonPlan[] = [
{
id: "personal",
name: "Personal",
price: 7.5,
unit: "/mo",
action: { label: "Choose Personal", href: "/signup?plan=personal" },
},
{
id: "household",
name: "Household",
price: 12,
unit: "/mo",
action: { label: "Choose Household", href: "/signup?plan=household" },
},
]
const NOTES_SECTIONS: ComparisonSection[] = [
{
id: "notes",
title: "Notes",
features: [
{
id: "devices",
name: "Synced devices",
values: { personal: "3", household: "Unlimited" },
},
{
id: "offline",
name: "Offline notebooks",
values: { personal: true, household: true },
},
{
id: "scan",
name: "Handwriting search",
hint: "In photos and scanned pages",
values: { personal: false, household: true },
},
],
},
{
id: "sharing",
title: "Sharing",
features: [
{
id: "members",
name: "Members",
values: { personal: "1", household: "Up to 6" },
},
{
id: "shared-notebooks",
name: "Shared notebooks",
values: { personal: false, household: true },
},
],
},
]
export const scenarios = {
empty: () => <PricingComparisonStickyHeader headingLevel={1} plans={[]} sections={[]} />,
overflow: () => (
<PricingComparisonStickyHeader
headingLevel={1}
title="Compare every Portside plan, from a single shipper to a carrier network"
description="Counts beside each section show how much of it a plan covers."
plans={FREIGHT_PLANS}
sections={FREIGHT_SECTIONS}
priceNote="Per user, billed monthly in US dollars. Tracking volume is pooled across the workspace."
featuredLabel="Most forwarders choose this"
/>
),
"two-plans-decimal-prices": () => (
<PricingComparisonStickyHeader
headingLevel={1}
title="Personal or Household"
description="Household adds handwriting search and shared notebooks for up to 6 members."
plans={NOTES_PLANS}
sections={NOTES_SECTIONS}
priceNote="Billed monthly. Cancel at any time."
currency="EUR"
/>
),
"below-fixed-site-header": () => (
<>
<div className="sticky top-0 z-30 flex h-16 items-center border-b border-border bg-background px-4 text-sm font-semibold">
Site header, 4rem tall
</div>
<PricingComparisonStickyHeader headingLevel={1} stickyOffset="4rem" />
</>
),
}
Props11
- title
- string = "Compare plans"
- description
- string = "Marks show what a plan includes, and limits are written out in full."
- Follows the computed plan and feature count in the intro sentence.
- headingLevel
- HeadingLevel = 2
- plans
- ComparisonPlan[] = DEFAULT_PLANS
- sections
- ComparisonSection[] = DEFAULT_SECTIONS
- priceNote
- string = "Per editor, billed yearly. Readers are free on every plan."
- Billing terms, set in the corner cell beside the prices.
- featuredLabel
- string = "Recommended"
- Text of the chip on a featured plan.
- currency
- string = "USD"
- ISO 4217 code.
- locale
- string = "en-US"
- stickyOffset
- string = "0px"
- CSS length from the top of the page at which the header pins: the height of a fixed site header.
- contactHref
- string = "/contact"
Also accepts every prop of Omit<React.ComponentProps<"section">, "title">.
Accessibility
- Pattern
- Table (APG, opens in a new tab), Landmarks and headings
- Keyboard
Keyboard support for Comparison Table with Sticky Header Key Effect Tab Moves to the table frame while it scrolls, then through each plan action in column order, then the sales link Arrow keys, Page Up, Page Down, Home, End Scroll the focused table frame. Plan header and feature column stay pinned - Screen reader
A section labelled by its heading holds a native table with a caption, a column header per plan (plain text, because a th may not contain a heading), a rowgroup header per section and a row header per feature. Marks carry hidden Included or Not included text. The frame is a focusable named region only while it scrolls.
- Reduced motion
- No motion. Colour transitions only.
- Checked
- Not checked yet. Automated results appear here once CI has run.
Dependencies3
- button
- @hazine/heading
- lucide-react
Filled chips are registry items the CLI adds for you. Outlined chips are npm packages.
Tokens shipped0
None. The item is styled by the tokens your theme already has.