Skip to the main content

Monthly and Yearly Billing Toggle

Free Pricing

A two-option billing switch that changes three example plan prices between monthly and yearly and works the saving out from the prices.

Checked on 3 December 2026 in Chrome 143.0.7499.169: 12 automated checks. What the checks are

Preview and code

HTML

<section class="bt" aria-labelledby="bt-title">
  <div class="bt__top">
  <div class="bt__head">
    <h2 class="bt__title" id="bt-title">Choose a billing period</h2>
    <p class="bt__caption">Example prices only. These are not real offers.</p>
  </div>

  <fieldset class="bt__toggle" id="bt-toggle" hidden>
    <legend class="bt__legend">Billing period</legend>
    <div class="bt__options">
      <label class="bt__option"><input type="radio" name="bt-period" value="monthly" checked><span>Monthly</span></label>
      <label class="bt__option"><input type="radio" name="bt-period" value="yearly"><span>Yearly</span></label>
    </div>
  </fieldset>
  </div>

  <ul class="bt__plans" aria-label="Example plans">
      <li class="bt__plan" data-monthly="9" data-yearly="90">
        <h3 class="bt__name">Basic</h3>
        <p class="bt__price"><span class="bt__amount">&pound;9</span> <span class="bt__period">a month</span></p>
        <p class="bt__note">Billed monthly</p>
        <ul class="bt__features">
          <li>3 example projects</li>
          <li>Weekly summary</li>
          <li>Email notes</li>
        </ul>
      </li>
      <li class="bt__plan" data-monthly="19" data-yearly="190">
        <h3 class="bt__name">Team</h3>
        <p class="bt__price"><span class="bt__amount">&pound;19</span> <span class="bt__period">a month</span></p>
        <p class="bt__note">Billed monthly</p>
        <ul class="bt__features">
          <li>20 example projects</li>
          <li>Shared notes</li>
          <li>Daily summary</li>
        </ul>
      </li>
      <li class="bt__plan" data-monthly="39" data-yearly="390">
        <h3 class="bt__name">Studio</h3>
        <p class="bt__price"><span class="bt__amount">&pound;39</span> <span class="bt__period">a month</span></p>
        <p class="bt__note">Billed monthly</p>
        <ul class="bt__features">
          <li>Unlimited projects</li>
          <li>Notes and history</li>
          <li>Hourly summary</li>
        </ul>
      </li>
  </ul>
  <p class="bt__sr" id="bt-status" role="status"></p>
</section>

CSS

.bt {
  --bt-bg: #ffffff;
  --bt-tint: #f3f4fb;
  --bt-ink: #1c2033;
  --bt-muted: #4b5266;
  --bt-line: #d5d9e6;
  --bt-accent: #4338ca;
  --bt-on-accent: #ffffff;
  --bt-focus: #1c2033;
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  max-width: 46rem;
  padding: 1.5rem;
  color: var(--bt-ink);
  background: var(--bt-bg);
  border: 1px solid var(--bt-line);
  border-radius: 16px;
  box-shadow: 0 1px 2px rgba(28, 32, 51, 0.06), 0 10px 28px -14px rgba(28, 32, 51, 0.22);
}
.bt *, .bt *::before, .bt *::after { box-sizing: inherit; }
.bt [hidden] { display: none; }

.bt__top { display: grid; gap: 0.9rem; margin-bottom: 1.1rem; }
.bt__head { min-width: 0; }
.bt__title { margin: 0; font-size: 1.35rem; line-height: 1.2; letter-spacing: -0.01em; }
.bt__caption { display: inline-block; margin: 0.45rem 0 0; padding: 0.15rem 0.6rem; color: var(--bt-ink); background: var(--bt-tint); border: 1px dashed var(--bt-muted); border-radius: 8px; font-size: 0.82rem; font-weight: 600; }

.bt__toggle { margin: 0; padding: 0; border: 0; min-width: 0; }
.bt__legend { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; padding: 0; }
.bt__options { display: inline-flex; flex-wrap: wrap; gap: 0.25rem; padding: 0.25rem; background: var(--bt-tint); border: 1px solid var(--bt-line); border-radius: 14px; }
.bt__option {
  display: inline-flex; align-items: center; gap: 0.5rem;
  min-height: 2.75rem; padding: 0.3rem 0.9rem 0.3rem 0.7rem;
  font-weight: 650; cursor: pointer; border: 1.5px solid transparent; border-radius: 10px;
}
.bt__option input { flex: none; width: 1.15rem; height: 1.15rem; margin: 0; accent-color: var(--bt-accent); }
.bt__option:has(input:checked) { background: var(--bt-bg); border-color: var(--bt-accent); box-shadow: 0 1px 3px rgba(28, 32, 51, 0.12); }
.bt__option input:focus-visible { outline: 3px solid var(--bt-focus); outline-offset: 2px; }

