Bootstrap5 Modal

A modal (Modal) is a child window that overlays the parent form. Usually, the purpose is to display content from a separate source, allowing some interaction without leaving the parent form. The child window can provide information interaction, etc.


How to Create a Modal

The following example creates a simple modal effect:

Example

<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#myModal">Open Modal</button> <!--Modal--> <div class="modal" id="myModal"> <div class="modal-dialog"> <div class="modal-content"> <!--Modal Header--> <div class="modal-header"> <h4 class="modal-title">Modal Title</h4> <button type="button" class="btn-close" data-bs-dismiss="modal"></button> </div> <!--Modal Body--> <div class="modal-body">Modal Body..</div> <!--Modal Footer--> <div class="modal-footer"> <button type="button" class="btn btn-danger" data-bs-dismiss="modal">Close</button> </div> </div> </div> </div>

Try it Yourself »

Add Animation

Use the .fade class to set the effect of the modal popping up or closing:

Example

<!--With animation effect--> <div class="modal fade"></div> <!--Without animation effect--> <div class="modal"></div>

Try it Yourself »

Modal Size

We can use the.modal-smclass to create a small modal,.modal-lgclass can create a large modal.

The size class is placed<div>after the element's.modal-dialogclass:

Example - Small Modal

<div class="modal-dialog modal-sm">

Try it Yourself »

Example - Large Modal

<div class="modal-dialog modal-lg">

Try it Yourself »

Example - Extra Large Modal

<div class="modal-dialog modal-xl">

Try it Yourself »

Fullscreen Display

Use the.modal-fullscreenclass to make the modal display fullscreen:

Example - Fullscreen Display

<div class="modal-dialog modal-fullscreen">

Try it Yourself »

Use the.modal-fullscreen-*-*class to control at what screen size to display fullscreen:

Class Description Example
.modal-fullscreen-sm-down Fullscreen below 576px Try it Yourself
.modal-fullscreen-md-down Fullscreen below 768px Try it Yourself
.modal-fullscreen-lg-down Fullscreen below 992px Try it Yourself
.modal-fullscreen-xl-down Fullscreen below 1200px Try it Yourself
.modal-fullscreen-xxl-down Fullscreen below 1400px Try it Yourself

Modal Centered Display

Use the.modal-dialog-centeredclass to set the modal to be centered both horizontally and vertically:

Example

<div class="modal-dialog modal-dialog-centered">

Try it Yourself »

Modal Scrollbar

By default, if the modal contains a lot of content, the page will automatically generate a scrollbar, and the modal will scroll with the page:

Example

<div class="modal-dialog">

Try it Yourself »

If we only want to set a scrollbar inside the modal, we can use the.modal-dialog-scrollableclass:

Example

<div class="modal-dialog modal-dialog-scrollable">

Try it Yourself »
Other Extensions