Snippets Card

Bootstrap 5 Credit Card Payment Form

A card payment form with selectable payment methods, floating-label fields that format as you type, and an order summary above the pay button.

Bootstrap 5 No jQuery Jun 2020 2.7K views

<section class="wdw-stage">
  <div class="container" style="max-width: 460px">
    <form class="wdw-card p-4 cc-form" novalidate>
      <div class="d-flex align-items-center justify-content-between mb-3">
        <div>
          <span class="wdw-eyebrow">Secure checkout</span>
          <h2 class="wdw-heading h4 mb-0">Payment details</h2>
        </div>
        <span class="wdw-icon" aria-hidden="true">
          <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" 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>
        </span>
      </div>

      <fieldset class="mb-3">
        <legend class="form-label small fw-semibold">Payment method</legend>
        <div class="row g-2 cc-types">
          <div class="col-3"><input type="radio" class="btn-check" name="cc-type" id="cc-visa" value="visa" checked><label class="btn btn-outline-secondary w-100 px-0 fw-bold" for="cc-visa">VISA</label></div>
          <div class="col-3"><input type="radio" class="btn-check" name="cc-type" id="cc-mc" value="mc"><label class="btn btn-outline-secondary w-100 px-0 fw-bold" for="cc-mc" aria-label="Mastercard"><span class="cc-mc" aria-hidden="true"></span></label></div>
          <div class="col-3"><input type="radio" class="btn-check" name="cc-type" id="cc-amex" value="amex"><label class="btn btn-outline-secondary w-100 px-0 fw-bold" for="cc-amex">AMEX</label></div>
          <div class="col-3"><input type="radio" class="btn-check" name="cc-type" id="cc-pp" value="paypal"><label class="btn btn-outline-secondary w-100 px-0 fw-bold" for="cc-pp" aria-label="PayPal"><span>Pay<span class="text-primary">Pal</span></span></label></div>
        </div>
      </fieldset>

      <div class="form-floating mb-3">
        <input type="text" class="form-control" id="cc-name" placeholder="Name on card" autocomplete="cc-name" required>
        <label for="cc-name">Name on card</label>
      </div>
      <div class="form-floating mb-3">
        <input type="text" class="form-control" id="cc-number" placeholder="Card number" inputmode="numeric" autocomplete="cc-number" maxlength="19" pattern="[0-9 ]{13,19}" required>
        <label for="cc-number">Card number</label>
      </div>
      <div class="row g-3 mb-3">
        <div class="col-6"><div class="form-floating">
          <input type="text" class="form-control" id="cc-exp" placeholder="MM/YY" inputmode="numeric" autocomplete="cc-exp" maxlength="5" pattern="(0[1-9]|1[0-2])/[0-9]{2}" required>
          <label for="cc-exp">Expiry (MM/YY)</label></div></div>
        <div class="col-6"><div class="form-floating">
          <input type="text" class="form-control" id="cc-cvv" placeholder="CVV" inputmode="numeric" autocomplete="cc-csc" maxlength="4" pattern="[0-9]{3,4}" required>
          <label for="cc-cvv">CVV</label></div></div>
      </div>

      <dl class="mb-0 pb-3 mb-3 border-bottom small">
        <div class="d-flex justify-content-between mb-1"><dt class="fw-normal wdw-muted">Subtotal</dt><dd class="mb-0 fw-semibold">$3,000.00</dd></div>
        <div class="d-flex justify-content-between mb-1"><dt class="fw-normal wdw-muted">Shipping</dt><dd class="mb-0 fw-semibold">$20.00</dd></div>
        <div class="d-flex justify-content-between"><dt class="fw-bold">Total (incl. taxes)</dt><dd class="mb-0 fw-bold">$3,020.00</dd></div>
      </dl>
      <button type="submit" class="btn btn-primary btn-lg rounded-pill w-100 justify-content-between px-4">
        <span>Pay $3,020.00</span>
        <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12h14M13 6l6 6-6 6"/></svg>
      </button>
      <p class="text-center small wdw-muted mt-3 mb-0" role="status" aria-live="polite" id="cc-status">Payments are encrypted end to end.</p>
    </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.