PRICING

Pricing Table.

Plan cards with a monthly and yearly switch. Prices count to their new value when the period changes, and one plan can be highlighted.

Fictional pricingAcme is a made-up product, and these plans and prices are examples. Opalframe itself is free.

Billing period
  • Starter

    For side projects and trying Acme out.

    $0 per month

    Free forever

    • 1 project
    • Up to 3 teammates
    • Community support
  • Team

    Most popular

    For small teams that ship every week.

    $24 per month

    Billed monthly

    • Unlimited projects
    • Up to 20 teammates
    • Preview deployments
    • Email support
  • Business

    For companies with review and compliance needs.

    $59 per month

    Billed monthly

    • Everything in Team
    • SSO and audit logs
    • 99.9% uptime SLA
    • Priority support

Showing monthly prices.

The buttons call onSelect. Nothing is purchased.

REACT + TYPESCRIPT + CSSMIT LICENSE

Installation

In a project with React and shadcn configured, run:

npx shadcn@latest add https://aduneer.github.io/opalframe/r/pricing-table.json

Copies the component and its stylesheet into components/ui. No additional runtime dependencies. Tailwind classes work through className.

For manual installation, copy both files from Source below. Keep the CSS import alongside the component.

Usage

import { PricingTable } from "@/components/ui/pricing-table";

export default function Example() {
  return (
    <PricingTable
      yearlyNote="Save 20%"
      plans={[
        {
          id: "starter", name: "Starter", price: { monthly: 0, yearly: 0 },
          features: ["1 project"], cta: "Start for free", href: "/signup",
        },
        {
          id: "team", name: "Team", price: { monthly: 24, yearly: 19 },
          features: ["Unlimited projects", "Email support"],
          cta: "Start a trial", href: "/signup?plan=team",
          highlighted: true, badge: "Most popular",
        },
      ]}
    />
  );
}

Customize

Colors and sizes are scoped CSS variables. Override them on your own class.

<PricingTable plans={plans} className="your-pricing" />

.your-pricing {
  --pricing-accent: #a6cfff;
  --pricing-accent-ink: #101216;
  --pricing-surface: #1e2530;
  --pricing-line: #3f4f64;
  --pricing-radius: 20px;
}

Props

PropTypeWhat it does
plansPricingPlan[]Unique id, name, price per month for each period, features, and a call-to-action label. Add href to render a link, plus an optional description, highlighted flag, and badge.
period / defaultPeriod"monthly" | "yearly"Controlled or initial billing period. Defaults to monthly.
onPeriodChange(period: BillingPeriod) => voidCalled when the visitor switches the period.
onSelect(plan, period) => voidCalled by button calls to action. Plans with href render links instead.
yearlyNotestringShort note beside the yearly option, such as Save 20%.
currency / localestringIntl currency formatting. Defaults to USD and en-US so server and client render the same text.
label / className / reducedMotionstring / string / booleanAccessible name for the section, root customization, and showing new prices without counting.

Accessibility & motion

The billing switch is a pair of native radio buttons in a fieldset, so arrow keys and screen readers work as usual. Each price is read once as its final value, such as $19 per month; the counting is hidden from assistive technology. A status message announces the period change. Plan names are headings and features are lists. The pointer light appears only with a mouse. Reduced motion shows the new price immediately.

Dependencies

React only. Styles live in a plain CSS file next to the component, and Tailwind utilities work through className.

Source

pricing-table.tsx
"use client";

import {
  useEffect,
  useId,
  useState,
  useSyncExternalStore,
  type PointerEvent,
} from "react";
import "./pricing-table.css";

export type BillingPeriod = "monthly" | "yearly";

export interface PricingPlan {
  id: string;
  name: string;
  description?: string;
  /** Price per month for each billing period. */
  price: Record<BillingPeriod, number>;
  features: string[];
  cta: string;
  /** Renders the call to action as a link instead of a button. */
  href?: string;
  highlighted?: boolean;
  badge?: string;
}

