# Pricing Toggle Card

> A pricing card with a monthly/yearly switch that swaps the price using radio buttons and :has().

- Category: [CSS Cards](https://copy-css.com/category/cards)
- Tags: pricing, monthly yearly, billing toggle, has, radio, discount
- Live preview: https://copy-css.com/snippets/pricing-toggle-card
- License: Free for personal and commercial use. No signup, no attribution required.

## HTML

```html
<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>
```

## CSS

```css
.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;
}
```

## Notes

- 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.
- the :has() selector: Chrome 105+, Safari 15.4+, Firefox 121+.
- In JSX use `className` instead of `class`. In Tailwind projects put the CSS in the global stylesheet.
