Bootstrap 5 Modal Form Example

Ruth Jul 09, 2026

In the dynamic world of web development, Bootstrap has long been a go-to library for creating responsive and mobile-first websites. With the release of Bootstrap 5, developers have gained access to a plethora of new features and improvements, including a revamped modal component. In this article, we'll delve into an example of a Bootstrap 5 modal form, exploring its creation, customization, and functionality.

Bootstrap 5 Modal Form
Bootstrap 5 Modal Form

Before we dive into the modal form example, let's briefly recap what makes Bootstrap 5's modals stand out. They are now built using CSS Grid for improved layout flexibility, and they come with a new, cleaner design that aligns with the rest of the Bootstrap 5 components. Additionally, Bootstrap 5 modals are now fully responsive and can be easily customized to fit your project's unique needs.

the homepage for an employee portal with a rocket ship in the background and text that reads, apply as a employee
the homepage for an employee portal with a rocket ship in the background and text that reads, apply as a employee

Setting Up the Bootstrap 5 Modal Form

The first step in creating a Bootstrap 5 modal form is to include the necessary CSS and JavaScript files in your project. You can either download the Bootstrap 5 files or include them via a CDN. Once you've set up the Bootstrap environment, you're ready to start building your modal form.

Bootstrap 5 popup form
Bootstrap 5 popup form

To create a modal, you'll need to include three essential elements: the modal dialog, the modal content, and the modal body. The modal dialog serves as the backdrop, the modal content contains the title and close button, and the modal body houses the form itself.

Creating the Modal Dialog and Content

HTML Form Validation with Bootstrap
HTML Form Validation with Bootstrap

To create the modal dialog and content, you'll use the .modal and .modal-dialog classes, along with the .modal-content class for the modal content. Within the modal content, you'll place a .modal-header for the title and close button, and a .modal-body for the form.

Here's a basic example of how to structure your modal dialog and content:

<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
        <-- Form goes here -->
      </div>
    </div>
  </div>
</div>

Building the Modal Form

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

Now that you have the modal structure in place, it's time to build the form within the .modal-body section. For this example, let's create a simple contact form with fields for name, email, and message.

To create the form, use the <form> tag and include the necessary input fields and submit button. You can use Bootstrap's form classes, such as .form-control for inputs and .btn for the submit button, to style your form elements.

Here's an example of a simple contact form for your modal:

Bootstrap Fieldset Legend: How To + Examples + Template | AZMIND
Bootstrap Fieldset Legend: How To + Examples + Template | AZMIND

<form>
  <div class="mb-3">
    <label for="name" class="form-label">Name</label>
    <input type="text" class="form-control" id="name" placeholder="Enter your name">
  </div>
  <div class="mb-3">
    <label for="email" class="form-label">Email</label>
    <input type="email" class="form-control" id="email" placeholder="Enter your email">
  </div>
  <div class="mb-3">
    <label for="message" class="form-label">Message</label>
    <textarea class="form-control" id="message" rows="3"></textarea>
  </div>
  <button type="submit" class="btn btn-primary">Submit</button>
</form>

Customizing and Enhancing the Modal Form

With the basic modal form in place, you can now explore various customization options and enhancements to make your modal form truly unique and functional.

Free 22+ HTML5 Signup & Registration Forms - HTML, CSS
Free 22+ HTML5 Signup & Registration Forms - HTML, CSS
Bootstrap 4 Modal Dialog Form-Wizard
Bootstrap 4 Modal Dialog Form-Wizard
Wizard
Wizard
the form wizard screen is displayed on an ipad
the form wizard screen is displayed on an ipad
Login Form Template Bootstrap 5
Login Form Template Bootstrap 5
Multi-Step Form Modal
Multi-Step Form Modal
Upgrade To Premium Modal | Free Webflow Component
Upgrade To Premium Modal | Free Webflow Component
BOOTSTRAP INPUT FORM (2020) | HOW TO MAKE FORM IN BOOTSTRAP
BOOTSTRAP INPUT FORM (2020) | HOW TO MAKE FORM IN BOOTSTRAP
📝 Create Text Input Forms and Submit Button in HTML
📝 Create Text Input Forms and Submit Button in HTML
the website page is displayed with green and white colors, including an arrow pointing up to the
the website page is displayed with green and white colors, including an arrow pointing up to the
a screen shot of the timeline sharing page on an iphone, with two people looking at each other
a screen shot of the timeline sharing page on an iphone, with two people looking at each other
Bootstrap Tutorials: The Best of Azmind | AZMIND
Bootstrap Tutorials: The Best of Azmind | AZMIND
Create Step By Step Modal with jQuery and Bootstrap
Create Step By Step Modal with jQuery and Bootstrap
Simple Signup Modal | Free Webflow Component
Simple Signup Modal | Free Webflow Component
30 Best Free Bootstrap Wizards & Forms 2026 - Colorlib
30 Best Free Bootstrap Wizards & Forms 2026 - Colorlib
Profile Modal | Free Webflow Component
Profile Modal | Free Webflow Component
GitHub - themesberg/flowbite-admin-dashboard: Free and open-source admin dashboard template built with Tailwind CSS and Flowbite
GitHub - themesberg/flowbite-admin-dashboard: Free and open-source admin dashboard template built with Tailwind CSS and Flowbite
Login With Password | Webflow Components | Memberstack
Login With Password | Webflow Components | Memberstack
Simple Login Modal | Free Webflow Component
Simple Login Modal | Free Webflow Component
Login Modal | Free Webflow Component
Login Modal | Free Webflow Component

For instance, you can add form validation using JavaScript or a library like jQuery to ensure users fill out the form correctly before submission. You can also style the modal further using Bootstrap's utility classes or custom CSS to match your project's design.

Adding Form Validation

To add form validation, you can use JavaScript or jQuery to listen for the form submission event and check if the input fields are valid. If the form is invalid, you can display error messages or prevent the form from being submitted.

Here's an example of how to add basic form validation using jQuery:

$('#exampleModal form').submit(function(event) {
  event.preventDefault();
  var name = $('#name').val();
  var email = $('#email').val();
  var message = $('#message').val();

  if (name === '' || email === '' || message === '') {
    alert('Please fill out all fields.');
  } else {
    // Submit the form or perform other actions here
  }
});

Styling the Modal Form

To style your modal form, you can use Bootstrap's utility classes or custom CSS. For example, you can change the background color, font size, or add borders to the form elements to make them stand out.

Here's an example of how to add some basic styling to your modal form using custom CSS:

.modal-content {
  background-color: #f8f9fa;
}

.modal-body form {
  font-size: 16px;
}

.modal-body form input,
.modal-body form textarea {
  border: 1px solid #ced4da;
  border-radius: 0.25rem;
}

As you've seen in this article, creating a Bootstrap 5 modal form is a straightforward process that allows you to build responsive and functional forms with ease. By exploring the customization and enhancement options, you can create modal forms that perfectly fit your project's needs and stand out from the crowd.

Now that you've learned how to create and customize a Bootstrap 5 modal form, it's time to put your newfound knowledge into practice. Start building your own modal forms and experiment with different styles and functionalities to make your projects truly unique.