Bootstrap 5 Modal Tutorial: Master Modals in 5 Steps

Ruth Jul 09, 2026

Bootstrap, the popular CSS framework, has just rolled out its fifth version, bringing with it a host of new features and improvements. One of the most notable additions is the revamped modal component. Modals are essential for creating interactive and engaging user experiences, and with Bootstrap 5, they've become even more powerful and intuitive. Let's dive into a comprehensive tutorial on how to use and customize Bootstrap 5 modals.

Bootstrap Tutorial | Bootstrap Notes | Bootstrap 5
Bootstrap Tutorial | Bootstrap Notes | Bootstrap 5

Before we get started, ensure you have the latest version of Bootstrap 5 installed. You can include it in your project using the official CDN or download and host the files locally. For this tutorial, we'll use the CDN version. Add the following lines to the section of your HTML file:

Bootstrap Tutorial | Bootstrap Notes | Bootstrap 5
Bootstrap Tutorial | Bootstrap Notes | Bootstrap 5

<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>

Setting Up Your First Bootstrap 5 Modal

Now that we have Bootstrap 5 set up, let's create our first modal. Modals in Bootstrap 5 are built using a combination of HTML, CSS, and JavaScript. The basic structure consists of a modal dialog and a trigger element, such as a button.

Bootstrap 5 Modal Form
Bootstrap 5 Modal Form

Here's a simple example of a Bootstrap 5 modal:

<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#myModal">Launch demo modal</button>

<div class="modal fade" id="myModal" tabindex="-1" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="myModalLabel">Modal title</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

Understanding the Modal Structure

Bootstrap 5 popup form
Bootstrap 5 popup form

The modal is composed of several elements:

  • Button trigger: The button that opens the modal when clicked.
  • Modal dialog: The main container of the modal, with the class modal fade.
  • Modal header: The top section of the modal, containing the title and close button.
  • Modal body: The main content area of the modal.
  • Modal footer: The bottom section of the modal, typically containing buttons for closing or confirming actions.

Customizing Modal Appearance

HTML Form Validation with Bootstrap
HTML Form Validation with Bootstrap

Bootstrap 5 modals come with a variety of customization options. You can change the size, color scheme, and more. Let's explore a few customization options:

  • Sizes: Add the modal-dialog modal-{size} classes to change the modal size. Valid sizes are sm, md, lg, and xl.
  • Color schemes: Use the modal-{color} classes to change the modal's color scheme. Valid colors are primary, secondary, success, danger, warning, and info.
  • Fullscreen: Add the modal-fullscreen class to make the modal fullscreen on mobile devices.

Interactive Modals with JavaScript

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

While Bootstrap 5 modals are interactive out of the box, you can enhance their functionality using JavaScript. For example, you can show or hide modals programmatically, or handle modal events like show and hide.

Here's an example of showing a modal programmatically:

How to Load Dynamic Content in Bootstrap Modal - CodexWorld
How to Load Dynamic Content in Bootstrap Modal - CodexWorld
GoSnippets — Free Code Snippets for Bootstrap, Tailwind, React, CSS, JavaScript & more
GoSnippets — Free Code Snippets for Bootstrap, Tailwind, React, CSS, JavaScript & more
Bootstrap Modal Popup Form Submit with Ajax & PHP - CodexWorld
Bootstrap Modal Popup Form Submit with Ajax & PHP - CodexWorld
Popup Share Modal UI Design using HTML CSS & JavaScript
Popup Share Modal UI Design using HTML CSS & JavaScript
Bootstrap 4 Modal Dialog Form-Wizard
Bootstrap 4 Modal Dialog Form-Wizard
Minimal Modal Popup HTML & CSS - Code Snippet
Minimal Modal Popup HTML & CSS - Code Snippet
Wizard
Wizard
#CSS Animations Tips and Tricks
#CSS Animations Tips and Tricks
Bootstrap Roadmap: Ultimate Guide for Beginners
Bootstrap Roadmap: Ultimate Guide for Beginners
Bootstrap Tutorials: The Best of Azmind | AZMIND
Bootstrap Tutorials: The Best of Azmind | AZMIND
Bootstrap Modal Vertically Centered
Bootstrap Modal Vertically Centered
BOOTSTRAP INPUT FORM (2020) | HOW TO MAKE FORM IN BOOTSTRAP
BOOTSTRAP INPUT FORM (2020) | HOW TO MAKE FORM IN BOOTSTRAP
Bootstrap 5 Classes List Cheat Sheet
Bootstrap 5 Classes List Cheat Sheet
Building a customizable Modal Component with React
Building a customizable Modal Component with React
HTML/CSS Bootstrap Simple Success Confirmation Popup
HTML/CSS Bootstrap Simple Success Confirmation Popup
Working with Bootstrap Plugin: Modal Window
Working with Bootstrap Plugin: Modal Window
How To Center a div Horizontally in Bootstrap 4
How To Center a div Horizontally in Bootstrap 4
How to Use Bootstrap in HTML | Web Development
How to Use Bootstrap in HTML | Web Development
the color chart for different colors and font options in an iphone phone screen, including blue, red, yellow, green, black, white
the color chart for different colors and font options in an iphone phone screen, including blue, red, yellow, green, black, white
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

const myModal = new bootstrap.Modal(document.getElementById('myModal'));
myModal.show();

Handling Modal Events

You can listen for modal events, such as show.bs.modal, shown.bs.modal, hide.bs.modal, and hidden.bs.modal, to perform actions when the modal is shown or hidden.

Here's an example of listening for the show.bs.modal event:

document.getElementById('myModal').addEventListener('show.bs.modal', event => {
  // Do something...
});

And that's a wrap! You now know how to create, customize, and enhance Bootstrap 5 modals. Whether you're using them for user authentication, displaying important messages, or creating interactive forms, modals are an essential tool in your web development kit. Happy coding!