Pricing section
Three pricing tiers with a monthly/yearly switch, rolling prices and a lifted, glowing recommended plan.
"use client";
import { useId, useState } from "react";
import "./pricing-section.css";
export type Plan = {
name: string;
monthly: number;
yearly: number; // price per month when billed yearly
blurb: string;
features: string[];
cta: string;
featured?: boolean;
};
type PricingSectionProps = {
plans: Plan[];
title?: string;
currency?: string;
theme?: "light" | "dark";
};
/**
* PricingSection
* - A real radio toggle switches Monthly / Yearly.
* - Prices roll vertically when they change (old number slides up, new one in).
* - The featured plan is lifted and outlined in the accent color.
* - Layout uses container queries, so it adapts to the box it lives in.
*/
export function PricingSection({
plans,
title = "Simple pricing",
currency = "$",
theme = "light",
}: PricingSectionProps) {
const [yearly, setYearly] = useState(true);
const id = useId(); // unique names, so two sections on one page never clash
return (
<section
className="gu-pricing"
data-theme={theme}
aria-labelledby={`${id}-title`}
>
<div className="gu-pricing__inner">
<header className="gu-pricing__head">
<h2 id={`${id}-title`}>{title}</h2>
<fieldset className="gu-pricing__switch">
<legend className="gu-pricing__sr">Billing period</legend>
<label data-on={!yearly || undefined}>
<input
type="radio"
name={`${id}-billing`}
checked={!yearly}
onChange={() => setYearly(false)}
/>
Monthly
</label>
<label data-on={yearly || undefined}>
<input
type="radio"
name={`${id}-billing`}
checked={yearly}
onChange={() => setYearly(true)}
/>
Yearly <span className="gu-pricing__save">−20%</span>
</label>
<span
className="gu-pricing__thumb"
data-right={yearly || undefined}
aria-hidden="true"
/>
</fieldset>
</header>
<ul className="gu-pricing__grid">
{plans.map((plan) => {
const price = yearly ? plan.yearly : plan.monthly;
return (
<li
key={plan.name}
className="gu-pricing__card"
data-featured={plan.featured || undefined}
>
{plan.featured && (
<p className="gu-pricing__badge">Most popular</p>
)}
<h3>{plan.name}</h3>
<p className="gu-pricing__blurb">{plan.blurb}</p>
<p className="gu-pricing__price">
<span className="gu-pricing__currency">{currency}</span>
{/* key = price, so React swaps the node and the roll-in animation plays */}
<span className="gu-pricing__amount" key={price}>
{price}
</span>
<span className="gu-pricing__per">/ month</span>
</p>
<a className="gu-pricing__cta" href="#">
{plan.cta}
</a>
<ul className="gu-pricing__features">
{plan.features.map((f) => (
<li key={f}>{f}</li>
))}
</ul>
</li>
);
})}
</ul>
</div>
</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 section
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 complete pricing section: a giant heading next to a Monthly/Yearly switch, then three plan cards. The middle "featured" plan is lifted, outlined in orange and carries a "Most popular" badge. When billing changes, every price rolls up into place.
## Layout and look
- Section background #f3eee3 (dark: #0e0e10), text #0e0e10 (dark: #f3eee3), muted #57534b (dark: #aea89c). Inner max-width 1100px, padding 72px 20px.
- Header: flex, wrap, space-between, aligned to bottom. Heading weight 900, clamp(2.2rem, 7cqi, 4.5rem), line-height 0.95, letter-spacing -0.045em.
- Switch: pill with 1px border and 4px padding; two 120×44px options; an orange (#ff5a1f) thumb slides behind the selected option (transform translateX(100%), 450ms cubic-bezier(0.34,1.3,0.5,1)). "Yearly" carries a tiny lime (#d7ff3a) "−20%" chip.
- Cards: 24px radius, 28px padding, 1px border, background #fbf8f2 (dark #18181b). Stack in one column; at container width ≥ 760px use three columns and lift the featured card by 14px.
- Featured card: 2px #ff5a1f border, orange glow shadow, orange badge sitting on the top border, solid orange button.
- Price: currency small and raised, amount 54px weight 900, tabular numbers, then "/ month" muted. The price row is a fixed 3.4rem tall with overflow hidden.
- Button: 48px tall pill, 2px border in text color, fills with text color on hover/focus.
- Features: list with 16px orange circle checkmarks.
## Behavior and motion
- When the price changes, re-mount the amount element (key = price) so a 550ms roll-in keyframe plays (from translateY(100%) and opacity 0).
- Use container queries (container-type: inline-size on the section) so the layout adapts to its container, not just the viewport.
## Accessibility
- The switch is a fieldset with a visually hidden legend "Billing period" and two real radio inputs. Focus ring on the focused option.
- Section is labelled by its heading.
- prefers-reduced-motion: no price roll, no lifted card, no thumb transition.
## 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.
### PricingSection.tsx
```tsx
"use client";
import { useId, useState } from "react";
import "./pricing-section.css";
export type Plan = {
name: string;
monthly: number;
yearly: number; // price per month when billed yearly
blurb: string;
features: string[];
cta: string;
featured?: boolean;
};
type PricingSectionProps = {
plans: Plan[];
title?: string;
currency?: string;
theme?: "light" | "dark";
};
/**
* PricingSection
* - A real radio toggle switches Monthly / Yearly.
* - Prices roll vertically when they change (old number slides up, new one in).
* - The featured plan is lifted and outlined in the accent color.
* - Layout uses container queries, so it adapts to the box it lives in.
*/
export function PricingSection({
plans,
title = "Simple pricing",
currency = "$",
theme = "light",
}: PricingSectionProps) {
const [yearly, setYearly] = useState(true);
const id = useId(); // unique names, so two sections on one page never clash
return (
<section
className="gu-pricing"
data-theme={theme}
aria-labelledby={`${id}-title`}
>
<div className="gu-pricing__inner">
<header className="gu-pricing__head">
<h2 id={`${id}-title`}>{title}</h2>
<fieldset className="gu-pricing__switch">
<legend className="gu-pricing__sr">Billing period</legend>
<label data-on={!yearly || undefined}>
<input
type="radio"
name={`${id}-billing`}
checked={!yearly}
onChange={() => setYearly(false)}
/>
Monthly
</label>
<label data-on={yearly || undefined}>
<input
type="radio"
name={`${id}-billing`}
checked={yearly}
onChange={() => setYearly(true)}
/>
Yearly <span className="gu-pricing__save">−20%</span>
</label>
<span
className="gu-pricing__thumb"
data-right={yearly || undefined}
aria-hidden="true"
/>
</fieldset>
</header>
<ul className="gu-pricing__grid">
{plans.map((plan) => {
const price = yearly ? plan.yearly : plan.monthly;
return (
<li
key={plan.name}
className="gu-pricing__card"
data-featured={plan.featured || undefined}
>
{plan.featured && (
<p className="gu-pricing__badge">Most popular</p>
)}
<h3>{plan.name}</h3>
<p className="gu-pricing__blurb">{plan.blurb}</p>
<p className="gu-pricing__price">
<span className="gu-pricing__currency">{currency}</span>
{/* key = price, so React swaps the node and the roll-in animation plays */}
<span className="gu-pricing__amount" key={price}>
{price}
</span>
<span className="gu-pricing__per">/ month</span>
</p>
<a className="gu-pricing__cta" href="#">
{plan.cta}
</a>
<ul className="gu-pricing__features">
{plan.features.map((f) => (
<li key={f}>{f}</li>
))}
</ul>
</li>
);
})}
</ul>
</div>
</section>
);
}
```
### pricing-section.css
```css
.gu-pricing {
--bg: #f3eee3;
--card: #fbf8f2;
--text: #0e0e10;
--muted: #57534b;
--line: rgb(14 14 16 / 0.12);
--accent: #ff5a1f;
--accent-text: #0e0e10;
container-type: inline-size; /* children respond to this box's width */
background: var(--bg);
color: var(--text);
font-family: system-ui, sans-serif;
}
.gu-pricing[data-theme="dark"] {
--bg: #0e0e10;
--card: #18181b;
--text: #f3eee3;
--muted: #aea89c;
--line: rgb(243 238 227 / 0.1);
}
.gu-pricing__inner {
max-width: 1100px;
margin: 0 auto;
padding: 72px 20px;
}
/* Heading + billing switch */
.gu-pricing__head {
display: flex;
flex-wrap: wrap;
align-items: end;
justify-content: space-between;
gap: 24px;
margin-bottom: 40px;
}
.gu-pricing__head h2 {
margin: 0;
font-size: clamp(2.2rem, 7cqi, 4.5rem);
font-weight: 900;
line-height: 0.95;
letter-spacing: -0.045em;
}
.gu-pricing__switch {
position: relative;
display: inline-flex;
margin: 0;
padding: 4px;
border: 1px solid var(--line);
border-radius: 999px;
}
.gu-pricing__switch label {
position: relative;
z-index: 1;
display: inline-flex;
align-items: center;
gap: 6px;
min-width: 120px;
min-height: 44px;
justify-content: center;
border-radius: 999px;
font-weight: 700;
font-size: 0.95rem;
color: var(--muted);
cursor: pointer;
transition: color 0.3s;
}
.gu-pricing__switch label[data-on] {
color: var(--accent-text);
}
.gu-pricing__switch input {
position: absolute;
inset: 0;
opacity: 0;
cursor: pointer;
}
.gu-pricing__switch label:has(input:focus-visible) {
outline: 2px solid var(--text);
outline-offset: 2px;
}
.gu-pricing__thumb {
position: absolute;
top: 4px;
left: 4px;
width: 120px;
height: 44px;
border-radius: 999px;
background: var(--accent);
transition: transform 0.45s cubic-bezier(0.34, 1.3, 0.5, 1);
}
.gu-pricing__thumb[data-right] {
transform: translateX(100%);
}
.gu-pricing__save {
font-size: 0.72rem;
padding: 2px 6px;
border-radius: 999px;
background: #d7ff3a;
color: #0e0e10;
}
/* Plans */
.gu-pricing__grid {
display: grid;
gap: 16px;
margin: 0;
padding: 0;
list-style: none;
}
@container (min-width: 760px) {
.gu-pricing__grid {
grid-template-columns: repeat(3, 1fr);
align-items: start;
}
.gu-pricing__card[data-featured] {
transform: translateY(-14px);
}
}
.gu-pricing__card {
position: relative;
padding: 28px;
border: 1px solid var(--line);
border-radius: 24px;
background: var(--card);
transition:
transform 0.5s cubic-bezier(0.16, 1, 0.3, 1),
box-shadow 0.5s;
}
.gu-pricing__card[data-featured] {
border: 2px solid var(--accent);
box-shadow: 0 30px 60px -30px rgb(255 90 31 / 0.55);
}
@media (hover: hover) {
.gu-pricing__card:hover {
box-shadow: 0 30px 60px -34px rgb(14 14 16 / 0.35);
}
}
.gu-pricing__badge {
position: absolute;
top: -13px;
right: 24px;
margin: 0;
padding: 4px 12px;
border-radius: 999px;
background: var(--accent);
color: var(--accent-text);
font-size: 0.78rem;
font-weight: 800;
}
.gu-pricing__card h3 {
margin: 0 0 6px;
font-size: 1.35rem;
letter-spacing: -0.02em;
}
.gu-pricing__blurb {
margin: 0;
color: var(--muted);
font-size: 0.95rem;
}
.gu-pricing__price {
display: flex;
align-items: baseline;
margin: 28px 0 24px;
height: 3.4rem;
overflow: hidden;
}
.gu-pricing__currency {
align-self: flex-start;
margin-top: 0.4rem;
font-size: 1.5rem;
font-weight: 800;
}
.gu-pricing__amount {
display: inline-block;
font-size: 3.4rem;
font-weight: 900;
line-height: 1;
letter-spacing: -0.05em;
font-variant-numeric: tabular-nums;
animation: gu-price-roll 0.55s cubic-bezier(0.16, 1, 0.3, 1);
}
.gu-pricing__per {
margin-left: 6px;
color: var(--muted);
font-size: 0.9rem;
}
@keyframes gu-price-roll {
from {
transform: translateY(100%);
opacity: 0;
}
}
.gu-pricing__cta {
display: flex;
align-items: center;
justify-content: center;
min-height: 48px;
border: 2px solid var(--text);
border-radius: 999px;
color: var(--text);
font-weight: 800;
text-decoration: none;
transition:
background-color 0.25s,
color 0.25s;
}
.gu-pricing__cta:hover,
.gu-pricing__cta:focus-visible {
background: var(--text);
color: var(--bg);
}
.gu-pricing__card[data-featured] .gu-pricing__cta {
border-color: var(--accent);
background: var(--accent);
color: var(--accent-text);
}
.gu-pricing__features {
display: grid;
gap: 10px;
margin: 24px 0 0;
padding: 0;
list-style: none;
font-size: 0.95rem;
}
.gu-pricing__features li {
display: flex;
gap: 10px;
}
.gu-pricing__features li::before {
content: "";
flex: none;
width: 16px;
height: 16px;
margin-top: 3px;
border-radius: 50%;
background: var(--accent)
url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path d='M4.5 8.2l2.2 2.2 4.8-4.9' fill='none' stroke='%230e0e10' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/></svg>")
center / 100% no-repeat;
}
.gu-pricing__sr {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip: rect(0 0 0 0);
}
@media (prefers-reduced-motion: reduce) {
.gu-pricing__amount {
animation: none;
}
.gu-pricing__card[data-featured] {
transform: none;
}
.gu-pricing__thumb {
transition: none;
}
}
```
You might also want
Next piece: FAQ accordionBento features grid
Templates, intermediate
Pricing comparison table
Templates, intermediate
Public roadmap
Templates, intermediate