AI Bootstrap Builder Logo
AI Bootstrap Builder Questions & Answers

How can I create a modal in Bootstrap 5? Pending Review

Asked on Sep 16, 2025

1 Answer

To create a modal in Bootstrap 5, you need to use the modal component which includes a combination of HTML structure and JavaScript functionality. Here's a basic example of how to set up a modal.

<!-- BEGIN COPY / PASTE -->
        <!-- Button trigger modal -->
        <button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal">
          Launch demo modal
        </button>

        <!-- Modal -->
        <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">
                ...
              </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>
        <!-- END COPY / PASTE -->
ADDITIONAL COMMENT: - Ensure you include Bootstrap's CSS and JS files in your project for the modal to function properly. - The button with "data-bs-toggle="modal"" and "data-bs-target="#exampleModal"" attributes is used to trigger the modal. - The modal structure includes ".modal", ".modal-dialog", and ".modal-content" classes. - Use ".btn-close" for the close button inside the modal header. - The "aria-*" attributes help with accessibility by providing additional context to screen readers. ✅ Answered with Bootstrap 5 best practices.
← Back to All Questions