Bootstrap: Check Password Match Instantly

Ruth Jul 09, 2026

In the realm of web development, ensuring a secure and seamless user experience is paramount. One crucial aspect of this is implementing a robust password check system, especially during user registration or password reset processes. Bootstrap, a popular front-end framework, offers a simple yet effective way to achieve this through its built-in validation features. Let's delve into how you can create a Bootstrap check password match functionality.

JavaScript Password Strength Checker
JavaScript Password Strength Checker

Before we dive into the implementation, let's understand the importance of password matching. A password match check ensures that the user has entered the same password in both the 'Password' and 'Confirm Password' fields. This simple yet powerful feature helps prevent typos and enhances user confidence, knowing their password has been entered correctly.

Best Free Bootstrap Login Forms » CSS Author
Best Free Bootstrap Login Forms » CSS Author

Setting Up the Bootstrap Password Check

To start, you'll need to include the Bootstrap CSS and JavaScript files in your project. If you're using a CDN, you can add the following lines in your HTML file:

Forget password flow
Forget password flow

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>

Creating the HTML Structure

a notebook with some writing on it and someone's handwritten notes attached to the cover
a notebook with some writing on it and someone's handwritten notes attached to the cover

First, create the HTML structure for your password fields. You'll need two password input fields and a div to display the validation message:

<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" name="password">
</div>
<div class="mb-3">
<label for="confirmPassword" class="form-label">Confirm Password</label>
<input type="password" class="form-control" id="confirmPassword" name="confirmPassword">
</div>
<div id="message" class="invalid-feedback"></div>

Adding Bootstrap Validation

a screen shot of the change password button
a screen shot of the change password button

Next, add the 'is-invalid' class to the password fields and use Bootstrap's 'show' and 'hide' methods to display the validation message:

<script>
const password = document.getElementById('password');
const confirmPassword = document.getElementById('confirmPassword');
const message = document.getElementById('message');
confirmPassword.addEventListener('input', function () {
if (password.value !== confirmPassword.value) {
message.textContent = 'Passwords do not match';
confirmPassword.classList.add('is-invalid');
} else {
message.textContent = '';
confirmPassword.classList.remove('is-invalid');
}
});
</script>

Implementing Real-Time Password Match Check

an iphone screen showing the change your facebook account to login or click on it
an iphone screen showing the change your facebook account to login or click on it

For a better user experience, you can implement real-time password matching. This means the validation message appears as soon as the user types in the 'Confirm Password' field:

To achieve this, add the 'event' parameter to the 'addEventListener' method and use the 'input' event to trigger the validation:

the facebook login screen is open and it appears to be blocked by someone else
the facebook login screen is open and it appears to be blocked by someone else
two screens with the words which u is better? and an image of a man's face
two screens with the words which u is better? and an image of a man's face
the login page for an email account
the login page for an email account
***
***
Forgot Password Step 2 | Free Webflow Component
Forgot Password Step 2 | Free Webflow Component
Responsive Login Form with Toggle Password Visibility (HTML CSS JavaScript)
Responsive Login Form with Toggle Password Visibility (HTML CSS JavaScript)
20 Printable Password Trackers For Free-Manage Your Passwords Hassle! - Bear & Dear
20 Printable Password Trackers For Free-Manage Your Passwords Hassle! - Bear & Dear
Password Organizer Worksheets - 12 Free PDF Printables | Printablee
Password Organizer Worksheets - 12 Free PDF Printables | Printablee
an image of a computer screen with text on it
an image of a computer screen with text on it
an image of a phone screen with the text enter your passcode
an image of a phone screen with the text enter your passcode
My Friends Still Use “123456” Passwords—Here’s How I Finally Got Them to Stop
My Friends Still Use “123456” Passwords—Here’s How I Finally Got Them to Stop
Password Show Hide Toggle JS - Code Snippet
Password Show Hide Toggle JS - Code Snippet
two screens showing the settings for facebook's accounts
two screens showing the settings for facebook's accounts
It Gets Worse: The Newest Sony Data Breach Exposes Thousands Of Passwords
It Gets Worse: The Newest Sony Data Breach Exposes Thousands Of Passwords
Invest Forgot Password | Free Webflow Component
Invest Forgot Password | Free Webflow Component
the words are in different languages and there is no image to describe on this page
the words are in different languages and there is no image to describe on this page
How To Make Login Form With Password Toggle In HTML CSS JS
How To Make Login Form With Password Toggle In HTML CSS JS
How to use Google's new Password Checkup tool
How to use Google's new Password Checkup tool
Passwords Not Being Hidden/Masked on iPhone: 4 Ways To Fix
Passwords Not Being Hidden/Masked on iPhone: 4 Ways To Fix
Downloads Reset Password Form for Webflow
Downloads Reset Password Form for Webflow

<script>
// ... (previous code)
confirmPassword.addEventListener('input', function (event) {
if (password.value !== confirmPassword.value) {
message.textContent = 'Passwords do not match';
confirmPassword.classList.add('is-invalid');
event.target.classList.add('is-invalid');
} else {
message.textContent = '';
confirmPassword.classList.remove('is-invalid');
event.target.classList.remove('is-invalid');
}
});
</script>

Styling the Validation Message

Finally, you can style the validation message to make it more visible and user-friendly. You can use Bootstrap's utility classes or custom CSS:

<style>
#message {
display: none;
color: red;
}
</style>

And there you have it! A simple yet effective Bootstrap check password match functionality. This not only enhances the user experience but also ensures that users enter their passwords correctly, reducing the likelihood of forgotten passwords and lockouts.