.bt__plans { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.8rem; margin: 0; padding: 0; list-style: none; }
.bt__plan { padding: 0.95rem 1.1rem 1rem; background: var(--bt-bg); border: 1px solid var(--bt-line); border-top: 4px solid var(--bt-accent); border-radius: 12px; }
.bt__name { margin: 0 0 0.35rem; color: var(--bt-muted); font-size: 0.85rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.bt__price { margin: 0; line-height: 1.1; }
.bt__amount { font-size: 2.1rem; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.bt__period { color: var(--bt-muted); font-size: 0.9rem; }
.bt__note { min-height: 2.6em; margin: 0.35rem 0 0.7rem; color: var(--bt-muted); font-size: 0.82rem; line-height: 1.3; }
.bt__features { margin: 0; padding: 0.7rem 0 0; list-style: none; border-top: 1px solid var(--bt-line); font-size: 0.9rem; }
.bt__features li { position: relative; padding: 0.2rem 0 0.2rem 1.5rem; }
.bt__features li::before { content: ""; position: absolute; left: 0.15rem; top: 0.5rem; width: 0.55rem; height: 0.3rem; border-left: 2px solid var(--bt-accent); border-bottom: 2px solid var(--bt-accent); transform: rotate(-45deg); }
.bt__sr { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

@media (min-width: 36rem) {
  .bt__top { grid-template-columns: minmax(0, 1fr) auto; align-items: end; }
  .bt__plans { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 30rem) {
  .bt { padding: 1rem; }
  .bt__note { min-height: 0; }
}
@media (prefers-color-scheme: dark) {
  .bt {
    --bt-bg: #1c2033; --bt-tint: #272c45; --bt-ink: #eceef8; --bt-muted: #b3b9d0; --bt-line: #3d4466;
    --bt-accent: #b4b9ff; --bt-on-accent: #14172a; --bt-focus: #ffffff;
    box-shadow: none;
  }
  .bt__option:has(input:checked) { box-shadow: none; }
}

JavaScript

(function () {
  'use strict';

  var root = document.querySelector('.bt');
  var toggle = document.getElementById('bt-toggle');
  var status = document.getElementById('bt-status');
  if (!root || !toggle || !status) return;

  var plans = Array.prototype.slice.call(root.querySelectorAll('.bt__plan'));
  var options = toggle.querySelectorAll('input[name="bt-period"]');

  function pounds(value) {
    return '£' + value;
  }

  // A saving is worked out here from the two example prices, never typed into the page.
  function show(period) {
    var yearly = period === 'yearly';
    plans.forEach(function (plan) {
      var monthly = Number(plan.getAttribute('data-monthly'));
      var year = Number(plan.getAttribute('data-yearly'));
      plan.querySelector('.bt__amount').textContent = pounds(yearly ? year : monthly);
      plan.querySelector('.bt__period').textContent = yearly ? 'a year' : 'a month';
      plan.querySelector('.bt__note').textContent = yearly
        ? 'Saves ' + pounds(monthly * 12 - year) + ' against 12 monthly payments'
        : 'Billed monthly';
    });
    status.textContent = 'Showing ' + (yearly ? 'yearly' : 'monthly') + ' example prices.';
  }

  // The choice only works with this script, so it appears when the script runs.
  toggle.hidden = false;
  Array.prototype.forEach.call(options, function (input) {
    input.addEventListener('change', function () {
      if (input.checked) show(input.value);
    });
  });
})();

Accessibility notes

Written by the author of the snippet. Each note has a test step or a markup check that reads the page.

  • The choice is a fieldset of native radio buttons, so arrow keys move between the options.
  • A polite status line says which prices are shown after each change.
  • The page says in words that the prices are examples.
Pricing
Free

Pricing Table

A three-plan pricing table with a featured plan, feature lists that use words as well as ticks, and a button on each plan. All prices are labelled as examples.

  • HTML
  • CSS
  • No library
  • Cards
  • Grid