Tailwind pricing
Utility classes in markup, with class arrays for conditional styles.
<script lang="ts">
const plans = [
{ name: 'Hobby', monthly: 0, features: ['1 project', 'Community support'] },
{ name: 'Pro', monthly: 12, features: ['Unlimited projects', 'Email support', 'Custom domains'], popular: true },
{ name: 'Team', monthly: 39, features: ['Everything in Pro', 'SSO', 'Audit log'] },
]
const yearly = state(false)
const price = (monthly: number) => (yearly ? Math.round(monthly * 12 * 0.8) : monthly)
</script>
<div class="mx-auto max-w-3xl">
<div class="mb-6 flex items-center justify-center gap-3 text-sm">
<span class={yearly ? 'opacity-50' : 'font-semibold'}>Monthly</span>
<button
role="switch"
aria-checked={yearly}
aria-label="Bill yearly"
onClick={() => yearly.set(!yearly)}
class={['relative h-6 min-h-0 w-11 flex-none rounded-full border-0 p-0 shadow-none transition-colors', yearly ? 'bg-neutral-900 dark:bg-white' : 'bg-neutral-300 dark:bg-neutral-700']}
>
<span class={['absolute top-1 left-1 size-4 rounded-full bg-white shadow transition-transform', yearly && 'translate-x-5 dark:bg-neutral-950']}></span>
</button>
<span class={yearly ? 'font-semibold' : 'opacity-50'}>Yearly <em class="rounded-full bg-blue-500/10 px-1.5 py-0.5 text-xs text-blue-600 not-italic dark:text-blue-400">−20%</em></span>
</div>
<div class="grid gap-4 sm:grid-cols-3">
{plans.map((p) => (
<div
key={p.name}
class={[
'relative flex flex-col rounded-xl border bg-white p-5 transition hover:-translate-y-0.5 hover:shadow-lg dark:bg-neutral-950',
p.popular ? 'border-neutral-900 dark:border-white' : 'border-neutral-200 dark:border-neutral-800',
]}
>
{p.popular && <span class="absolute -top-3 left-5 rounded-full bg-neutral-900 px-2 py-0.5 text-xs font-medium text-white dark:bg-white dark:text-black">Popular</span>}
<h3 class="text-sm font-medium text-neutral-500">{p.name}</h3>
<p class="mt-1 text-3xl font-semibold tracking-tight">
${price(p.monthly)}
<span class="text-sm font-normal tracking-normal text-neutral-500">/{yearly ? 'yr' : 'mo'}</span>
</p>
<ul class="mt-4 flex flex-1 flex-col gap-2 p-0 text-sm">
{p.features.map((f) => (
<li key={f} class="flex gap-2"><span class="text-neutral-400">✓</span>{f}</li>
))}
</ul>
<button class={['mt-5 w-full rounded-lg py-2 font-medium', p.popular ? 'border-neutral-900 bg-neutral-900 text-white hover:bg-neutral-700! dark:border-white dark:bg-white dark:text-black dark:hover:bg-neutral-200!' : '']}>Choose {p.name}</button>
</div>
))}
</div>
</div>