Bootstrap 5 Modal Example

Ruth Jul 09, 2026

Bootstrap, the popular CSS framework, has been a game-changer for web developers, offering a plethora of pre-built components to streamline the development process. One of its most useful features is the modal, a pop-up window that appears on top of the current page, providing additional content or functionality without disrupting the user's flow. With the release of Bootstrap 5, the modal component has been updated with new features and improved responsiveness. Let's dive into an example of a Bootstrap 5 modal to see how it works.

Bootstrap 5 Modal Form
Bootstrap 5 Modal Form

Before we start, ensure you have included the Bootstrap 5 CSS and JavaScript files in your project. You can either download them or use the CDN links provided by the Bootstrap website. For this example, we'll use the CDN links:

Bootstrap 5 popup form
Bootstrap 5 popup form

```html ```

Setting Up the Bootstrap 5 Modal

To create a modal in Bootstrap 5, you'll need to include the modal markup in your HTML and use the appropriate data attributes to trigger it. Let's start by creating a simple modal with a title and some text content.

Bootstrap Modal Guide, Examples and Tutorials
Bootstrap Modal Guide, Examples and Tutorials

First, include the following HTML structure in your page where you want the modal to appear:

```html

```

Understanding the Modal Structure

The modal is composed of several parts: the button that triggers it, the modal backdrop, and the modal dialog itself. The dialog contains the header, body, and footer sections. The header includes the modal title and a close button, while the footer typically contains buttons for dismissing or confirming the modal.

The `data-bs-toggle` and `data-bs-target` attributes on the trigger button are used to specify that the button should toggle the modal with the ID `exampleModal`. The `modal` class on the dialog and the `fade` class on the backdrop are used to apply the default Bootstrap modal styling and animation.

Modals · Bootstrap v5.3
Modals · Bootstrap v5.3

Adding Content to the Modal Body

Now that we have the basic modal structure set up, let's add some content to the modal body. For this example, we'll include a form with some input fields and a text area:

```html

```

Customizing the Modal

the food app is being displayed on an iphone's screen, and it appears to be getting started with feedspring
the food app is being displayed on an iphone's screen, and it appears to be getting started with feedspring

Bootstrap 5 allows you to customize the modal's appearance and behavior using various options and data attributes. Let's explore some of these customization options.

First, you can change the modal size using the `size` option. Add the `data-bs-toggle` and `data-bs-target` attributes to your trigger button, and include the desired size class (`modal-sm`, `modal-lg`, or `modal-xl`) on the modal dialog:

37 Free Bootstrap Form Templates You Can Try Right Now
37 Free Bootstrap Form Templates You Can Try Right Now
Building a customizable Modal Component with React
Building a customizable Modal Component with React
Prompt Modal Code, Modern Task Management Ui, Delete Modal Ui, Prompt Modal Design, Task Management Ui Kit, Confirmation Modal Design, Confirmation Modal Ui, Task Management Interface Screenshot, Task Management App Ui Design
Prompt Modal Code, Modern Task Management Ui, Delete Modal Ui, Prompt Modal Design, Task Management Ui Kit, Confirmation Modal Design, Confirmation Modal Ui, Task Management Interface Screenshot, Task Management App Ui Design
Bootstrap Tutorials: The Best of Azmind | AZMIND
Bootstrap Tutorials: The Best of Azmind | AZMIND
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
Working with Bootstrap Plugin: Modal Window
Working with Bootstrap Plugin: Modal Window
Upgrade To Premium Modal | Free Webflow Component
Upgrade To Premium Modal | Free Webflow Component
30 Best Free Bootstrap Wizards & Forms 2026 - Colorlib
30 Best Free Bootstrap Wizards & Forms 2026 - Colorlib
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
Create Step By Step Modal with jQuery and Bootstrap
Create Step By Step Modal with jQuery and Bootstrap
Responsive Modal Design
Responsive Modal Design
Image Upload Modal | Free Webflow Component
Image Upload Modal | Free Webflow Component
Product Gallery Code | Bootstrap 5.3 snippet for building an eCommerce gallery
Product Gallery Code | Bootstrap 5.3 snippet for building an eCommerce gallery
Profile Modal | Free Webflow Component
Profile Modal | Free Webflow Component
an image of a computer screen with the words, what countries would you like to live in?
an image of a computer screen with the words, what countries would you like to live in?
the payment information page is shown in this screenshote, and it appears to be filled
the payment information page is shown in this screenshote, and it appears to be filled
Design a Reusable System Modal
Design a Reusable System Modal
Monty Hayton
Monty Hayton
Simple Login Modal | Free Webflow Component
Simple Login Modal | Free Webflow Component
Dare Adekoya
Dare Adekoya

```html

```

Adding a Modal Backdrop

By default, the modal backdrop is displayed when the modal is shown. However, you can remove the backdrop by adding the `data-bs-backdrop="false"` attribute to the trigger button:

```html ```

Making the Modal Scrollable

If your modal content is too large to fit within the modal dialog, you can make the modal scrollable by adding the `modal-dialog-scrollable` class to the dialog:

```html

```

With these customization options, you can create Bootstrap 5 modals tailored to your specific needs. Whether you're displaying additional information, collecting user input, or providing a way to confirm an action, modals are an essential tool for enhancing the user experience in your web applications.

As you continue to explore the capabilities of Bootstrap 5, remember that the official documentation is an invaluable resource. It provides detailed explanations of each component, along with code examples and best practices. By leveraging the power of Bootstrap 5 and its extensive documentation, you'll be well on your way to creating responsive, mobile-first websites with ease.

So, go ahead and start incorporating Bootstrap 5 modals into your projects. With a little creativity and some customization, you'll be able to create engaging and intuitive user experiences that set your web applications apart from the competition.