export interface PricingTableProps {
  plans: PricingPlan[];
  period?: BillingPeriod;
  defaultPeriod?: BillingPeriod;
  onPeriodChange?: (period: BillingPeriod) => void;
  /** Called by button calls to action. Links navigate natively. */
  onSelect?: (plan: PricingPlan, period: BillingPeriod) => void;
  /** Shown beside the yearly option, such as "Save 20%". */
  yearlyNote?: string;
  currency?: string;
  /** Fixed by default so server and client format prices identically. */
  locale?: string;
  label?: string;
  className?: string;
  reducedMotion?: boolean;
}

function subscribeMotion(callback: () => void) {
  const query = matchMedia("(prefers-reduced-motion: reduce)");
  query.addEventListener("change", callback);
  return () => query.removeEventListener("change", callback);
}
const getMotion = () => matchMedia("(prefers-reduced-motion: reduce)").matches;

/** Counts from the previous price to the next one. Assistive tech reads only the final value. */
function AnimatedPrice({
  value,
  format,
  animate,
}: {
  value: number;
  format: (value: number) => string;
  animate: boolean;
}) {
  const [shown, setShown] = useState(value);
  const [from, setFrom] = useState(value);
  const [to, setTo] = useState(value);
  if (value !== to) {
    setFrom(shown);
    setTo(value);
  }
  useEffect(() => {
    if (!animate || from === to) return;
    let frame = 0;
    const start = performance.now();
    const tick = (now: number) => {
      const progress = Math.min(1, (now - start) / 520);
      setShown(from + (to - from) * (1 - (1 - progress) ** 3));
      if (progress < 1) frame = requestAnimationFrame(tick);
    };
    frame = requestAnimationFrame(tick);
    return () => cancelAnimationFrame(frame);
  }, [from, to, animate]);
  const cents = !Number.isInteger(value);
  const display = animate ? shown : value;
  return <>{format(cents ? display : Math.round(display))}</>;
}

