Nearby lessons
24 of 39π¬ BS5 Modal
π What Are Bootstrap 5 Modals?
Modals are dialog overlays. The modal has .modal .fade and an id. Trigger: data-bs-toggle="modal" and data-bs-target="#modalId". Inside use .modal-dialog, .modal-content, then .modal-header, .modal-body, .modal-footer. Requires Bootstrapβs JavaScript.
πͺ Basic Modal (.modal, .modal-dialog, .modal-content, .modal-header, .modal-body, .modal-footer)
.modal .fade β overlay and fade-in. .modal-dialog β centers the box. .modal-content β the box (border, shadow). .modal-header β top bar with title and close. .modal-body β main content. .modal-footer β bottom buttons. .btn-close with data-bs-dismiss="modal" closes the modal.
π Modal Sizes (.modal-lg, .modal-sm)
.modal-lg β wider modal. .modal-sm β narrower. Add to .modal-dialog.
π Centered Modal (.modal-dialog-centered)
.modal-dialog-centered β vertically centers the dialog. Add to .modal-dialog.
β Modal Best Practices
- Use aria-labelledby and aria-hidden on the modal for accessibility.
- Close button: .btn-close with data-bs-dismiss="modal".
- Use .modal-lg or .modal-sm on .modal-dialog for size.
π§ Test Your Knowledge
3 QuestionsProgress: 0 / 3
Keep Going!BS5 Tooltip