Snippets Form

Bootstrap 5 Credit Card Checkout with Formatted Input

A credit card checkout with a live card preview that highlights the active field, brand-aware number formatting, an itemised receipt-style order summary and a promo code field.

Bootstrap 5 No jQuery Jul 2020 5.9K views

<section class="wdw-stage cc-stage">
  <div class="container" style="max-width:1020px">
    <form class="wdw-card overflow-hidden" id="cc-form" novalidate>
      <div class="row g-0">
        <div class="col-lg-7 p-4 p-md-5">
          <span class="wdw-eyebrow mb-1">Checkout</span>
          <h2 class="wdw-heading h4 mb-4">Payment details</h2>
          <div class="row g-3">
            <div class="col-12"><div class="form-floating"><input class="form-control" id="cc-name" placeholder="Name on card" autocomplete="cc-name" aria-describedby="cc-name-err" required><label for="cc-name">Name on card</label><div class="invalid-feedback" id="cc-name-err">Enter the name shown on the card.</div></div></div>
            <div class="col-12"><div class="form-floating"><input class="form-control" id="cc-no" placeholder="Card number" inputmode="numeric" autocomplete="cc-number" maxlength="19" aria-describedby="cc-no-err" required><label for="cc-no">Card number</label><div class="invalid-feedback" id="cc-no-err">Enter a valid card number.</div></div></div>
            <div class="col-6"><div class="form-floating"><input class="form-control" id="cc-exp" placeholder="MM/YY" inputmode="numeric" autocomplete="cc-exp" maxlength="5" aria-describedby="cc-exp-err" required><label for="cc-exp">Expiry (MM/YY)</label><div class="invalid-feedback" id="cc-exp-err">Use MM/YY.</div></div></div>
            <div class="col-6"><div class="form-floating"><input class="form-control" id="cc-cvc" placeholder="CVC" inputmode="numeric" autocomplete="cc-csc" maxlength="4" aria-describedby="cc-cvc-err" required><label for="cc-cvc">CVC</label><div class="invalid-feedback" id="cc-cvc-err">Enter the security code.</div></div></div>
            <div class="col-12"><div class="form-floating"><input type="email" class="form-control" id="cc-mail" placeholder="Receipt email" autocomplete="email" aria-describedby="cc-mail-err" required><label for="cc-mail">Email for receipt</label><div class="invalid-feedback" id="cc-mail-err">Enter a valid email address.</div></div></div>
            <div class="col-sm-6"><div class="form-floating"><select class="form-select" id="cc-country" autocomplete="country"><option>United States</option><option>Canada</option><option>United Kingdom</option><option>Germany</option><option>Australia</option></select><label for="cc-country">Country</label></div></div>
            <div class="col-sm-6"><div class="form-floating"><input class="form-control" id="cc-zip" placeholder="Postal code" autocomplete="postal-code" aria-describedby="cc-zip-err" required><label for="cc-zip">Postal code</label><div class="invalid-feedback" id="cc-zip-err">Enter your postal code.</div></div></div>
            <div class="col-12"><div class="form-check"><input class="form-check-input" type="checkbox" id="cc-save" checked><label class="form-check-label" for="cc-save">Save this card for future payments</label></div></div>
          </div>
          <p class="small wdw-muted d-flex gap-2 align-items-center mt-4 mb-0"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg>Payments are encrypted and secure.</p>
        </div>
        <div class="col-lg-5 cc-side p-4 p-md-5">
                    <div class="cc-preview wdw-aurora rounded-4 p-3 mb-4" aria-hidden="true">
            <div class="d-flex justify-content-between align-items-start">
              <svg width="34" height="26" viewBox="0 0 34 26" fill="none"><rect x="1" y="1" width="32" height="24" rx="5" fill="#fff" fill-opacity=".18" stroke="#fff" stroke-opacity=".7" stroke-width="1.5"/><path d="M1 9h32M1 17h32M12 1v24" stroke="#fff" stroke-opacity=".6" stroke-width="1.5"/></svg>
              <span class="cc-brand" id="cc-brand" data-brand="card"><span class="cc-b cc-b-visa">VISA</span><svg class="cc-b cc-b-mc" width="40" height="26" viewBox="0 0 40 26"><circle cx="14" cy="13" r="12" fill="#eb001b"/><circle cx="26" cy="13" r="12" fill="#f79e1b" fill-opacity=".9"/></svg><span class="cc-b cc-b-amex">AMEX</span></span>
            </div>
            <div class="cc-num mt-3 mb-2" id="cc-p-num">•••• •••• •••• ••••</div>
            <div class="d-flex justify-content-between align-items-end small text-uppercase gap-2">
              <span id="cc-p-name" class="cc-f text-truncate" data-for="cc-name">Your name</span>
              <span class="d-flex gap-3"><span id="cc-p-exp" class="cc-f" data-for="cc-exp">MM/YY</span><span class="cc-f" data-for="cc-cvc">CVC <span id="cc-p-cvc">•••</span></span></span>
            </div>
          </div>
          <h3 class="h5 fw-bold mb-3">Order summary</h3>
          <dl class="mb-3 cc-receipt">
            <div class="d-flex justify-content-between align-items-center mb-2"><dt class="fw-normal d-flex align-items-center gap-2"><span class="badge rounded-pill text-bg-primary">Pro</span>Pro plan, monthly</dt><dd class="mb-0">$49.00</dd></div>
            <div class="d-flex justify-content-between mb-2"><dt class="fw-normal wdw-muted">Extra seat</dt><dd class="mb-0">$8.00</dd></div>
            <div class="d-flex justify-content-between mb-2 d-none" id="cc-disc-row"><dt class="fw-normal text-success">Promo SAVE10</dt><dd class="mb-0 text-success" id="cc-disc">-$5.70</dd></div>
            <div class="d-flex justify-content-between mb-2"><dt class="fw-normal wdw-muted">Tax (8%)</dt><dd class="mb-0" id="cc-tax">$4.56</dd></div>
            <div class="d-flex justify-content-between align-items-baseline border-top pt-3 mt-3"><dt class="fw-semibold">Total</dt><dd class="mb-0 fs-3 fw-bold text-body-emphasis" id="cc-total">$61.56</dd></div>
          </dl>
          <label for="cc-promo" class="visually-hidden">Promo code</label>
          <div class="input-group mb-1">
            <input class="form-control" id="cc-promo" placeholder="Promo code (try SAVE10)" autocomplete="off">
            <button class="btn btn-outline-primary" type="button" id="cc-apply">Apply</button>
          </div>
          <div class="small mb-3" id="cc-promo-msg" role="status" aria-live="polite"> </div>
          <button type="submit" class="btn btn-primary rounded-pill w-100 " id="cc-pay">Pay $61.56</button>
          <div class="alert alert-success d-none mt-3 mb-0 py-2" id="cc-ok" role="status">Payment successful. A receipt is on its way.</div>
        </div>
      </div>
    </form>
  </div>
</section>

Built on Bootstrap 5.3.8 with plain JavaScript — no jQuery. Supports light and dark mode via data-bs-theme.

Free to use in personal and commercial projects under the MIT license.