CHAPTER 13
Beginner
Bootstrap Modals and Popups
Updated: May 18, 2026
5 min read
# CHAPTER 13
Bootstrap Modals and Popups
1. Chapter Introduction
Modals are overlay dialogs that appear on top of the current page — perfect for confirmations, login forms, image lightboxes, and settings panels. Bootstrap's modal and offcanvas components handle all this with just HTML data attributes and zero custom JavaScript for basic use.2. Learning Objectives
- Build modals with triggers, headers, bodies, and footers.
- Control modal sizes (sm, lg, xl, fullscreen).
- Create scrollable and centered modals.
- Build side drawer panels with offcanvas.
- Build a login modal.
3. Basic Modal
html
4. Modal Sizes
html
5. Centered and Scrollable Modals
html
6. Confirmation Modal
html
7. Offcanvas (Side Drawer)
html
8. Mini Project: Login Modal
html
9. Common Mistakes
-
data-bs-targetmismatch: The#idindata-bs-targetmust exactly match the modal'sid. A missing#or typo means the modal won't open.
-
Missing
tabindex="-1"on modal: This is required for accessibility — it removes the modal from the tab order until it is open.
10. MCQs
Question 1
What attribute opens a modal on button click?
Question 2
What class animates modal fade in?
Question 3
Modal dialog centered vertically?
Question 4
Extra large modal size class?
Question 5
Fullscreen mobile modal?
Question 6
What class dismisses a modal from a button?
Question 7
Offcanvas from right side?
Question 8
What does modal-dialog-scrollable do?
Question 9
tabindex="-1" on a modal?
Question 10
Offcanvas from top?
11. Interview Questions
- Q: How does Bootstrap open a modal without custom JavaScript?
- Q: What is the difference between a Modal and an Offcanvas?