export function PricingTable({
  plans,
  period,
  defaultPeriod = "monthly",
  onPeriodChange,
  onSelect,
  yearlyNote,
  currency = "USD",
  locale = "en-US",
  label = "Pricing plans",
  className = "",
  reducedMotion = false,
}: PricingTableProps) {
  const uid = useId();
  const [internal, setInternal] = useState(defaultPeriod);
  const billing = period ?? internal;
  const osReduced = useSyncExternalStore(
    subscribeMotion,
    getMotion,
    () => true,
  );
  const animate = !reducedMotion && !osReduced;

  function format(amount: number) {
    return new Intl.NumberFormat(locale, {
      style: "currency",
      currency,
      minimumFractionDigits: Number.isInteger(amount) ? 0 : 2,
      maximumFractionDigits: Number.isInteger(amount) ? 0 : 2,
    }).format(amount);
  }

  function choose(next: BillingPeriod) {
    if (period === undefined) setInternal(next);
    onPeriodChange?.(next);
  }

  function light(event: PointerEvent<HTMLElement>) {
    if (event.pointerType !== "mouse") return;
    const card = event.currentTarget;
    const bounds = card.getBoundingClientRect();
    card.style.setProperty("--pricing-x", `${event.clientX - bounds.left}px`);
    card.style.setProperty("--pricing-y", `${event.clientY - bounds.top}px`);
  }

  if (!plans.length) return null;
  return (
    <section
      className={`is-pricing ${className}`}
      aria-label={label}
      data-period={billing}
      data-reduced-motion={reducedMotion || undefined}
    >
      <fieldset className="is-pricing-period">
        <legend className="is-pricing-sr">Billing period</legend>
        <span className="is-pricing-thumb" aria-hidden="true" />
        {(["monthly", "yearly"] as const).map((option) => (
          <label key={option}>
            <input
              type="radio"
              name={`${uid}-period`}
              value={option}
              checked={billing === option}
              onChange={() => choose(option)}
            />
            {option === "monthly" ? "Monthly" : "Yearly"}
            {option === "yearly" && yearlyNote && (
              <span className="is-pricing-note">{yearlyNote}</span>
            )}
          </label>
        ))}
      </fieldset>
      <ul className="is-pricing-plans" role="list">
        {plans.map((plan) => {
          const amount = plan.price[billing];
          return (
            <li
              key={plan.id}
              className="is-pricing-plan"
              data-highlighted={plan.highlighted || undefined}
              onPointerMove={light}
            >
              <div className="is-pricing-head">
                <h3>{plan.name}</h3>
                {plan.badge && (
                  <span className="is-pricing-badge">{plan.badge}</span>
                )}
              </div>
              {plan.description && (
                <p className="is-pricing-description">{plan.description}</p>
              )}
              <p className="is-pricing-price">
                <span className="is-pricing-amount" aria-hidden="true">
                  <AnimatedPrice
                    value={amount}
                    format={format}
                    animate={animate}
                  />
                </span>
                <span className="is-pricing-unit" aria-hidden="true">
                  / month
                </span>
                <span className="is-pricing-sr">
                  {format(amount)} per month
                </span>
              </p>
              <p className="is-pricing-billing">
                {amount === 0
                  ? "Free forever"
                  : billing === "yearly"
                    ? `${format(amount * 12)} billed yearly`
                    : "Billed monthly"}
              </p>
              {plan.href ? (
                <a className="is-pricing-cta" href={plan.href}>
                  {plan.cta}
                </a>
              ) : (
                <button
                  className="is-pricing-cta"
                  type="button"
                  onClick={() => onSelect?.(plan, billing)}
                >
                  {plan.cta}
                </button>
              )}
              <ul className="is-pricing-features" role="list">
                {plan.features.map((feature) => (
                  <li key={feature}>
                    <svg viewBox="0 0 16 16" aria-hidden="true">
                      <path d="m3.5 8.5 3 3 6-7" />
                    </svg>
                    {feature}
                  </li>
                ))}
              </ul>
            </li>
          );
        })}
      </ul>
      <p className="is-pricing-sr" role="status">
        {billing === "yearly"
          ? "Showing yearly prices."
          : "Showing monthly prices."}
      </p>
    </section>
  );
}
pricing-table.css
.is-pricing {
  --pricing-surface: var(--surface, #181d25);
  --pricing-text: var(--text, #f0f3f8);
  --pricing-muted: var(--muted, #adb7c6);
  --pricing-line: var(--line, #343d4a);
  --pricing-selected: var(--raised, #242a33);
  --pricing-accent: var(--accent, #b2cfff);
  --pricing-accent-ink: var(--bg, #101216);
  --pricing-radius: 16px;
  width: 100%;
  min-width: 0;
  container-type: inline-size;
  color: var(--pricing-text);
}
.is-pricing *,
.is-pricing *::before,
.is-pricing *::after {
  box-sizing: border-box;
}
.is-pricing-period {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: fit-content;
  min-width: 260px;
  margin: 0 auto 28px;
  padding: 4px;
  border: 1px solid var(--pricing-line);
  border-radius: 999px;
  background: var(--pricing-surface);
}
.is-pricing-period label {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 36px;
  padding: 0 16px;
  border-radius: 999px;
  color: var(--pricing-muted);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: color 160ms;
}
.is-pricing-period label:has(input:checked) {
  color: var(--pricing-text);
}
.is-pricing-period label:has(input:focus-visible) {
  outline: 2px solid var(--pricing-accent);
  outline-offset: -2px;
}
.is-pricing-period input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.is-pricing-thumb {
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: 4px;
  width: calc(50% - 4px);
  border-radius: 999px;
  background: var(--pricing-selected);
  box-shadow:
    inset 0 1px 0 #ffffff0d,
    0 1px 3px #00000024;
  transition: transform 280ms cubic-bezier(0.22, 1, 0.36, 1);
}
.is-pricing[data-period="yearly"] .is-pricing-thumb {
  transform: translateX(100%);
}
.is-pricing-note {
  padding: 2px 7px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--pricing-accent) 18%, transparent);
  color: var(--pricing-accent);
  font-size: 10px;
  font-weight: 600;
}
.is-pricing-plans {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.is-pricing-plan {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 24px;
  overflow: hidden;
  border: 1px solid var(--pricing-line);
  border-radius: var(--pricing-radius);
  background: var(--pricing-surface);
  transition:
    border-color 180ms,
    transform 220ms cubic-bezier(0.22, 1, 0.36, 1);
}
.is-pricing-plan::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(
    280px circle at var(--pricing-x, 50%) var(--pricing-y, 0%),
    color-mix(in srgb, var(--pricing-accent) 12%, transparent),
    transparent 70%
  );
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms;
}
@media (hover: hover) and (pointer: fine) {
  .is-pricing-plan:hover::before {
    opacity: 1;
  }
  .is-pricing-plan:hover {
    border-color: color-mix(
      in srgb,
      var(--pricing-accent) 40%,
      var(--pricing-line)
    );
  }
}
.is-pricing-plan[data-highlighted] {
  border-color: color-mix(in srgb, var(--pricing-accent) 70%, transparent);
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--pricing-accent) 10%, var(--pricing-surface)),
    var(--pricing-surface) 55%
  );
  box-shadow: 0 24px 50px -32px
    color-mix(in srgb, var(--pricing-accent) 60%, transparent);
}
.is-pricing-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.is-pricing-head h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}
.is-pricing-badge {
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--pricing-accent);
  color: var(--pricing-accent-ink);
  font-size: 10px;
  font-weight: 600;
  white-space: nowrap;
}
.is-pricing-description {
  margin: 0;
  min-height: 2.9em;
  color: var(--pricing-muted);
  font-size: 13px;
  line-height: 1.45;
}
.is-pricing-price {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin: 6px 0 0;
}
.is-pricing-amount {
  font-size: 38px;
  font-weight: 600;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
.is-pricing-unit,
.is-pricing-billing {
  color: var(--pricing-muted);
  font-size: 12px;
}
.is-pricing-billing {
  margin: -8px 0 0;
}
.is-pricing-cta {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid var(--pricing-line);
  border-radius: 9px;
  background: transparent;
  color: var(--pricing-text);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition:
    background 160ms,
    border-color 160ms;
}
.is-pricing-cta:hover {
  background: var(--pricing-selected);
}
.is-pricing-cta:focus-visible {
  outline: 2px solid var(--pricing-accent);
  outline-offset: 2px;
}
.is-pricing-plan[data-highlighted] .is-pricing-cta {
  border-color: var(--pricing-accent);
  background: var(--pricing-accent);
  color: var(--pricing-accent-ink);
}
.is-pricing-plan[data-highlighted] .is-pricing-cta:hover {
  background: color-mix(in srgb, var(--pricing-accent) 85%, #ffffff);
}
.is-pricing-features {
  display: grid;
  gap: 9px;
  margin: 6px 0 0;
  padding: 16px 0 0;
  border-top: 1px solid var(--pricing-line);
  list-style: none;
  color: var(--pricing-muted);
  font-size: 13px;
  line-height: 1.4;
}
.is-pricing-features li {
  display: flex;
  align-items: flex-start;
  gap: 9px;
}
.is-pricing-features svg {
  flex: 0 0 16px;
  width: 16px;
  height: 16px;
  margin-top: 1px;
  fill: none;
  stroke: var(--pricing-accent);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.is-pricing-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
@container (max-width: 520px) {
  .is-pricing-period {
    min-width: 0;
    width: 100%;
  }
  .is-pricing-period label {
    padding: 0 10px;
  }
  .is-pricing-plan {
    padding: 20px;
  }
}
.is-pricing[data-reduced-motion] .is-pricing-thumb,
.is-pricing[data-reduced-motion] .is-pricing-plan,
.is-pricing[data-reduced-motion] .is-pricing-plan::before {
  transition: none;
}
@media (prefers-reduced-motion: reduce) {
  .is-pricing .is-pricing-thumb,
  .is-pricing .is-pricing-plan,
  .is-pricing .is-pricing-plan::before {
    transition: none;
  }
}