Ask any question about Bootstrap here... and get an instant response.
Post this Question & Answer:
How can I customize Bootstrap's modal animations for a unique transition effect? Pending Review
Asked on Apr 14, 2026
Answer
To customize Bootstrap's modal animations, you can override the default CSS transitions with your own styles. This involves using custom CSS to define new keyframes and applying them to the modal.
<!-- BEGIN COPY / PASTE -->
<style>
@keyframes customFadeIn {
from { transform: translateY(-50px); opacity: 0; }
to { transform: translateY(0); opacity: 1; }
}
@keyframes customFadeOut {
from { transform: translateY(0); opacity: 1; }
to { transform: translateY(-50px); opacity: 0; }
}
.modal.fade .modal-dialog {
transition: none;
animation: customFadeOut 0.3s forwards;
}
.modal.fade.show .modal-dialog {
animation: customFadeIn 0.3s forwards;
}
</style>
<div class="modal fade" id="myModal" 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">Custom Modal</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
This is a custom animated modal.
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!-- END COPY / PASTE -->Additional Comment:
✅ Answered with Bootstrap 5 best practices.- The `@keyframes customFadeIn` and `@keyframes customFadeOut` define the custom animations.
- The `.modal.fade .modal-dialog` class is used to apply the custom fade-out animation.
- The `.modal.fade.show .modal-dialog` class is used to apply the custom fade-in animation.
- Adjust the `transform` and `opacity` values in the keyframes to create different effects.
- Ensure the modal has the `fade` class for the animations to apply.
Recommended Links:
