Bootstrap 5 Form Validation Example

Ruth Jul 09, 2026

Bootstrap, the popular CSS framework, has always been a go-to for developers seeking a quick and responsive layout. With the release of Bootstrap 5, form validation has become even more robust and intuitive. Let's explore how to implement Bootstrap 5 form validation with an example.

HTML Form Validation with Bootstrap
HTML Form Validation with Bootstrap

Before diving into the code, it's essential to understand that Bootstrap 5 uses HTML5's native form validation features. This means that basic form validation, like required fields and pattern checks, is handled by the browser. Bootstrap 5 enhances this by providing custom styles and additional functionality.

Bootstrap Forms
Bootstrap Forms

Setting Up Bootstrap 5 Form Validation

To start using Bootstrap 5 form validation, you'll first need to include the Bootstrap 5 CSS and JavaScript files in your project. You can do this via a CDN or by downloading the files directly.

Free 22+ HTML5 Signup & Registration Forms - HTML, CSS
Free 22+ HTML5 Signup & Registration Forms - HTML, CSS

Once Bootstrap 5 is included, you can begin styling your forms. Bootstrap 5 uses the following classes to style form elements: .form-control for inputs, .form-select for select elements, and .form-check for checkboxes and radio buttons.

Basic Form Validation

Bootstrap 3 Contact form with Validation
Bootstrap 3 Contact form with Validation

For basic form validation, you can use the required attribute in your HTML. This will ensure that the field must be filled out before the user can submit the form. Here's an example:

<input type="text" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" required>

Feedback Icons

the sign up form for an email account is shown in red and green colors,
the sign up form for an email account is shown in red and green colors,

Bootstrap 5 introduces feedback icons that appear next to form inputs. These icons provide visual feedback to the user, indicating whether the input is valid or invalid. To use these icons, add the .is-valid or .is-invalid classes to your input fields.

Here's an example of a valid and invalid input:

<input type="text" class="form-control is-valid"> and <input type="text" class="form-control is-invalid">

W3Schools.com
W3Schools.com

Custom Validation

Sometimes, you'll need to perform custom validation that goes beyond what HTML5 can offer. For these cases, Bootstrap 5 provides a JavaScript plugin that can be used to customize the validation behavior.

Bootstrap 5 popup form
Bootstrap 5 popup form
Bootstrap Fieldset Legend: How To + Examples + Template | AZMIND
Bootstrap Fieldset Legend: How To + Examples + Template | AZMIND
Form validation best practices
Form validation best practices
BOOTSTRAP INPUT FORM (2020) | HOW TO MAKE FORM IN BOOTSTRAP
BOOTSTRAP INPUT FORM (2020) | HOW TO MAKE FORM IN BOOTSTRAP
Forms Need Validation
Forms Need Validation
The Ultimate UX Design of Form Validation
The Ultimate UX Design of Form Validation
How to use real-time validation in your forms
How to use real-time validation in your forms
Server Side Form Validation Using Regular Expressions Using PHP
Server Side Form Validation Using Regular Expressions Using PHP
Login Form Template Bootstrap 5
Login Form Template Bootstrap 5
form
form
15 Best Lead Generation Form Examples to Convert More
15 Best Lead Generation Form Examples to Convert More
a paper with some writing on it and an image of a woman's name
a paper with some writing on it and an image of a woman's name
Hello Form – PHP Working Ajax Contact Form with Validation
Hello Form – PHP Working Ajax Contact Form with Validation
HTML5 Form Validation With the “pattern” Attribute | Envato Tuts+
HTML5 Form Validation With the “pattern” Attribute | Envato Tuts+
form for when your bored!🙉🐛
form for when your bored!🙉🐛
Form-Field Validation: The Errors-Only Approach — Smashing Magazine
Form-Field Validation: The Errors-Only Approach — Smashing Magazine
do my long form Plssss
do my long form Plssss
Complete Beginner CSS Master Notes
Complete Beginner CSS Master Notes
a form for an application to fill out the forms in which they are not available
a form for an application to fill out the forms in which they are not available
Inline Validation in Web Forms
Inline Validation in Web Forms

The plugin provides several methods for custom validation, including validate() to manually trigger validation, resetForm() to reset the form, and destroy() to remove the validation functionality.

Using the validate() Method

The validate() method can be used to manually trigger the validation of a form. This can be useful if you want to validate the form when a specific button is clicked, rather than on form submission.

Here's an example of using the validate() method:

const form = document.querySelector('form'); form.addEventListener('click', function (event) { if (event.target.classList.contains('validate')) { event.preventDefault(); form.validate(); } });

Using the resetForm() Method

The resetForm() method can be used to reset the form, clearing any validation messages and resetting the form fields.

Here's an example of using the resetForm() method:

const form = document.querySelector('form'); form.addEventListener('click', function (event) { if (event.target.classList.contains('reset')) { event.preventDefault(); form.resetForm(); } });

With these examples, you should now have a solid understanding of how to implement Bootstrap 5 form validation. Whether you're using basic HTML5 validation or custom JavaScript validation, Bootstrap 5 provides the tools you need to create intuitive and user-friendly forms. Happy coding!