Bootstrap Payment Form Example

Ruth Jul 09, 2026

In the dynamic world of web development, creating responsive and functional forms is a crucial aspect. Bootstrap, a popular CSS framework, simplifies this process with its extensive collection of pre-built components. Today, we're going to explore a practical example of a Bootstrap payment form, a common requirement in e-commerce and subscription-based platforms.

37 Free Bootstrap Form Templates You Can Try Right Now
37 Free Bootstrap Form Templates You Can Try Right Now

Bootstrap's grid system and form classes make it easy to create clean, responsive forms. By leveraging these features, we can build a payment form that adapts to different screen sizes and provides a seamless user experience. Let's dive into the details.

the payment request form is shown in this screenshote, which shows that it has been
the payment request form is shown in this screenshote, which shows that it has been

Setting Up the Bootstrap Payment Form

To start, include the Bootstrap CSS and JavaScript files in your HTML document. You'll also need jQuery for some of Bootstrap's JavaScript plugins. Here's a basic setup:

Halaman Tidak Ditemukan - 404
Halaman Tidak Ditemukan - 404

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/css/bootstrap.min.css" rel="stylesheet"> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.6/dist/umd/popper.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/js/bootstrap.min.js"></script>

Creating the Form Structure

Flight Reservation Form Template | Jotform
Flight Reservation Form Template | Jotform

Bootstrap's grid system uses a series of containers, rows, and columns to layout and align content. For our payment form, we'll use a combination of these to create a clean, organized structure. Here's a basic example:

<div class="container"> <div class="row"> <div class="col-md-8 offset-md-2"> <form> <div class="mb-3"> <label for="cardNumber" class="form-label">Card Number</label> <input type="text" class="form-control" id="cardNumber" placeholder="1234 5678 9012 3456"> </div> <!-- More form fields here --> </form> </div> </div> </div>

Styling the Form Fields

Responsive Payment Form Page Design (HTML CSS Tutorial)
Responsive Payment Form Page Design (HTML CSS Tutorial)

Bootstrap's form classes provide built-in styles for various form elements. To make our payment form visually appealing, we can use these classes along with some custom CSS. Here's how you can style the card number field:

.form-control { font-size: 16px; padding: 10px; border: 1px solid #ced4da; border-radius: 4px; } .form-control:focus { border-color: #80bdff; box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25); }

Adding Functionality with JavaScript

Bootstrap Forms
Bootstrap Forms

While Bootstrap provides a lot of styling out of the box, we'll need to add some JavaScript to make our payment form functional. For example, we might want to validate the card number using the Luhn algorithm or format the card number as the user types.

Form Validation

a screenshot of a web page with an email address and payment information on it
a screenshot of a web page with an email address and payment information on it
Payment Website Design
Payment Website Design
an invoice form that is used for payment
an invoice form that is used for payment
A unique Credit card checkout page design. 🥳
A unique Credit card checkout page design. 🥳
Free Bill of Sale Form | Editable Printable Template
Free Bill of Sale Form | Editable Printable Template
an invoice form with the words pay stub on it
an invoice form with the words pay stub on it
Fillable Free Pay Stub PDF Template - PDF Templates | Jotform
Fillable Free Pay Stub PDF Template - PDF Templates | Jotform
an iphone screen showing the payment form for a bank account, which has been changed to pay
an iphone screen showing the payment form for a bank account, which has been changed to pay
a payment agreement is shown in this document
a payment agreement is shown in this document
an email form for paypaal with the message thank you for your order on it
an email form for paypaal with the message thank you for your order on it
the final demand letter for payment is shown in red and white, with an orange border around it
the final demand letter for payment is shown in red and white, with an orange border around it
Request UPI Payments Using Google Forms: Step-by-Step Guide | IT4nextgen
Request UPI Payments Using Google Forms: Step-by-Step Guide | IT4nextgen
a receipt form for bank details
a receipt form for bank details
Request Form tailwind css
Request Form tailwind css
a screenshot of the payout page for an app that allows users to check out their credit cards
a screenshot of the payout page for an app that allows users to check out their credit cards
an invoice form for a bank account
an invoice form for a bank account
Payment Flow UX: Selecting a Payment Method
Payment Flow UX: Selecting a Payment Method
the login page for wordpress with an arrow pointing up to the account information section
the login page for wordpress with an arrow pointing up to the account information section
Payslip Template | Free Word Templates
Payslip Template | Free Word Templates
a screenshot of the payment options page
a screenshot of the payment options page

Bootstrap includes form validation classes that provide helpful feedback to users. To use these, add the `is-invalid` class to inputs that fail validation, and use the `was-validated` class on the form to show validation feedback when the form is submitted. Here's an example:

<input type="text" class="form-control" id="cardNumber" placeholder="1234 5678 9012 3456" required> <div class="invalid-feedback">Please enter a valid card number</div>

Formatting the Card Number

To format the card number as the user types, we can use a JavaScript library like Cleave.js. This library allows us to apply masks to input fields, making it easy to format credit card numbers, phone numbers, and more. Here's how you can use it to format the card number:

<script src="https://cdn.jsdelivr.net/npm/@egjs/cleave@1.5.0/dist/cleave.min.js"></script> <script> new Cleave('#cardNumber', { creditCard: true, onCreditCardTypeChanged: function (type) { // Handle card type changes if needed } }); </script>

And there you have it! With these steps, you've created a responsive, functional Bootstrap payment form. This form provides a seamless user experience, adapts to different screen sizes, and includes helpful feedback for users. Happy coding!