- No data uploaded
- Instant results
Bootstrap 5 Razorpay Checkout Form for Vanilla JS — Glassmorphism
A production-ready glassmorphism razorpay checkout form: a two-column checkout with an order summary (subtotal, GST, total in INR), contact fields, a UPI / card / netbanking selector and a pay button that opens Razorpay Checkout. Pick your brand color, toggle dark mode and corner radius — the live preview and the Vanilla JS code update instantly in your browser.
Live component editor
<!-- Requires Bootstrap 5.3 CSS + theme.css:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="theme.css"> -->
<div class="w-100 mw-4xl row row-cols-1 row-cols-md-2 g-4">
<div class="col">
<div class="h-100 p-4 glass shadow-lg rounded-3">
<h2 class="fs-5 fw-semibold text-body-emphasis">Order summary</h2>
<div class="mt-3 d-flex align-items-start justify-content-between gap-3">
<div>
<p class="fw-medium text-body-emphasis">Pro plan · annual</p>
<p class="small text-body-secondary">Billed once, renews yearly</p>
</div>
<p class="fw-medium text-body-emphasis">₹8,474</p>
</div>
<div class="mt-4 pt-3 d-flex flex-column gap-2 small border-top">
<div class="d-flex justify-content-between text-body-secondary"><span>Subtotal</span><span>₹8,474</span></div>
<div class="d-flex justify-content-between text-body-secondary"><span>GST (18%)</span><span>₹1,525</span></div>
<div class="d-flex justify-content-between fw-semibold text-body-emphasis"><span>Total</span><span>₹9,999</span></div>
</div>
<p class="mt-4 small text-body-secondary">Secured by Razorpay · PCI DSS compliant</p>
</div>
</div>
<div class="col">
<form class="h-100 p-4 d-flex flex-column gap-3 glass shadow-lg rounded-3">
<h2 class="fs-5 fw-semibold text-body-emphasis">Payment details</h2>
<div>
<label for="rp-email" class="form-label small fw-medium">Email</label>
<input id="rp-email" type="email" autocomplete="email" placeholder="you@company.com" class="form-control rounded-2" required>
</div>
<div>
<label for="rp-phone" class="form-label small fw-medium">Mobile number</label>
<input id="rp-phone" type="tel" inputmode="tel" autocomplete="tel" placeholder="+91 98765 43210" class="form-control rounded-2" required>
</div>
<div>
<p class="form-label small fw-medium">Payment method</p>
<div class="d-flex flex-wrap gap-2" role="group" aria-label="Payment method">
<button type="button" class="btn btn-outline-secondary choice fw-semibold rounded-2" data-set="method:upi" data-pressed="method:upi" aria-pressed="true">UPI</button>
<button type="button" class="btn btn-outline-secondary choice fw-semibold rounded-2" data-set="method:card" data-pressed="method:card" aria-pressed="false">Card</button>
<button type="button" class="btn btn-outline-secondary choice fw-semibold rounded-2" data-set="method:netbanking" data-pressed="method:netbanking" aria-pressed="false">Netbanking</button>
</div>
<p class="mt-2 small text-body-secondary" data-when="method:upi">Pay with any UPI app — GPay, PhonePe, Paytm or BHIM.</p>
<p class="mt-2 small text-body-secondary" data-when="method:card" hidden>Visa, Mastercard, RuPay and Amex credit or debit cards.</p>
<p class="mt-2 small text-body-secondary" data-when="method:netbanking" hidden>All major Indian banks supported.</p>
</div>
<button type="button" class="btn btn-brand fw-semibold rounded-2 w-100" data-call="payWithRazorpay">Pay ₹9,999</button>
</form>
</div>
</div>
<script>
(() => {
// Razorpay Standard Checkout — https://razorpay.com/docs/payments/payment-gateway/web-integration/standard/
const RAZORPAY_KEY_ID = 'rzp_test_YOUR_KEY_ID'; // public key only — the secret stays on your server
function loadRazorpay() {
if (window.Razorpay) return Promise.resolve();
return new Promise((resolve, reject) => {
const s = document.createElement('script');
s.src = 'https://checkout.razorpay.com/v1/checkout.js';
s.onload = resolve;
s.onerror = () => reject(new Error('Razorpay SDK failed to load'));
document.head.appendChild(s);
});
}
async function payWithRazorpay() {
await loadRazorpay();
// 1) Server creates the order (amount in paise) — never trust a client-side amount.
const order = await fetch('/api/razorpay/order', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ plan: 'pro-annual' })
}).then((r) => r.json());
// 2) Open Checkout for that order.
const rzp = new window.Razorpay({
key: RAZORPAY_KEY_ID,
order_id: order.id,
amount: order.amount,
currency: order.currency,
name: 'Acme Inc.',
description: 'Pro plan — annual',
prefill: {
email: document.getElementById('rp-email')?.value,
contact: document.getElementById('rp-phone')?.value
},
theme: { color: '#4f46e5' },
// 3) Server verifies razorpay_signature before fulfilling.
handler: (res) =>
fetch('/api/razorpay/verify', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(res) })
});
rzp.on('payment.failed', (res) => console.error(res.error));
rzp.open();
}
const state = { method: "upi" };
const actions = { payWithRazorpay };
const pair = (s) => s.split(':');
const sync = () => {
document.querySelectorAll('[data-show]').forEach((el) => (el.hidden = !state[el.dataset.show]));
document.querySelectorAll('[data-hide]').forEach((el) => (el.hidden = !!state[el.dataset.hide]));
document.querySelectorAll('[data-when]').forEach((el) => { const [k, v] = pair(el.dataset.when); el.hidden = state[k] !== v; });
document.querySelectorAll('[data-pressed]').forEach((el) => { const [k, v] = pair(el.dataset.pressed); el.setAttribute('aria-pressed', String(state[k] === v)); });
document.querySelectorAll('[data-expanded]').forEach((el) => el.setAttribute('aria-expanded', String(!!state[el.dataset.expanded])));
};
document.addEventListener('click', (e) => {
const t = e.target.closest('[data-toggle],[data-open],[data-close],[data-set],[data-call]');
if (!t) return;
const { toggle, open, close, set, call } = t.dataset;
if (call) actions[call]?.(e);
if (toggle) state[toggle] = !state[toggle];
if (open) state[open] = true;
if (close) state[close] = false;
if (set) { const [k, v] = pair(set); state[k] = v; }
sync();
});
sync();
})();
</script>
/* theme.css — brand color #4f46e5 for Bootstrap 5.3 */
:root { --brand: #4f46e5; --brand-hover: #433cc3; --brand-rgb: 79, 70, 229; --brand-contrast: #ffffff; }
.btn-brand {
--bs-btn-color: var(--brand-contrast); --bs-btn-bg: var(--brand); --bs-btn-border-color: var(--brand);
--bs-btn-hover-color: var(--brand-contrast); --bs-btn-hover-bg: var(--brand-hover); --bs-btn-hover-border-color: var(--brand-hover);
--bs-btn-active-color: var(--brand-contrast); --bs-btn-active-bg: var(--brand-hover); --bs-btn-active-border-color: var(--brand-hover);
--bs-btn-focus-shadow-rgb: var(--brand-rgb);
}
.text-brand { color: var(--brand) !important; }
.border-brand { border: 2px solid var(--brand) !important; }
.bg-brand-subtle { background-color: rgba(var(--brand-rgb), .12) !important; }
.form-control:focus, .form-check-input:focus { border-color: var(--brand); box-shadow: 0 0 0 .25rem rgba(var(--brand-rgb), .25); }
.form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }
.overlay { background: rgba(15, 23, 42, .5); backdrop-filter: blur(4px); z-index: 1050; }
.choice[aria-pressed="true"] { border-color: var(--brand) !important; color: var(--brand) !important; box-shadow: 0 0 0 .2rem rgba(var(--brand-rgb), .2); }
.mw-sm { max-width: 24rem; } .mw-md { max-width: 28rem; } .mw-lg { max-width: 32rem; } .mw-xl { max-width: 36rem; }
.mw-2xl { max-width: 42rem; } .mw-4xl { max-width: 56rem; } .mw-6xl { max-width: 72rem; }
.glass { background: rgba(255, 255, 255, .6) !important; backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px); border: 1px solid rgba(255, 255, 255, .6) !important; }
[data-bs-theme="dark"] .glass, [data-bs-theme="dark"].glass { background: rgba(255, 255, 255, .05) !important; border-color: rgba(255, 255, 255, .1) !important; }
.bg-glass-page { background: linear-gradient(135deg, #e0e7ff, #f0f9ff, #ffe4e6); }
[data-bs-theme="dark"] .bg-glass-page, [data-bs-theme="dark"].bg-glass-page { background: linear-gradient(135deg, #020617, #1e1b4b, #0f172a); }
More Bootstrap components for Vanilla JS
All components →- Currency Pricing Table A dynamic pricing section that detects the visitor’s currency, shows purchasing-power-adjusted regional prices and lets users switch between USD, EUR, GBP, INR and JPY
- Pricing Table A three-tier pricing section with a monthly/yearly billing toggle, a highlighted “most popular” plan and feature checklists
- Signup Form A registration card with name, email and password fields, a password hint, a terms-of-service checkbox and a primary call to action
- Cookie Consent Banner A GDPR-style cookie banner with equally prominent “Accept all” and “Reject all”, granular analytics/marketing toggles (off by default), stored consent and Google Consent Mode v2 signals
- FAQ Accordion A frequently-asked-questions section with four expandable items, each toggled by a button that exposes its state via aria-expanded
- Login Modal A centered sign-in dialog with email and password fields, “remember me”, a forgot-password link and a social sign-in button
- Navbar A responsive top navigation bar with a logo, primary links, a sign-in/CTA pair on desktop and a collapsible hamburger menu on mobile
- Hero Section A landing-page hero with an announcement badge, a large headline, supporting copy, primary and secondary calls to action and a row of social-proof stats
Install Bootstrap 5 for Vanilla JS
Include Bootstrap 5.3 from the CDN (or npm install bootstrap) and the generated theme.css:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="theme.css">Use the razorpay checkout form in Vanilla JS
Paste the markup where the component should appear. The small inline <script> wires up the interactive state with one delegated click listener — no framework needed.
Connecting the form to Razorpay
- Create an order on your server with the Orders API using your
key_secretand return{ id, amount, currency }from/api/razorpay/order. - Replace
rzp_test_YOUR_KEY_IDwith your public key_id (test keys first). - In
/api/razorpay/verify, computeHMAC_SHA256(order_id + "|" + payment_id, key_secret)and compare it withrazorpay_signaturebefore marking the order paid. Also handle thepayment.capturedwebhook as the source of truth.
The preview never contacts Razorpay — clicking “Pay” there only shows where checkout would open.
Accessibility & customization
Payment methods are toggle buttons with aria-pressed, totals are real text (not images), the phone field uses inputmode="tel" and autocomplete tokens, and the pay button states the exact amount.
Every color, radius and dark-mode choice is baked into plain Bootstrap classes plus a tiny CSS-variable theme file, so the copied code has no runtime dependency on this site. The glass style relies on backdrop-filter, supported in all current browsers; place it over a colorful background for the best effect.
Compatibility
| Item | Details |
|---|---|
| CSS framework | Bootstrap 5.3+ (CSS only) |
| Library | Plain HTML + optional vanilla JS |
| Interactive state | method |
| Dark mode | Yes — toggle in the editor |
| Style | Glassmorphism (backdrop blur) |