Ask any question about Bootstrap here... and get an instant response.
Post this Question & Answer:
How can I customize Bootstrap's modal animations?
Asked on Apr 11, 2026
Answer
To customize Bootstrap's modal animations, you can override the default CSS transitions with your own styles. This involves modifying the `transform` and `opacity` properties for the modal's `.modal-dialog` class.
<!-- BEGIN COPY / PASTE -->
<style>
.modal.fade .modal-dialog {
transition: transform 0.3s ease-out, opacity 0.3s ease-out;
transform: translateY(-50px);
opacity: 0;
}
.modal.show .modal-dialog {
transform: translateY(0);
opacity: 1;
}
</style>
<!-- Example modal trigger and structure -->
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal">
Launch demo modal
</button>
<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">
Modal body text goes here.
</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:
✅ Answered with Bootstrap 5 best practices.- The `.modal.fade .modal-dialog` class is used to define the initial state of the modal with a custom animation.
- The `.modal.show .modal-dialog` class is used to define the final state when the modal is fully visible.
- You can adjust the `transform` and `opacity` properties to create different animation effects.
- Ensure that the transition duration matches between the `fade` and `show` states for a smooth animation.
Recommended Links:
