Snippets Card

Bootstrap 5 Credit Card Payment Form with Live Preview

A credit card payment form with a live card preview, floating labels, input formatting and inline validation alerts.

Bootstrap 5 No jQuery Nov 2020 2.2K views

<section class="wdw-stage">
  <div class="container" style="max-width:960px">
    <div class="row g-4 align-items-center">
      <div class="col-lg-5">
        <span class="wdw-eyebrow">Secure checkout</span>
        <h2 class="wdw-heading display-6 mt-1 mb-3">Pay by card</h2>
        <p class="wdw-muted mb-4">Your details are encrypted. Watch the card update as you type.</p>
        <div class="wdw-aurora pay-card rounded-4 p-4 d-flex flex-column justify-content-between" aria-hidden="true">
          <div class="d-flex justify-content-between align-items-center">
            <svg width="38" height="28" viewBox="0 0 38 28" fill="none"><rect x=".75" y=".75" width="36.5" height="26.5" rx="5" stroke="#fff" stroke-opacity=".6" stroke-width="1.5"/><path d="M1 10h36M12 10v17.5M26 10v17.5M1 19h36" stroke="#fff" stroke-opacity=".6" stroke-width="1.2"/></svg>
            <span class="small fw-semibold opacity-75">Credit</span>
          </div>
          <div class="pay-number fs-4 fw-semibold" id="pvNumber">•••• •••• •••• ••••</div>
          <div class="d-flex justify-content-between small">
            <div><div class="opacity-50 text-uppercase pay-lbl">Card holder</div><div class="fw-semibold" id="pvName">Your name</div></div>
            <div class="text-end"><div class="opacity-50 text-uppercase pay-lbl">Expires</div><div class="fw-semibold" id="pvExp">MM/YY</div></div>
          </div>
        </div>
      </div>
      <div class="col-lg-7">
        <form class="wdw-card p-4 p-md-5" id="payForm" novalidate>
          <div class="alert alert-danger d-flex align-items-center justify-content-between py-2 mb-4" id="payAlert" role="alert">
            <span id="payAlertMsg">CVC code is required.</span>
            <button type="button" class="btn-close" aria-label="Dismiss" data-pay-dismiss></button>
          </div>
          <div class="form-floating mb-3">
            <input type="text" class="form-control" id="payName" placeholder="Name" autocomplete="cc-name" required>
            <label for="payName">Card holder name</label>
          </div>
          <div class="form-floating mb-3">
            <input type="text" class="form-control" id="payNumber" placeholder="Number" inputmode="numeric" autocomplete="cc-number" maxlength="19" required>
            <label for="payNumber">Card number</label>
          </div>
          <div class="row g-3 mb-4">
            <div class="col-6">
              <div class="form-floating">
                <input type="text" class="form-control" id="payExp" placeholder="MM/YY" inputmode="numeric" autocomplete="cc-exp" maxlength="5" required>
                <label for="payExp">Expiry (MM/YY)</label>
              </div>
            </div>
            <div class="col-6">
              <div class="form-floating">
                <input type="text" class="form-control" id="payCvc" placeholder="CVC" inputmode="numeric" autocomplete="cc-csc" maxlength="4" required>
                <label for="payCvc">CVC</label>
              </div>
            </div>
          </div>
          <button type="submit" class="btn btn-primary rounded-pill w-100">
            <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="4" y="11" width="16" height="10" rx="2"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg>
            Pay $149.00
          </button>
          <p class="text-center wdw-muted small mt-3 mb-0">Payments are processed securely. We never store your card.</p>
        </form>
      </div>
    </div>
  </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.