CSS Pricing Toggle Card
A pricing card with a monthly/yearly switch that swaps the price using radio buttons and :has().
$15 $12 per month
Get started<article class="price-switch">
<fieldset class="price-switch-toggle">
<legend>Billing period</legend>
<label><input type="radio" name="period" value="monthly" checked> Monthly</label>
<label><input type="radio" name="period" value="yearly"> Yearly <em>−20%</em></label>
</fieldset>
<p class="price-switch-amount">
<span class="price-switch-monthly">$15</span>
<span class="price-switch-yearly">$12</span>
<small>per month</small>
</p>
<a href="#">Get started</a>
</article>
.price-switch {
width: 240px;
padding: 18px;
border-radius: 18px;
background: #fff;
box-shadow: 0 10px 30px -12px rgba(20, 83, 45, 0.3);
color: #14532d;
font-family: system-ui, sans-serif;
text-align: center;
}
.price-switch-toggle {
display: grid;
grid-template-columns: 1fr 1fr;
margin: 0;
padding: 4px;
border: 0;
border-radius: 999px;
background: #dcfce7;
}
.price-switch-toggle legend {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip-path: inset(50%);
}
.price-switch-toggle label {
padding: 7px 4px;
border-radius: 999px;
font-size: 13px;
font-weight: 600;
cursor: pointer;
transition: background 0.2s ease;
}
.price-switch-toggle input {
position: absolute;
opacity: 0;
}
.price-switch-toggle label:has(:checked) {
background: #fff;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}
.price-switch-toggle label:has(:focus-visible) {
outline: 2px solid #16a34a;
outline-offset: 1px;
}
.price-switch-toggle em {
color: #16a34a;
font-size: 11px;
font-style: normal;
}
.price-switch-amount {
margin: 14px 0;
}
.price-switch-amount span {
font-size: 40px;
font-weight: 800;
}
.price-switch-amount small {
display: block;
color: #4d7c5f;
font-size: 13px;
}
.price-switch-yearly,
.price-switch:has([value="yearly"]:checked) .price-switch-monthly {
display: none;
}
.price-switch:has([value="yearly"]:checked) .price-switch-yearly {
display: inline;
}
.price-switch > a {
display: block;
padding: 10px;
border-radius: 10px;
background: #16a34a;
color: #fff;
font-size: 14px;
font-weight: 700;
text-decoration: none;
}
.price-switch > a:focus-visible {
outline: 2px solid #14532d;
outline-offset: 2px;
}
About this CSS Pricing Toggle Card
This CSS Pricing Toggle Card is 98 lines of pure CSS (1.7 KB) with no JavaScript and no dependencies. It uses transitions, box shadows, clip paths and CSS Grid. It works in current versions of Chrome, Edge, Safari and Firefox. It works in any stack: plain HTML, React, Vue, Svelte, Astro, WordPress or Webflow.
CSS features used
- transitions
- box shadows
- clip paths
- CSS Grid
- the :has() selectorChrome 105+, Safari 15.4+, Firefox 121+.
- the :checked state (no JavaScript)
- keyboard focus styles
Customize it
The colors in this snippet. Search and replace them to match your brand:
#fff#14532d#dcfce7#16a34a#4d7c5f
How to use this pricing toggle card
- Copy the HTML and paste it where you want the element to appear.
- Copy the CSS into your stylesheet, or inside a
<style>tag. - Keep the
.price-switchclass name, or rename it in both places. Then tweak colors, sizes and timing to match your design. - Using React or Next.js? Change
classtoclassNamein the HTML. The CSS works as is, including in Tailwind projects (put it in your global stylesheet).
Building with an AI tool?
“Copy for AI” copies a short prompt for Cursor, Claude Code, Lovable, Bolt or v0. Your AI tool opens the Markdown version of this snippet and reads the HTML, CSS and setup notes there. If your tool can't open links, with the code instead. More ways to use copy CSS with AI.